< Summary

Information
Class: Anichron.API.Endpoints.AssetDtoMapper
Assembly: Anichron.API
File(s): /home/runner/work/anichron/anichron/src/Anichron.API/Endpoints/AssetDtoMapper.cs
Tag: 19_45211875487
Line coverage
96%
Covered lines: 31
Uncovered lines: 1
Coverable lines: 32
Total lines: 47
Line coverage: 96.8%
Branch coverage
90%
Covered branches: 27
Total branches: 30
Branch coverage: 90%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ToDto(...)91.66%2424100%
ToDto(...)100%11100%
Published(...)83.33%6685.71%

File(s)

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

#LineLine coverage
 1using Anichron.Core.Data.Repository;
 2using Anichron.Core.Domain;
 3using System.Diagnostics;
 4
 5namespace Anichron.API.Endpoints;
 6
 7internal static class AssetDtoMapper
 8{
 9    internal static AssetDto ToDto(AssetView view, AssetBurstDto? burst)
 18210    {
 18211        var swapsAxes = view.Orientation is { } orientation && ExifOrientation.SwapsAxes(orientation);
 18212        var liveVideoUrl = view is { PairedMovHasVideo: true, PairedMovId: { } movId, PairedMovContentHash: { } movHash 
 18213            ? ProxyKinds.UrlOf(movId, ProxyType.WebVideo, movHash)
 18214            : null;
 15
 18216        return new AssetDto(
 18217            view.Id,
 18218            Published(view.MediaType, liveVideoUrl is not null).ToString(),
 18219            view.Year,
 18220            view.Month,
 18221            view.Day,
 18222            swapsAxes ? view.Height : view.Width,
 18223            swapsAxes ? view.Width : view.Height,
 18224            view.MediaType == MediaType.Video ? view.DurationInSeconds : null,
 18225            new AssetProxyUrls(
 18226                view.HasThumbnail ? ProxyKinds.UrlOf(view.Id, ProxyType.Thumbnail, view.ContentHash) : null,
 18227                view.HasPreview ? ProxyKinds.UrlOf(view.Id, ProxyType.FullPreview, view.ContentHash) : null,
 18228                view.HasCompactPreview ? ProxyKinds.UrlOf(view.Id, ProxyType.CompactPreview, view.ContentHash) : null,
 18229                view.HasVideo ? ProxyKinds.UrlOf(view.Id, ProxyType.WebVideo, view.ContentHash) : null),
 18230            view.Blurhash,
 18231            liveVideoUrl,
 18232            ToDto(new InteractionState(view.IsStarred, view.IsLiked, view.HiddenAt is not null)),
 18233            burst);
 18234    }
 35
 36    internal static AssetInteractionDto ToDto(InteractionState state)
 19037        => new(state.Starred, state.Liked, state.Hidden, FlashbackWeight.For(state.Liked));
 38
 39    private static PublishedMediaType Published(MediaType type, bool playsLive)
 18240        => type switch
 18241        {
 16942            MediaType.Image => PublishedMediaType.Image,
 743            MediaType.Video => PublishedMediaType.Video,
 644            MediaType.LivePhoto => playsLive ? PublishedMediaType.LivePhoto : PublishedMediaType.Image,
 045            _ => throw new UnreachableException($"MediaType {type} has no published value."),
 18246        };
 47}