mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-05-24 00:52:23 -04:00
* Updated a ton of dependencies. PDFs reader got a big update from PDF.js 2.6 -> 3.x * Rolled back fontawesome update * Updated to latest angular patch. Fixed search being too long instead of just to the end of the browser screen. * Fixed alignment on download icon for download indicator in cards * Include progress information on Want To Read API and when marking something as Read, perform cleanup service on want to read. * Removed mark-read updating want to read. As there are series restrictions and it could be misleading. * Tweaked login page spacing when form is dirty * Replaced an object instantiation * Commented out a few tests that always break when updating NetVips (but always work) * Updated ngx-toastr * Added styles for alerts to Kavita. They were somehow missing. Fixed an issue where when OPDS was disabled, user preferences wouldn't tell them. * Wired up a reset base url button to match Ip Addresses * Disable ipAddress and port for docker users * Removed cache dir since it's kinda pointless currently * Started the update for OPDS BaseUrl support * Fixed OPDS url not reflecting base url on localhost * Added extra plumbing to allow sending a real email when testing a custom service. * Implemented OPDS support under Base Url. Added pagination to all APIs where applicable. * Added a swallowing of permission denied on Updating baseurl in index.html for inapplicable users. * Fixed a bad test
100 lines
3.4 KiB
C#
100 lines
3.4 KiB
C#
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);
|
|
|
|
await _unitOfWork.SeriesRepository.AddSeriesModifiers(User.GetUserId(), pagedList);
|
|
|
|
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);
|
|
if (user == null) return Unauthorized();
|
|
|
|
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);
|
|
if (user == null) return Unauthorized();
|
|
|
|
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");
|
|
}
|
|
}
|