Recently Added Page (#261)

- Updated route task for 'recently-added'.
- Refactored GetRecentlyAdded task instead of creating new API task. This way is more efficient and prevents bloat.
- Adding pageSize to UserParams.cs (got lost in PRs).
This commit is contained in:
Robbie Davis 2021-06-04 11:09:33 -04:00 committed by GitHub
parent e6cfa4feca
commit 606e4c8b12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 16 deletions

View File

@ -148,11 +148,20 @@ namespace API.Controllers
} }
[HttpGet("recently-added")] [HttpGet("recently-added")]
public async Task<ActionResult<IEnumerable<SeriesDto>>> GetRecentlyAdded(int libraryId = 0, int limit = 20) public async Task<ActionResult<IEnumerable<SeriesDto>>> GetRecentlyAdded([FromQuery] UserParams userParams, int libraryId = 0)
{ {
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername()); var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername());
if (user == null) return Ok(Array.Empty<SeriesDto>()); var series =
return Ok(await _unitOfWork.SeriesRepository.GetRecentlyAdded(user.Id, libraryId, limit)); await _unitOfWork.SeriesRepository.GetRecentlyAdded(libraryId, user.Id, userParams);
// Apply progress/rating information (I can't work out how to do this in initial query)
if (series == null) return BadRequest("Could not get series");
await _unitOfWork.SeriesRepository.AddSeriesModifiers(user.Id, series);
Response.AddPaginationHeader(series.CurrentPage, series.PageSize, series.TotalCount, series.TotalPages);
return Ok(series);
} }
[HttpGet("in-progress")] [HttpGet("in-progress")]

View File

@ -291,7 +291,7 @@ namespace API.Data
/// <param name="libraryId">Library to restrict to, if 0, will apply to all libraries</param> /// <param name="libraryId">Library to restrict to, if 0, will apply to all libraries</param>
/// <param name="limit">How many series to pick.</param> /// <param name="limit">How many series to pick.</param>
/// <returns></returns> /// <returns></returns>
public async Task<IEnumerable<SeriesDto>> GetRecentlyAdded(int userId, int libraryId, int limit) public async Task<PagedList<SeriesDto>> GetRecentlyAdded(int libraryId, int userId, UserParams userParams)
{ {
if (libraryId == 0) if (libraryId == 0)
{ {
@ -302,24 +302,24 @@ namespace API.Data
.Select(library => library.Id) .Select(library => library.Id)
.ToList(); .ToList();
return await _context.Series var allQuery = _context.Series
.Where(s => userLibraries.Contains(s.LibraryId)) .Where(s => userLibraries.Contains(s.LibraryId))
.AsNoTracking() .AsNoTracking()
.OrderByDescending(s => s.Created) .OrderByDescending(s => s.Created)
.Take(limit)
.ProjectTo<SeriesDto>(_mapper.ConfigurationProvider) .ProjectTo<SeriesDto>(_mapper.ConfigurationProvider)
.ToListAsync(); .AsNoTracking();
return await PagedList<SeriesDto>.CreateAsync(allQuery, userParams.PageNumber, userParams.PageSize);
} }
return await _context.Series var query = _context.Series
.Where(s => s.LibraryId == libraryId) .Where(s => s.LibraryId == libraryId)
.AsNoTracking() .AsNoTracking()
.OrderByDescending(s => s.Created) .OrderByDescending(s => s.Created)
.Take(limit)
.ProjectTo<SeriesDto>(_mapper.ConfigurationProvider) .ProjectTo<SeriesDto>(_mapper.ConfigurationProvider)
.ToListAsync(); .AsNoTracking();
return await PagedList<SeriesDto>.CreateAsync(query, userParams.PageNumber, userParams.PageSize);
} }
/// <summary> /// <summary>

View File

@ -4,7 +4,7 @@
{ {
private const int MaxPageSize = 50; private const int MaxPageSize = 50;
public int PageNumber { get; set; } = 1; public int PageNumber { get; set; } = 1;
private int _pageSize = 10; private int _pageSize = 30;
public int PageSize public int PageSize
{ {

View File

@ -58,7 +58,7 @@ namespace API.Interfaces
Task<byte[]> GetVolumeCoverImageAsync(int volumeId); Task<byte[]> GetVolumeCoverImageAsync(int volumeId);
Task<byte[]> GetSeriesCoverImageAsync(int seriesId); Task<byte[]> GetSeriesCoverImageAsync(int seriesId);
Task<IEnumerable<SeriesDto>> GetInProgress(int userId, int libraryId, int limit); Task<IEnumerable<SeriesDto>> GetInProgress(int userId, int libraryId, int limit);
Task<IEnumerable<SeriesDto>> GetRecentlyAdded(int userId, int libraryId, int limit); Task<PagedList<SeriesDto>> GetRecentlyAdded(int libraryId, int userId, UserParams userParams);
Task<SeriesMetadataDto> GetSeriesMetadata(int seriesId); Task<SeriesMetadataDto> GetSeriesMetadata(int seriesId);
Task<PagedList<SeriesDto>> GetSeriesDtoForCollectionAsync(int collectionId, int userId, UserParams userParams); Task<PagedList<SeriesDto>> GetSeriesDtoForCollectionAsync(int collectionId, int userId, UserParams userParams);
} }