Implemented the ability to move between volumes (reading) automatically without existing the app. (#198)

This commit is contained in:
Joseph Milazzo 2021-05-05 16:48:39 -05:00 committed by GitHub
parent 2be1630af3
commit d92e9e7602
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 77 additions and 12 deletions

View File

@ -239,5 +239,80 @@ namespace API.Controllers
return BadRequest("Could not save progress");
}
/// <summary>
/// Returns the next logical volume from the series.
/// </summary>
/// <param name="seriesId"></param>
/// <param name="volumeId"></param>
/// <param name="currentChapterId"></param>
/// <returns>chapter id for next manga</returns>
[HttpGet("next-chapter")]
public async Task<ActionResult<int>> GetNextChapter(int seriesId, int volumeId, int currentChapterId)
{
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername());
var volumes = await _unitOfWork.SeriesRepository.GetVolumesDtoAsync(seriesId, user.Id);
var currentVolume = await _unitOfWork.SeriesRepository.GetVolumeAsync(volumeId);
var next = false;
if (currentVolume.Number == 0)
{
foreach (var chapter in currentVolume.Chapters)
{
if (next)
{
return Ok(chapter.Id);
}
if (currentChapterId == chapter.Id) next = true;
}
}
foreach (var volume in volumes)
{
if (volume.Number == currentVolume.Number + 1)
{
return Ok(volume.Chapters.FirstOrDefault()?.Id);
}
}
return Ok(-1);
}
/// <summary>
/// Returns the previous logical volume from the series.
/// </summary>
/// <param name="seriesId"></param>
/// <param name="volumeId"></param>
/// <returns>chapter id for next manga</returns>
[HttpGet("prev-chapter")]
public async Task<ActionResult<int>> GetPreviousChapter(int seriesId, int volumeId, int currentChapterId)
{
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername());
var volumes = await _unitOfWork.SeriesRepository.GetVolumesDtoAsync(seriesId, user.Id);
var currentVolume = await _unitOfWork.SeriesRepository.GetVolumeAsync(volumeId);
var next = false;
if (currentVolume.Number == 0)
{
var chapters = currentVolume.Chapters.Reverse();
foreach (var chapter in chapters)
{
if (next)
{
return Ok(chapter.Id);
}
if (currentChapterId == chapter.Id) next = true;
}
}
foreach (var volume in volumes.Reverse())
{
if (volume.Number == currentVolume.Number - 1)
{
return Ok(volume.Chapters.LastOrDefault()?.Id);
}
}
return Ok(-1);
}
}
}

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using API.DTOs;
using API.Entities;
@ -89,18 +90,7 @@ namespace API.Controllers
return Ok(await _unitOfWork.VolumeRepository.GetChapterDtoAsync(chapterId));
}
/// <summary>
/// Returns the next logical volume from the series.
/// </summary>
/// <param name="seriesId"></param>
/// <param name="volumeId"></param>
/// <returns>chapter id for next manga</returns>
[HttpGet("next-volume")]
public async Task<ActionResult<int>> GetNextChapter(int seriesId, int volumeId)
{
return Ok();
}
[HttpPost("update-rating")]