From 27e498bb1405936a37eb70cfac9a875a4f3cda48 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Wed, 3 May 2023 11:08:39 +0300 Subject: [PATCH] Fixed: Add ForeignEditionId to books endpoint --- .../AlbumRepositoryTests/AlbumRepositoryFixture.cs | 3 ++- src/NzbDrone.Core/Books/Model/Book.cs | 3 +++ src/NzbDrone.Core/Datastore/TableMapping.cs | 1 + src/NzbDrone.Core/ImportLists/Readarr/ReadarrAPIResource.cs | 1 + src/NzbDrone.Core/ImportLists/Readarr/ReadarrImport.cs | 5 +---- src/Readarr.Api.V1/Books/BookResource.cs | 3 +++ 6 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/NzbDrone.Core.Test/MusicTests/AlbumRepositoryTests/AlbumRepositoryFixture.cs b/src/NzbDrone.Core.Test/MusicTests/AlbumRepositoryTests/AlbumRepositoryFixture.cs index bd6c734fc..9d72a0a7f 100644 --- a/src/NzbDrone.Core.Test/MusicTests/AlbumRepositoryTests/AlbumRepositoryFixture.cs +++ b/src/NzbDrone.Core.Test/MusicTests/AlbumRepositoryTests/AlbumRepositoryFixture.cs @@ -166,6 +166,7 @@ public void get_last_books_should_return_next_book() private EquivalencyAssertionOptions BookComparerOptions(EquivalencyAssertionOptions opts) => opts.ComparingByMembers() .Excluding(ctx => ctx.SelectedMemberInfo.MemberType.IsGenericType && ctx.SelectedMemberInfo.MemberType.GetGenericTypeDefinition() == typeof(LazyLoaded<>)) - .Excluding(x => x.AuthorId); + .Excluding(x => x.AuthorId) + .Excluding(x => x.ForeignEditionId); } } diff --git a/src/NzbDrone.Core/Books/Model/Book.cs b/src/NzbDrone.Core/Books/Model/Book.cs index 8fd13fb29..0cd369f71 100644 --- a/src/NzbDrone.Core/Books/Model/Book.cs +++ b/src/NzbDrone.Core/Books/Model/Book.cs @@ -26,6 +26,7 @@ public Book() // These are metadata entries public int AuthorMetadataId { get; set; } public string ForeignBookId { get; set; } + public string ForeignEditionId { get; set; } public string TitleSlug { get; set; } public string Title { get; set; } public DateTime? ReleaseDate { get; set; } @@ -71,6 +72,7 @@ public override string ToString() public override void UseMetadataFrom(Book other) { ForeignBookId = other.ForeignBookId; + ForeignEditionId = other.ForeignEditionId; TitleSlug = other.TitleSlug; Title = other.Title; ReleaseDate = other.ReleaseDate; @@ -95,6 +97,7 @@ public override void UseDbFieldsFrom(Book other) public override void ApplyChanges(Book other) { ForeignBookId = other.ForeignBookId; + ForeignEditionId = other.ForeignEditionId; AddOptions = other.AddOptions; Monitored = other.Monitored; AnyEditionOk = other.AnyEditionOk; diff --git a/src/NzbDrone.Core/Datastore/TableMapping.cs b/src/NzbDrone.Core/Datastore/TableMapping.cs index 2cff688b9..3fd326bb3 100644 --- a/src/NzbDrone.Core/Datastore/TableMapping.cs +++ b/src/NzbDrone.Core/Datastore/TableMapping.cs @@ -135,6 +135,7 @@ public static void Map() Mapper.Entity("Books").RegisterModel() .Ignore(x => x.AuthorId) + .Ignore(x => x.ForeignEditionId) .HasOne(r => r.AuthorMetadata, r => r.AuthorMetadataId) .LazyLoad(x => x.BookFiles, (db, book) => db.Query(new SqlBuilder(db.DatabaseType) diff --git a/src/NzbDrone.Core/ImportLists/Readarr/ReadarrAPIResource.cs b/src/NzbDrone.Core/ImportLists/Readarr/ReadarrAPIResource.cs index bc9fdafa1..5a46b3425 100644 --- a/src/NzbDrone.Core/ImportLists/Readarr/ReadarrAPIResource.cs +++ b/src/NzbDrone.Core/ImportLists/Readarr/ReadarrAPIResource.cs @@ -28,6 +28,7 @@ public class ReadarrBook { public string Title { get; set; } public string ForeignBookId { get; set; } + public string ForeignEditionId { get; set; } public string Overview { get; set; } public List Images { get; set; } public bool Monitored { get; set; } diff --git a/src/NzbDrone.Core/ImportLists/Readarr/ReadarrImport.cs b/src/NzbDrone.Core/ImportLists/Readarr/ReadarrImport.cs index 88da51fcd..7e9a83545 100644 --- a/src/NzbDrone.Core/ImportLists/Readarr/ReadarrImport.cs +++ b/src/NzbDrone.Core/ImportLists/Readarr/ReadarrImport.cs @@ -68,10 +68,7 @@ public override IList Fetch() { BookGoodreadsId = remoteBook.ForeignBookId, Book = remoteBook.Title, - - // ToDo: Fix me. Edition is no longer in the book resource; rethink edition logic - // Bandaid fix for now...This will cause the imported book to possibly not be same edition as the source - // EditionGoodreadsId = remoteBook.Editions.Single(x => x.Monitored).ForeignEditionId, + EditionGoodreadsId = remoteBook.ForeignEditionId, Author = remoteAuthor.AuthorName, AuthorGoodreadsId = remoteAuthor.ForeignAuthorId }); diff --git a/src/Readarr.Api.V1/Books/BookResource.cs b/src/Readarr.Api.V1/Books/BookResource.cs index c8fa6e9f7..db49b06bb 100644 --- a/src/Readarr.Api.V1/Books/BookResource.cs +++ b/src/Readarr.Api.V1/Books/BookResource.cs @@ -19,6 +19,7 @@ public class BookResource : RestResource public string Overview { get; set; } public int AuthorId { get; set; } public string ForeignBookId { get; set; } + public string ForeignEditionId { get; set; } public string TitleSlug { get; set; } public bool Monitored { get; set; } public bool AnyEditionOk { get; set; } @@ -62,6 +63,7 @@ public static BookResource ToResource(this Book model) Id = model.Id, AuthorId = model.AuthorId, ForeignBookId = model.ForeignBookId, + ForeignEditionId = model.Editions?.Value?.SingleOrDefault(x => x.Monitored)?.ForeignEditionId, TitleSlug = model.TitleSlug, Monitored = model.Monitored, AnyEditionOk = model.AnyEditionOk, @@ -92,6 +94,7 @@ public static Book ToModel(this BookResource resource) { Id = resource.Id, ForeignBookId = resource.ForeignBookId, + ForeignEditionId = resource.ForeignEditionId, TitleSlug = resource.TitleSlug, Title = resource.Title, Monitored = resource.Monitored,