Skip to content

Kavita is a fast, feature rich, cross platform reading server. Built with the goal of being a full solution for all your reading needs. Setup your own server and share your reading collection with your friends and family.

Minor cleanup. Next commit will cleanup repositories and code base to be more concise.

Joseph Milazzo4a2296a18a6d
diff --git a/API/Controllers/SeriesController.cs b/API/Controllers/SeriesController.cs
index 7df62afc2..c8eee5db5 100644
--- a/API/Controllers/SeriesController.cs
+++ b/API/Controllers/SeriesController.cs
@@ -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")]
diff --git a/API/Data/SeriesRepository.cs b/API/Data/SeriesRepository.cs
index ff48c31af..2be26063d 100644
--- a/API/Data/SeriesRepository.cs
+++ b/API/Data/SeriesRepository.cs
@@ -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)
diff --git a/API/Entities/AppUserProgress.cs b/API/Entities/AppUserProgress.cs
index 2f9274e26..e9d6a2279 100644
--- a/API/Entities/AppUserProgress.cs
+++ b/API/Entities/AppUserProgress.cs
@@ -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; }
}
}
\ No newline at end of file
diff --git a/API/Interfaces/ISeriesRepository.cs b/API/Interfaces/ISeriesRepository.cs
index 1400431d7..3657a2a6e 100644
--- a/API/Interfaces/ISeriesRepository.cs
+++ b/API/Interfaces/ISeriesRepository.cs
@@ -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);