Fixed: Prevent books being added with AuthorMetadataId 0

(cherry picked from commit 0c227d0f21e3803c6293fd5988e48ea010483cad)
This commit is contained in:
ta264 2021-08-03 21:48:28 +01:00
parent 1571ef4172
commit 59c1bf0b1f
3 changed files with 18 additions and 0 deletions

View file

@ -63,6 +63,11 @@ public BookService(IBookRepository bookRepository,
public Book AddBook(Book newBook, bool doRefresh = true)
{
if (newBook.AuthorMetadataId == 0)
{
throw new InvalidOperationException("Cannot insert book with AuthorMetadataId = 0");
}
_bookRepository.Upsert(newBook);
var editions = newBook.Editions.Value;
@ -244,6 +249,11 @@ public List<Book> GetAuthorBooksWithFiles(Author author)
public void InsertMany(List<Book> books)
{
if (books.Any(x => x.AuthorMetadataId == 0))
{
throw new InvalidOperationException("Cannot insert book with AuthorMetadataId = 0");
}
_bookRepository.InsertMany(books);
}

View file

@ -374,6 +374,12 @@ private Book EnsureBookAdded(List<ImportDecision<LocalBook>> decisions)
if (dbBook == null)
{
_logger.Debug($"Adding remote book {book}");
if (book.AuthorMetadataId == 0)
{
throw new InvalidOperationException("Cannot insert book with AuthorMetadataId = 0");
}
try
{
book.Added = DateTime.UtcNow;

View file

@ -747,6 +747,7 @@ private Book MapSearchResult(WorkResource resource)
book.Author = author;
book.AuthorMetadata = book.Author.Value.Metadata.Value;
book.AuthorMetadataId = author.AuthorMetadataId;
book.CleanTitle = book.Title.CleanAuthorName();
}
@ -833,6 +834,7 @@ private Book MapJsonSearchResult(SearchJsonResource resource, Action<Edition> ap
book.Author = author;
book.AuthorMetadata = book.Author.Value.Metadata.Value;
book.AuthorMetadataId = author.AuthorMetadataId;
book.CleanTitle = book.Title.CleanAuthorName();
book.SeriesLinks = MapSearchSeries(resource.Title, resource.BookTitleBare);