| | | 1 | | using Anichron.Core.Data.Repository; |
| | | 2 | | |
| | | 3 | | namespace Anichron.API.Endpoints; |
| | | 4 | | |
| | | 5 | | public sealed record FlashbackYearDto(int Year, IReadOnlyList<AssetDto> Assets); |
| | | 6 | | |
| | | 7 | | internal static class FlashbackYears |
| | | 8 | | { |
| | | 9 | | internal static IReadOnlyList<FlashbackYearDto> Group(IReadOnlyCollection<AssetView> views, OnThisDay day) |
| | 24 | 10 | | => [.. Items(views, day) |
| | 24 | 11 | | .GroupBy(item => item.View.Year) |
| | 24 | 12 | | .OrderByDescending(year => year.Key) |
| | 24 | 13 | | .Select(year => new FlashbackYearDto( |
| | 24 | 14 | | year.Key, |
| | 24 | 15 | | [.. year |
| | 24 | 16 | | .OrderByDescending(item => item.View.IsStarred) |
| | 24 | 17 | | .ThenBy(item => item.View.DateCaptured) |
| | 24 | 18 | | .ThenBy(item => item.View.Id) |
| | 24 | 19 | | .Select(item => AssetDtoMapper.ToDto(item.View, item.Burst))]))]; |
| | | 20 | | |
| | | 21 | | private static IEnumerable<AssetItem> Items(IReadOnlyCollection<AssetView> views, OnThisDay day) |
| | 24 | 22 | | => views |
| | 24 | 23 | | .Where(v => v.BurstId is null) |
| | 24 | 24 | | .Select(v => new AssetItem(v, null)) |
| | 24 | 25 | | .Concat(views |
| | 24 | 26 | | .Where(v => v.BurstId is not null) |
| | 24 | 27 | | .GroupBy(v => v.BurstId!.Value) |
| | 24 | 28 | | .Select(burst => Bursts.Cover(burst.Key, [.. burst])) |
| | 24 | 29 | | .Where(item => day.FallsOnTheDay(item.View))); |
| | | 30 | | } |