mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-07-09 03:04:19 -04:00
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:
parent
e6cfa4feca
commit
606e4c8b12
@ -148,13 +148,22 @@ 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")]
|
||||||
public async Task<ActionResult<IEnumerable<SeriesDto>>> GetInProgress(int libraryId = 0, int limit = 20)
|
public async Task<ActionResult<IEnumerable<SeriesDto>>> GetInProgress(int libraryId = 0, int limit = 20)
|
||||||
{
|
{
|
||||||
|
@ -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)
|
||||||
{
|
{
|
||||||
@ -301,25 +301,25 @@ namespace API.Data
|
|||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
.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>
|
||||||
|
@ -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
|
||||||
{
|
{
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user