| | | 1 | | using Anichron.Core.Data.Repository; |
| | | 2 | | |
| | | 3 | | namespace Anichron.API.Endpoints; |
| | | 4 | | |
| | | 5 | | internal sealed record AssetItem(AssetView View, AssetBurstDto? Burst); |
| | | 6 | | |
| | | 7 | | internal static class Bursts |
| | | 8 | | { |
| | | 9 | | internal static IReadOnlyList<AssetDto> Members(Guid burstId, IReadOnlyList<AssetView> members) |
| | 1 | 10 | | => [.. OldestFirst(members) |
| | 1 | 11 | | .Select((member, index) => AssetDtoMapper.ToDto( |
| | 1 | 12 | | member, new AssetBurstDto(burstId, IsCover: index == 0, members.Count)))]; |
| | | 13 | | |
| | | 14 | | internal static AssetItem Cover(Guid burstId, IReadOnlyCollection<AssetView> members) |
| | 15 | 15 | | { |
| | 15 | 16 | | var cover = OldestFirst(members)[0] with |
| | 15 | 17 | | { |
| | 15 | 18 | | IsStarred = members.Any(m => m.IsStarred), |
| | 15 | 19 | | IsLiked = members.Any(m => m.IsLiked), |
| | 15 | 20 | | }; |
| | 15 | 21 | | return new AssetItem(cover, new AssetBurstDto(burstId, IsCover: true, members.Count)); |
| | 15 | 22 | | } |
| | | 23 | | |
| | | 24 | | private static List<AssetView> OldestFirst(IEnumerable<AssetView> views) |
| | 16 | 25 | | => [.. views.OrderBy(v => v.DateCaptured).ThenBy(v => v.Id)]; |
| | | 26 | | } |