mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-05-31 04:04:19 -04:00
* Introduced a new claim on the Token to get UserId as well as Username, thus allowing for many places of reduced DB calls. All users will need to reauthenticate. Introduced UTC Dates throughout the application, they are not exposed in all DTOs, that will come later when we fully switch over. For now, Utc dates will be updated along side timezone specific dates. Refactored get-progress/progress api to be 50% faster by reducing how much data is loaded from the query. * Speed up the following apis: collection/search, download/bookmarks, reader/bookmark-info, recommended/quick-reads, recommended/quick-catchup-reads, recommended/highly-rated, recommended/more-in, recommended/rediscover, want-to-read/ * Added a migration to sync all dates with their new UTC counterpart. * Added LastReadingProgressUtc onto ChapterDto for some browsing apis, but not all. Added LastReadingProgressUtc to reading list items. Refactored the migration to run raw SQL which is much faster. * Added LastReadingProgressUtc onto ChapterDto for some browsing apis, but not all. Added LastReadingProgressUtc to reading list items. Refactored the migration to run raw SQL which is much faster. * Fixed the unit tests * Fixed an issue with auto mapper which was causing progress page number to not get sent to UI * series/volume has chapter last reading progress * Added filesize and library name on reading list item dto for CDisplayEx. * Some minor code cleanup * Forgot to fill a field
96 lines
3.2 KiB
C#
96 lines
3.2 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using API.Data;
|
|
using API.Data.Repositories;
|
|
using API.DTOs;
|
|
using API.DTOs.Filtering;
|
|
using API.DTOs.WantToRead;
|
|
using API.Extensions;
|
|
using API.Helpers;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace API.Controllers;
|
|
|
|
/// <summary>
|
|
/// Responsible for all things Want To Read
|
|
/// </summary>
|
|
[Route("api/want-to-read")]
|
|
public class WantToReadController : BaseApiController
|
|
{
|
|
private readonly IUnitOfWork _unitOfWork;
|
|
|
|
public WantToReadController(IUnitOfWork unitOfWork)
|
|
{
|
|
_unitOfWork = unitOfWork;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Return all Series that are in the current logged in user's Want to Read list, filtered
|
|
/// </summary>
|
|
/// <param name="userParams"></param>
|
|
/// <param name="filterDto"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<ActionResult<PagedList<SeriesDto>>> GetWantToRead([FromQuery] UserParams userParams, FilterDto filterDto)
|
|
{
|
|
userParams ??= new UserParams();
|
|
var pagedList = await _unitOfWork.SeriesRepository.GetWantToReadForUserAsync(User.GetUserId(), userParams, filterDto);
|
|
Response.AddPaginationHeader(pagedList.CurrentPage, pagedList.PageSize, pagedList.TotalCount, pagedList.TotalPages);
|
|
return Ok(pagedList);
|
|
}
|
|
|
|
[HttpGet]
|
|
public async Task<ActionResult<bool>> IsSeriesInWantToRead([FromQuery] int seriesId)
|
|
{
|
|
return Ok(await _unitOfWork.SeriesRepository.IsSeriesInWantToRead(User.GetUserId(), seriesId));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Given a list of Series Ids, add them to the current logged in user's Want To Read list
|
|
/// </summary>
|
|
/// <param name="dto"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("add-series")]
|
|
public async Task<ActionResult> AddSeries(UpdateWantToReadDto dto)
|
|
{
|
|
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername(),
|
|
AppUserIncludes.WantToRead);
|
|
|
|
var existingIds = user.WantToRead.Select(s => s.Id).ToList();
|
|
existingIds.AddRange(dto.SeriesIds);
|
|
|
|
var idsToAdd = existingIds.Distinct().ToList();
|
|
|
|
var seriesToAdd = await _unitOfWork.SeriesRepository.GetSeriesByIdsAsync(idsToAdd);
|
|
foreach (var series in seriesToAdd)
|
|
{
|
|
user.WantToRead.Add(series);
|
|
}
|
|
|
|
if (!_unitOfWork.HasChanges()) return Ok();
|
|
if (await _unitOfWork.CommitAsync()) return Ok();
|
|
|
|
return BadRequest("There was an issue updating Read List");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Given a list of Series Ids, remove them from the current logged in user's Want To Read list
|
|
/// </summary>
|
|
/// <param name="dto"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("remove-series")]
|
|
public async Task<ActionResult> RemoveSeries(UpdateWantToReadDto dto)
|
|
{
|
|
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername(),
|
|
AppUserIncludes.WantToRead);
|
|
|
|
user.WantToRead = user.WantToRead.Where(s => !dto.SeriesIds.Contains(s.Id)).ToList();
|
|
|
|
if (!_unitOfWork.HasChanges()) return Ok();
|
|
if (await _unitOfWork.CommitAsync()) return Ok();
|
|
|
|
return BadRequest("There was an issue updating Read List");
|
|
}
|
|
}
|