new DTOs: add more aggregate properties and extension methods which will be needed for importing

This commit is contained in:
Robert McRackan 2019-10-25 22:22:50 -04:00
parent 8e4dcb1780
commit 8872cba2cd
3 changed files with 22 additions and 2 deletions

View File

@ -9,6 +9,9 @@ namespace DTOs
{ {
public IEnumerable<Person> AuthorsDistinct => Items.GetAuthorsDistinct(); public IEnumerable<Person> AuthorsDistinct => Items.GetAuthorsDistinct();
public IEnumerable<Person> NarratorsDistinct => Items.GetNarratorsDistinct(); public IEnumerable<Person> NarratorsDistinct => Items.GetNarratorsDistinct();
public IEnumerable<Series> SeriesDistinct => Items.GetSeriesDistinct();
public IEnumerable<Ladder> ParentCategoriesDistinct => Items.GetParentCategoriesDistinct();
public IEnumerable<Ladder> ChildCategoriesDistinct => Items.GetChildCategoriesDistinct();
public override string ToString() => $"{Items.Length} {nameof(Items)}, {ResponseGroups.Length} {nameof(ResponseGroups)}"; 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 DateTime? DatePublished => IssueDate?.UtcDateTime; // item.IssueDate == item.ReleaseDate
public string Publisher => PublisherName; 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[] 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) // LibraryDTO.DownloadBookLink will be handled differently. see api.DownloadAaxWorkaroundAsync(asin)

View File

@ -11,6 +11,18 @@ namespace DTOs
=> items.SelectMany(i => i.Authors).DistinctBy(a => new { a.Name, a.Asin }); => items.SelectMany(i => i.Authors).DistinctBy(a => new { a.Name, a.Asin });
public static IEnumerable<Person> GetNarratorsDistinct(this IEnumerable<Item> items) public static IEnumerable<Person> GetNarratorsDistinct(this IEnumerable<Item> 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<Series> GetSeriesDistinct(this IEnumerable<Item> items)
=> items.SelectMany(i => i.Series).DistinctBy(s => new { s.SeriesName, s.SeriesId });
public static IEnumerable<Ladder> GetParentCategoriesDistinct(this IEnumerable<Item> items)
=> items.Select(l => l.ParentCategory).DistinctBy(l => new { l.CategoryName, l.CategoryId });
public static IEnumerable<Ladder> GetChildCategoriesDistinct(this IEnumerable<Item> items)
=> items
.Select(l => l.ChildCategory)
.Where(l => l != null)
.DistinctBy(l => new { l.CategoryName, l.CategoryId });
} }
} }

View File

@ -68,6 +68,7 @@ TONS of expensive conversion: GetLibraryAsync > string > JObject > string > Libr
-- begin ENHANCEMENT, CATEGORIES --------------------------------------------------------------------------------------------------------------------- -- begin ENHANCEMENT, CATEGORIES ---------------------------------------------------------------------------------------------------------------------
add support for multiple 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 --------------------------------------------------------------------------------------------------------------------- -- end ENHANCEMENT, CATEGORIES ---------------------------------------------------------------------------------------------------------------------
-- begin LEGACY --------------------------------------------------------------------------------------------------------------------- -- begin LEGACY ---------------------------------------------------------------------------------------------------------------------