Fixed: Adding alternative edition of a book via goodreads id

pull/755/head
ta264 4 years ago
parent 3575ca50da
commit 6a79c2f3a1

@ -141,7 +141,7 @@ class AddNewItem extends Component {
); );
} else if (item.book) { } else if (item.book) {
const book = item.book; const book = item.book;
const edition = book.editions[0]; const edition = book.editions.find((x) => x.monitored);
return ( return (
<AddNewBookSearchResultConnector <AddNewBookSearchResultConnector
key={item.id} key={item.id}

@ -63,15 +63,13 @@ namespace NzbDrone.Core.Books
public Book AddBook(Book newBook, bool doRefresh = true) public Book AddBook(Book newBook, bool doRefresh = true)
{ {
var editions = newBook.Editions.Value;
editions.ForEach(x => x.Monitored = newBook.Id > 0);
_bookRepository.Upsert(newBook); _bookRepository.Upsert(newBook);
var editions = newBook.Editions.Value;
editions.ForEach(x => x.BookId = newBook.Id); editions.ForEach(x => x.BookId = newBook.Id);
_editionService.InsertMany(editions); _editionService.InsertMany(editions.Where(x => x.Id == 0).ToList());
_editionService.SetMonitored(editions.First()); _editionService.SetMonitored(editions.FirstOrDefault(x => x.Monitored) ?? editions.First());
_eventAggregator.PublishEvent(new BookAddedEvent(GetBook(newBook.Id), doRefresh)); _eventAggregator.PublishEvent(new BookAddedEvent(GetBook(newBook.Id), doRefresh));

@ -438,10 +438,20 @@ namespace NzbDrone.Core.MetadataSource.Goodreads
var book = _bookService.FindById(remote.Item2.ForeignBookId); var book = _bookService.FindById(remote.Item2.ForeignBookId);
var result = book ?? remote.Item2; var result = book ?? remote.Item2;
var edition = _editionService.GetEditionByForeignEditionId(remote.Item2.Editions.Value.Single(x => x.Monitored).ForeignEditionId); // at this point, book could have the wrong edition.
if (edition != null) // 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> { edition }; result.Editions = new List<Edition> { 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); var author = _authorService.FindById(remote.Item1);

Loading…
Cancel
Save