mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-05-24 00:52:23 -04:00
Minor cleanup. Next commit will cleanup repositories and code base to be more concise.
This commit is contained in:
parent
effdf07cef
commit
4a2296a18a
@ -56,9 +56,14 @@ namespace API.Controllers
|
||||
}
|
||||
|
||||
[HttpGet("volumes")]
|
||||
public async Task<ActionResult<IEnumerable<VolumeDto>>> GetVolumes(int seriesId)
|
||||
public async Task<ActionResult<IEnumerable<VolumeDto>>> GetVolumes(int seriesId, bool forUser = true)
|
||||
{
|
||||
return Ok(await _seriesRepository.GetVolumesDtoAsync(seriesId));
|
||||
if (forUser)
|
||||
{
|
||||
var user = await _userRepository.GetUserByUsernameAsync(User.GetUsername());
|
||||
return Ok(await _seriesRepository.GetVolumesDtoAsync(seriesId, user.Id));
|
||||
}
|
||||
return Ok(await _seriesRepository.GetVolumesDtoAsync(seriesId)); // TODO: Refactor out forUser = false since everything is user based
|
||||
}
|
||||
|
||||
[HttpGet("volume")]
|
||||
|
@ -68,12 +68,26 @@ namespace API.Data
|
||||
return series;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<VolumeDto>> GetVolumesDtoAsync(int seriesId)
|
||||
public async Task<IEnumerable<VolumeDto>> GetVolumesDtoAsync(int seriesId, int userId = 0)
|
||||
{
|
||||
return await _context.Volume
|
||||
var volumes = await _context.Volume
|
||||
.Where(vol => vol.SeriesId == seriesId)
|
||||
.OrderBy(volume => volume.Number)
|
||||
.ProjectTo<VolumeDto>(_mapper.ConfigurationProvider).ToListAsync();
|
||||
if (userId > 0)
|
||||
{
|
||||
var userProgress = await _context.AppUserProgresses
|
||||
.Where(p => p.AppUserId == userId && volumes.Select(s => s.Id).Contains(p.VolumeId))
|
||||
.ToListAsync();
|
||||
|
||||
foreach (var v in volumes)
|
||||
{
|
||||
v.PagesRead = userProgress.Where(p => p.VolumeId == v.Id).Sum(p => p.PagesRead);
|
||||
}
|
||||
}
|
||||
|
||||
return volumes;
|
||||
|
||||
}
|
||||
|
||||
public IEnumerable<Volume> GetVolumes(int seriesId)
|
||||
|
@ -11,7 +11,6 @@
|
||||
public AppUser AppUser { get; set; }
|
||||
public int AppUserId { get; set; }
|
||||
public int VolumeId { get; set; }
|
||||
public int SeriesId { get; set; } // shortcut
|
||||
//public bool VolumeCompleted { get; set; } // This will be set true if PagesRead == Sum of MangaFiles on volume
|
||||
public int SeriesId { get; set; }
|
||||
}
|
||||
}
|
@ -13,12 +13,12 @@ namespace API.Interfaces
|
||||
Series GetSeriesByName(string name);
|
||||
bool SaveAll();
|
||||
Task<IEnumerable<SeriesDto>> GetSeriesDtoForLibraryIdAsync(int libraryId, int userId = 0);
|
||||
Task<IEnumerable<VolumeDto>> GetVolumesDtoAsync(int seriesId);
|
||||
Task<IEnumerable<VolumeDto>> GetVolumesDtoAsync(int seriesId, int userId = 0);
|
||||
IEnumerable<Volume> GetVolumes(int seriesId);
|
||||
Task<SeriesDto> GetSeriesDtoByIdAsync(int seriesId);
|
||||
|
||||
Task<Volume> GetVolumeAsync(int volumeId);
|
||||
Task<VolumeDto> GetVolumeDtoAsync(int volumeId);
|
||||
Task<VolumeDto> GetVolumeDtoAsync(int volumeId); // TODO: Likely need to update here
|
||||
|
||||
Task<IEnumerable<Volume>> GetVolumesForSeriesAsync(int[] seriesIds);
|
||||
Task<bool> DeleteSeriesAsync(int seriesId);
|
||||
|
Loading…
x
Reference in New Issue
Block a user