Kavita/API/Controllers/TachiyomiController.cs
ThePromidius e2fb19b288
Tachiyomi unit tests and fixes (#1549)
* Moved logic from TachiyomiController.cs to TachiyomiService.cs

* Added GetLatestChapter Unit Tests

* Tachiyomi more tests.
Implemented test for yearly volumes

* MarkVolumesUntilAsRead unit test

* Registered tachiyomi service.
Added new test

* Fixed test pages

* Added missing check if its single-file volume

* Removed dead code

* Added method documentation and breaked thousands with `_`

* Review details and renamed test method to be more descriptive

* Review changes
- Removed automapper
- Added spaces after commas
- Added class documentation (copied from controller)
- Made Culture static
- Added 'R' doc linking to docs.ms
- Added trycatch to service when saving progress and logged
- Removed redundant qualifiers

* finishing touches

Co-authored-by: Joseph Milazzo <joseph.v.milazzo@gmail.com>
2022-09-20 09:46:46 -07:00

51 lines
2.0 KiB
C#

using System.Threading.Tasks;
using API.Data;
using API.Data.Repositories;
using API.DTOs;
using API.Extensions;
using API.Services;
using Microsoft.AspNetCore.Mvc;
namespace API.Controllers;
/// <summary>
/// All APIs are for Tachiyomi extension and app. They have hacks for our implementation and should not be used for any
/// other purposes.
/// </summary>
public class TachiyomiController : BaseApiController
{
private readonly IUnitOfWork _unitOfWork;
private readonly ITachiyomiService _tachiyomiService;
public TachiyomiController(IUnitOfWork unitOfWork, ITachiyomiService tachiyomiService)
{
_unitOfWork = unitOfWork;
_tachiyomiService = tachiyomiService;
}
/// <summary>
/// Given the series Id, this should return the latest chapter that has been fully read.
/// </summary>
/// <param name="seriesId"></param>
/// <returns>ChapterDTO of latest chapter. Only Chapter number is used by consuming app. All other fields may be missing.</returns>
[HttpGet("latest-chapter")]
public async Task<ActionResult<ChapterDto>> GetLatestChapter(int seriesId)
{
if (seriesId < 1) return BadRequest("seriesId must be greater than 0");
var userId = await _unitOfWork.UserRepository.GetUserIdByUsernameAsync(User.GetUsername());
return Ok(await _tachiyomiService.GetLatestChapter(seriesId, userId));
}
/// <summary>
/// Marks every chapter that is sorted below the passed number as Read. This will not mark any specials as read.
/// </summary>
/// <remarks>This is built for Tachiyomi and is not expected to be called by any other place</remarks>
/// <returns></returns>
[HttpPost("mark-chapter-until-as-read")]
public async Task<ActionResult<bool>> MarkChaptersUntilAsRead(int seriesId, float chapterNumber)
{
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername(), AppUserIncludes.Progress);
return Ok(await _tachiyomiService.MarkChaptersUntilAsRead(user, seriesId, chapterNumber));
}
}