< Summary

Information
Class: Anichron.API.Endpoints.FlashbackEndpoints
Assembly: Anichron.API
File(s): /home/runner/work/anichron/anichron/src/Anichron.API/Endpoints/FlashbackEndpoints.cs
Tag: 19_45211875487
Line coverage
94%
Covered lines: 18
Uncovered lines: 1
Coverable lines: 19
Total lines: 47
Line coverage: 94.7%
Branch coverage
75%
Covered branches: 6
Total branches: 8
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
MapFlashbackEndpoints(...)100%11100%
GetOnThisDayAsync()75%8891.66%

File(s)

/home/runner/work/anichron/anichron/src/Anichron.API/Endpoints/FlashbackEndpoints.cs

#LineLine coverage
 1using Anichron.API.Infrastructure;
 2using Anichron.Core.Data.Repository;
 3using Microsoft.AspNetCore.Mvc;
 4using NodaTime.Text;
 5using System.Security.Claims;
 6
 7namespace Anichron.API.Endpoints;
 8
 9public sealed record OnThisDayDto(string Date, IReadOnlyList<FlashbackYearDto> Years);
 10
 11public static class FlashbackEndpoints
 12{
 13    internal const string InvalidDateMessage = "date must be a calendar date in the form YYYY-MM-DD.";
 14
 15    public static IEndpointRouteBuilder MapFlashbackEndpoints(this IEndpointRouteBuilder app)
 5216    {
 5217        var group = app.MapGroup(ApiPaths.Flashbacks.Group).WithTags("Flashbacks").RequireUser();
 5218        group.MapGet(ApiPaths.Flashbacks.OnThisDay, GetOnThisDayAsync)
 5219             .Produces<OnThisDayDto>()
 5220             .ProducesValidationProblem();
 5221        return app;
 5222    }
 23
 24    internal static async Task<IResult> GetOnThisDayAsync(
 25        string? date,
 26        ClaimsPrincipal user,
 27        [FromServices] IAssetViewReader reader,
 28        [FromServices] IClock clock,
 29        [FromServices] DateTimeZone zone,
 30        CancellationToken ct)
 1431    {
 1432        if (!Guid.TryParse(user.FindFirstValue(ClaimTypes.NameIdentifier), out var userId))
 033            return Results.Unauthorized();
 34
 35        LocalDate day;
 1436        if (date is null)
 237            day = clock.GetCurrentInstant().InZone(zone).Date;
 1238        else if (LocalDatePattern.Iso.Parse(date) is { Success: true } parsed)
 839            day = parsed.Value;
 40        else
 441            return ApiProblems.FieldProblem(StatusCodes.Status400BadRequest, ErrorCodes.InvalidDate, nameof(date), Inval
 42
 1043        var selection = new OnThisDay(day);
 1044        var views = await reader.ReadAsync(userId, selection, ct);
 1045        return Results.Ok(new OnThisDayDto(LocalDatePattern.Iso.Format(day), FlashbackYears.Group(views, selection)));
 1446    }
 47}