Revert "Unify ChapterRating with Rating"

This wasn't working out, there is still some duplicate code. But not
that much, and from the API, there is no different. Hooray!
This commit is contained in:
Amelia 2025-04-28 17:11:39 +02:00
parent 052b3f9fe4
commit 184cf46533
No known key found for this signature in database
GPG key ID: D6D0ECE365407EAA
21 changed files with 389 additions and 87 deletions

View file

@ -758,7 +758,7 @@ public class SeriesRepository : ISeriesRepository
foreach (var s in series)
{
s.PagesRead = userProgress.Where(p => p.SeriesId == s.Id).Sum(p => p.PagesRead);
var rating = userRatings.SingleOrDefault(r => r.SeriesId == s.Id && r.ChapterId == null);
var rating = userRatings.SingleOrDefault(r => r.SeriesId == s.Id);
if (rating != null)
{
s.UserRating = rating.Rating;
@ -2177,14 +2177,14 @@ public class SeriesRepository : ISeriesRepository
{
// If there is 0 or 1 rating and that rating is you, return 0 back
var countOfRatingsThatAreUser = await _context.AppUserRating
.Where(r => r.SeriesId == seriesId && r.HasBeenRated && r.ChapterId == null)
.Where(r => r.SeriesId == seriesId && r.HasBeenRated)
.CountAsync(u => u.AppUserId == userId);
if (countOfRatingsThatAreUser == 1)
{
return 0;
}
var avg = (await _context.AppUserRating
.Where(r => r.SeriesId == seriesId && r.HasBeenRated && r.ChapterId == null)
.Where(r => r.SeriesId == seriesId && r.HasBeenRated)
.AverageAsync(r => (int?) r.Rating));
return avg.HasValue ? (int) (avg.Value * 20) : 0;
}