From 6a79c2f3a1870b4739ccfd23d26d1b040018ad97 Mon Sep 17 00:00:00 2001 From: ta264 Date: Mon, 18 Jan 2021 20:09:28 +0000 Subject: [PATCH] Fixed: Adding alternative edition of a book via goodreads id --- frontend/src/Search/AddNewItem.js | 2 +- src/NzbDrone.Core/Books/Services/BookService.cs | 8 +++----- .../MetadataSource/Goodreads/GoodreadsProxy.cs | 16 +++++++++++++--- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/frontend/src/Search/AddNewItem.js b/frontend/src/Search/AddNewItem.js index cdfa125ce..caa818fed 100644 --- a/frontend/src/Search/AddNewItem.js +++ b/frontend/src/Search/AddNewItem.js @@ -141,7 +141,7 @@ class AddNewItem extends Component { ); } else if (item.book) { const book = item.book; - const edition = book.editions[0]; + const edition = book.editions.find((x) => x.monitored); return ( x.Monitored = newBook.Id > 0); - _bookRepository.Upsert(newBook); + var editions = newBook.Editions.Value; editions.ForEach(x => x.BookId = newBook.Id); - _editionService.InsertMany(editions); - _editionService.SetMonitored(editions.First()); + _editionService.InsertMany(editions.Where(x => x.Id == 0).ToList()); + _editionService.SetMonitored(editions.FirstOrDefault(x => x.Monitored) ?? editions.First()); _eventAggregator.PublishEvent(new BookAddedEvent(GetBook(newBook.Id), doRefresh)); diff --git a/src/NzbDrone.Core/MetadataSource/Goodreads/GoodreadsProxy.cs b/src/NzbDrone.Core/MetadataSource/Goodreads/GoodreadsProxy.cs index b31093569..a20afe32d 100644 --- a/src/NzbDrone.Core/MetadataSource/Goodreads/GoodreadsProxy.cs +++ b/src/NzbDrone.Core/MetadataSource/Goodreads/GoodreadsProxy.cs @@ -438,10 +438,20 @@ namespace NzbDrone.Core.MetadataSource.Goodreads var book = _bookService.FindById(remote.Item2.ForeignBookId); var result = book ?? remote.Item2; - var edition = _editionService.GetEditionByForeignEditionId(remote.Item2.Editions.Value.Single(x => x.Monitored).ForeignEditionId); - if (edition != null) + // at this point, book could have the wrong edition. + // Check if we already have the correct edition. + var remoteEdition = remote.Item2.Editions.Value.Single(x => x.Monitored); + var localEdition = _editionService.GetEditionByForeignEditionId(remoteEdition.ForeignEditionId); + if (localEdition != null) { - result.Editions = new List { edition }; + result.Editions = new List { localEdition }; + } + + // If we don't have the correct edition in the response, add it in. + if (!result.Editions.Value.Any(x => x.ForeignEditionId == remoteEdition.ForeignEditionId)) + { + result.Editions.Value.ForEach(x => x.Monitored = false); + result.Editions.Value.Add(remoteEdition); } var author = _authorService.FindById(remote.Item1);