diff --git a/DTOs/LibraryApiV10.custom.cs b/DTOs/LibraryApiV10.custom.cs index de302e64..95454cdb 100644 --- a/DTOs/LibraryApiV10.custom.cs +++ b/DTOs/LibraryApiV10.custom.cs @@ -9,6 +9,9 @@ namespace DTOs { public IEnumerable AuthorsDistinct => Items.GetAuthorsDistinct(); public IEnumerable NarratorsDistinct => Items.GetNarratorsDistinct(); + public IEnumerable SeriesDistinct => Items.GetSeriesDistinct(); + public IEnumerable ParentCategoriesDistinct => Items.GetParentCategoriesDistinct(); + public IEnumerable ChildCategoriesDistinct => Items.GetChildCategoriesDistinct(); public override string ToString() => $"{Items.Length} {nameof(Items)}, {ResponseGroups.Length} {nameof(ResponseGroups)}"; } @@ -41,8 +44,12 @@ namespace DTOs public DateTime? DatePublished => IssueDate?.UtcDateTime; // item.IssueDate == item.ReleaseDate public string Publisher => PublisherName; - // future: need support for multiple categories + // these category properties assume: + // - we're only exposing 1 category, irrespective of how many the Item actually has + // - each ladder will have either 1 or 2 levels: parent and optional child public Ladder[] Categories => CategoryLadders?.FirstOrDefault()?.Ladder ?? new Ladder[0]; + public Ladder ParentCategory => Categories[0]; + public Ladder ChildCategory => Categories.Length > 1 ? Categories[1] : null; // LibraryDTO.DownloadBookLink will be handled differently. see api.DownloadAaxWorkaroundAsync(asin) diff --git a/DTOs/LibraryApiV10Extensions.cs b/DTOs/LibraryApiV10Extensions.cs index 2f000b88..03f04c86 100644 --- a/DTOs/LibraryApiV10Extensions.cs +++ b/DTOs/LibraryApiV10Extensions.cs @@ -11,6 +11,18 @@ namespace DTOs => items.SelectMany(i => i.Authors).DistinctBy(a => new { a.Name, a.Asin }); public static IEnumerable GetNarratorsDistinct(this IEnumerable items) - => items.SelectMany(i => i.Narrators).DistinctBy(a => new { a.Name, a.Asin }); + => items.SelectMany(i => i.Narrators).DistinctBy(n => new { n.Name, n.Asin }); + + public static IEnumerable GetSeriesDistinct(this IEnumerable items) + => items.SelectMany(i => i.Series).DistinctBy(s => new { s.SeriesName, s.SeriesId }); + + public static IEnumerable GetParentCategoriesDistinct(this IEnumerable items) + => items.Select(l => l.ParentCategory).DistinctBy(l => new { l.CategoryName, l.CategoryId }); + + public static IEnumerable GetChildCategoriesDistinct(this IEnumerable items) + => items + .Select(l => l.ChildCategory) + .Where(l => l != null) + .DistinctBy(l => new { l.CategoryName, l.CategoryId }); } } diff --git a/__TODO.txt b/__TODO.txt index cfcd323d..1ca2ab30 100644 --- a/__TODO.txt +++ b/__TODO.txt @@ -68,6 +68,7 @@ TONS of expensive conversion: GetLibraryAsync > string > JObject > string > Libr -- begin ENHANCEMENT, CATEGORIES --------------------------------------------------------------------------------------------------------------------- add support for multiple categories +when i do this, learn about the different CategoryLadder.Root enums. probably only need Root.Genres -- end ENHANCEMENT, CATEGORIES --------------------------------------------------------------------------------------------------------------------- -- begin LEGACY ---------------------------------------------------------------------------------------------------------------------