Fixed: Removed unnecessary author data from book endpoint

This commit is contained in:
ta264
2022-05-26 21:51:37 +01:00
parent ce58e6ecdb
commit a59706ceb4
16 changed files with 190 additions and 49 deletions

View File

@@ -439,7 +439,7 @@ namespace NzbDrone.Core.MetadataSource.BookInfo
var edition = book.Editions.Value.SingleOrDefault(e => e.ForeignEditionId == id.ToString());
trimmed.Editions = new List<Edition> { edition };
return trimmed;
book = trimmed;
}
var authorDict = authors.ToDictionary(x => x.ForeignAuthorId);

View File

@@ -52,12 +52,23 @@ namespace NzbDrone.Integration.Test.ApiTests
{
EnsureAuthor("14586394", "43765115", "Andrew Hunter Murray", true);
var result = WantedMissing.GetPaged(0, 15, "releaseDate", "desc");
var result = WantedMissing.GetPagedIncludeAuthor(0, 15, "releaseDate", "desc", includeAuthor: true);
result.Records.First().Author.Should().NotBeNull();
result.Records.First().Author.AuthorName.Should().Be("Andrew Hunter Murray");
}
[Test]
[Order(1)]
public void missing_should_not_have_author()
{
EnsureAuthor("14586394", "43765115", "Andrew Hunter Murray", true);
var result = WantedMissing.GetPagedIncludeAuthor(0, 15, "releaseDate", "desc", includeAuthor: false);
result.Records.First().Author.Should().BeNull();
}
[Test]
[Order(2)]
public void cutoff_should_have_monitored_items()
@@ -103,12 +114,25 @@ namespace NzbDrone.Integration.Test.ApiTests
var author = EnsureAuthor("14586394", "43765115", "Andrew Hunter Murray", true);
EnsureBookFile(author, 1, "43765115", Quality.MOBI);
var result = WantedCutoffUnmet.GetPaged(0, 15, "releaseDate", "desc");
var result = WantedCutoffUnmet.GetPagedIncludeAuthor(0, 15, "releaseDate", "desc", includeAuthor: true);
result.Records.First().Author.Should().NotBeNull();
result.Records.First().Author.AuthorName.Should().Be("Andrew Hunter Murray");
}
[Test]
[Order(2)]
public void cutoff_should_not_have_author()
{
EnsureProfileCutoff(1, Quality.AZW3);
var author = EnsureAuthor("14586394", "43765115", "Andrew Hunter Murray", true);
EnsureBookFile(author, 1, "43765115", Quality.MOBI);
var result = WantedCutoffUnmet.GetPagedIncludeAuthor(0, 15, "releaseDate", "desc", includeAuthor: false);
result.Records.First().Author.Should().BeNull();
}
[Test]
[Order(1)]
public void missing_should_have_unmonitored_items()

View File

@@ -0,0 +1,40 @@
using System.Collections.Generic;
using Readarr.Api.V1.Books;
using Readarr.Http;
using RestSharp;
namespace NzbDrone.Integration.Test.Client
{
public class WantedClient : ClientBase<BookResource>
{
public WantedClient(IRestClient restClient, string apiKey, string resource)
: base(restClient, apiKey, resource)
{
}
public PagingResource<BookResource> GetPagedIncludeAuthor(int pageNumber, int pageSize, string sortKey, string sortDir, string filterKey = null, string filterValue = null, bool includeAuthor = true)
{
var request = BuildRequest();
request.AddParameter("page", pageNumber);
request.AddParameter("pageSize", pageSize);
request.AddParameter("sortKey", sortKey);
request.AddParameter("sortDir", sortDir);
if (filterKey != null && filterValue != null)
{
request.AddParameter("filterKey", filterKey);
request.AddParameter("filterValue", filterValue);
}
request.AddParameter("includeAuthor", includeAuthor);
return Get<PagingResource<BookResource>>(request);
}
public List<BookResource> GetBooksInAuthor(int authorId)
{
var request = BuildRequest("?authorId=" + authorId.ToString());
return Get<List<BookResource>>(request);
}
}
}

View File

@@ -53,8 +53,8 @@ namespace NzbDrone.Integration.Test
public ClientBase<RootFolderResource> RootFolders;
public AuthorClient Author;
public ClientBase<TagResource> Tags;
public ClientBase<BookResource> WantedMissing;
public ClientBase<BookResource> WantedCutoffUnmet;
public WantedClient WantedMissing;
public WantedClient WantedCutoffUnmet;
private List<SignalRMessage> _signalRReceived;
@@ -118,8 +118,8 @@ namespace NzbDrone.Integration.Test
RootFolders = new ClientBase<RootFolderResource>(RestClient, ApiKey);
Author = new AuthorClient(RestClient, ApiKey);
Tags = new ClientBase<TagResource>(RestClient, ApiKey);
WantedMissing = new ClientBase<BookResource>(RestClient, ApiKey, "wanted/missing");
WantedCutoffUnmet = new ClientBase<BookResource>(RestClient, ApiKey, "wanted/cutoff");
WantedMissing = new WantedClient(RestClient, ApiKey, "wanted/missing");
WantedCutoffUnmet = new WantedClient(RestClient, ApiKey, "wanted/cutoff");
}
[OneTimeTearDown]

View File

@@ -138,6 +138,17 @@ namespace Readarr.Api.V1.Books
return MapToResource(_bookService.GetBooks(bookIds), false);
}
[HttpGet("{id:int}/overview")]
public object Overview(int id)
{
var overview = _editionService.GetEditionsByBook(id).Single(x => x.Monitored).Overview;
return new
{
id,
overview
};
}
[RestPostById]
public ActionResult<BookResource> AddBook(BookResource bookResource)
{

View File

@@ -72,13 +72,10 @@ namespace Readarr.Api.V1.Books
AuthorTitle = authorTitle,
SeriesTitle = seriesTitle,
Disambiguation = selectedEdition?.Disambiguation,
Overview = selectedEdition?.Overview,
Images = selectedEdition?.Images ?? new List<MediaCover>(),
Links = model.Links.Concat(selectedEdition?.Links ?? new List<Links>()).ToList(),
Ratings = selectedEdition?.Ratings ?? new Ratings(),
Added = model.Added,
Author = model.Author?.Value.ToResource(),
Editions = model.Editions?.Value.ToResource() ?? new List<EditionResource>()
};
}

View File

@@ -51,6 +51,9 @@ namespace Readarr.Api.V1.Search
{
var book = (NzbDrone.Core.Books.Book)result;
resource.Book = book.ToResource();
resource.Book.Overview = book.Editions.Value.Single(x => x.Monitored).Overview;
resource.Book.Author = book.Author.Value.ToResource();
resource.Book.Editions = book.Editions.Value.ToResource();
resource.ForeignId = book.ForeignBookId;
var cover = book.Editions.Value.Single(x => x.Monitored).Images.FirstOrDefault(c => c.CoverType == MediaCoverTypes.Cover);