Skip to content

Kavita is a fast, feature rich, cross platform reading server. Built with the goal of being a full solution for all your reading needs. Setup your own server and share your reading collection with your friends and family.

Recently Added Page (#261)

Robbie Davis606e4c8b1274
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<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());
- if (user == null) return Ok(Array.Empty<SeriesDto>());
- 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<ActionResult<IEnumerable<SeriesDto>>> 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
/// <param name="libraryId">Library to restrict to, if 0, will apply to all libraries</param>
/// <param name="limit">How many series to pick.</param>
/// <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)
{
@@ -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<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)
.AsNoTracking()
.OrderByDescending(s => s.Created)
- .Take(limit)
.ProjectTo<SeriesDto>(_mapper.ConfigurationProvider)
- .ToListAsync();
-
-
+ .AsNoTracking();
+
+ return await PagedList<SeriesDto>.CreateAsync(query, userParams.PageNumber, userParams.PageSize);
}
/// <summary>
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<byte[]> GetVolumeCoverImageAsync(int volumeId);
Task<byte[]> GetSeriesCoverImageAsync(int seriesId);
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<PagedList<SeriesDto>> GetSeriesDtoForCollectionAsync(int collectionId, int userId, UserParams userParams);
}