diff --git a/API/Controllers/SeriesController.cs b/API/Controllers/SeriesController.cs index ac355abcb..320b08d6e 100644 --- a/API/Controllers/SeriesController.cs +++ b/API/Controllers/SeriesController.cs @@ -148,13 +148,22 @@ namespace API.Controllers } [HttpGet("recently-added")] - public async Task>> GetRecentlyAdded(int libraryId = 0, int limit = 20) + public async Task>> GetRecentlyAdded([FromQuery] UserParams userParams, int libraryId = 0) { var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername()); - if (user == null) return Ok(Array.Empty()); - return Ok(await _unitOfWork.SeriesRepository.GetRecentlyAdded(user.Id, libraryId, limit)); + var series = + 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")] public async Task>> GetInProgress(int libraryId = 0, int limit = 20) { diff --git a/API/Data/SeriesRepository.cs b/API/Data/SeriesRepository.cs index b77064898..c6575126b 100644 --- a/API/Data/SeriesRepository.cs +++ b/API/Data/SeriesRepository.cs @@ -291,7 +291,7 @@ namespace API.Data /// Library to restrict to, if 0, will apply to all libraries /// How many series to pick. /// - public async Task> GetRecentlyAdded(int userId, int libraryId, int limit) + public async Task> GetRecentlyAdded(int libraryId, int userId, UserParams userParams) { if (libraryId == 0) { @@ -301,25 +301,25 @@ namespace API.Data .AsNoTracking() .Select(library => library.Id) .ToList(); - - return await _context.Series + + var allQuery = _context.Series .Where(s => userLibraries.Contains(s.LibraryId)) .AsNoTracking() .OrderByDescending(s => s.Created) - .Take(limit) .ProjectTo(_mapper.ConfigurationProvider) - .ToListAsync(); + .AsNoTracking(); + + return await PagedList.CreateAsync(allQuery, userParams.PageNumber, userParams.PageSize); } - return await _context.Series + var query = _context.Series .Where(s => s.LibraryId == libraryId) .AsNoTracking() .OrderByDescending(s => s.Created) - .Take(limit) .ProjectTo(_mapper.ConfigurationProvider) - .ToListAsync(); - - + .AsNoTracking(); + + return await PagedList.CreateAsync(query, userParams.PageNumber, userParams.PageSize); } /// diff --git a/API/Helpers/UserParams.cs b/API/Helpers/UserParams.cs index 344738f6d..298719314 100644 --- a/API/Helpers/UserParams.cs +++ b/API/Helpers/UserParams.cs @@ -4,7 +4,7 @@ { private const int MaxPageSize = 50; public int PageNumber { get; set; } = 1; - private int _pageSize = 10; + private int _pageSize = 30; public int PageSize { diff --git a/API/Interfaces/ISeriesRepository.cs b/API/Interfaces/ISeriesRepository.cs index 266173ace..0b89d16b6 100644 --- a/API/Interfaces/ISeriesRepository.cs +++ b/API/Interfaces/ISeriesRepository.cs @@ -58,7 +58,7 @@ namespace API.Interfaces Task GetVolumeCoverImageAsync(int volumeId); Task GetSeriesCoverImageAsync(int seriesId); Task> GetInProgress(int userId, int libraryId, int limit); - Task> GetRecentlyAdded(int userId, int libraryId, int limit); + Task> GetRecentlyAdded(int libraryId, int userId, UserParams userParams); Task GetSeriesMetadata(int seriesId); Task> GetSeriesDtoForCollectionAsync(int collectionId, int userId, UserParams userParams); }