fix: fixed stats controller

fix-stats-controller
tidusjar 2 years ago
parent 15fe04d4a6
commit 5e0cfbf354

@ -25,28 +25,29 @@ namespace Ombi.Core.Engine
{ {
// get all movie requests // get all movie requests
var movies = _movieRequest.GetWithUser(); var movies = _movieRequest.GetWithUser();
var filteredMovies = movies.Where(x => x.RequestedDate >= request.From && x.RequestedDate <= request.To); var filteredMovies = await movies.Where(x => x.RequestedDate >= request.From && x.RequestedDate <= request.To).ToListAsync();
var tv = _tvRequest.GetLite(); var tv = _tvRequest.GetLite();
var children = tv.SelectMany(x => var children = await tv.SelectMany(x =>
x.ChildRequests.Where(c => c.RequestedDate >= request.From && c.RequestedDate <= request.To)); x.ChildRequests.Where(c => c.RequestedDate >= request.From && c.RequestedDate <= request.To)).ToListAsync();
var userMovie = filteredMovies.GroupBy(x => x.RequestedUserId).OrderBy(x => x.Key).FirstOrDefaultAsync(); var userMovie = filteredMovies.GroupBy(x => x.RequestedUserId).OrderBy(x => x.Key).FirstOrDefault();
var userTv = children.GroupBy(x => x.RequestedUserId).OrderBy(x => x.Key).FirstOrDefaultAsync(); var userTv = children.GroupBy(x => x.RequestedUserId).OrderBy(x => x.Key).FirstOrDefault();
var moviesCount = filteredMovies.CountAsync();
var childrenCount = children.CountAsync(); var moviesCount = filteredMovies.Count;
var childrenCount = children.Count;
var availableMovies = var availableMovies =
filteredMovies.Select(x => x.MarkedAsAvailable >= request.From && x.MarkedAsAvailable <= request.To).CountAsync(); filteredMovies.Select(x => x.MarkedAsAvailable >= request.From && x.MarkedAsAvailable <= request.To).Count();
var availableChildren = children.Where(c => c.MarkedAsAvailable >= request.From && c.MarkedAsAvailable <= request.To).CountAsync(); var availableChildren = children.Where(c => c.MarkedAsAvailable >= request.From && c.MarkedAsAvailable <= request.To).Count();
return new UserStatsSummary return new UserStatsSummary
{ {
TotalMovieRequests = await moviesCount, TotalMovieRequests = moviesCount,
TotalTvRequests = await childrenCount, TotalTvRequests = childrenCount,
CompletedRequestsTv = await availableChildren, CompletedRequestsTv = availableChildren,
CompletedRequestsMovies = await availableMovies, CompletedRequestsMovies = availableMovies,
MostRequestedUserMovie = (await userMovie).FirstOrDefault()?.RequestedUser ?? new OmbiUser(), MostRequestedUserMovie = userMovie.FirstOrDefault()?.RequestedUser ?? new OmbiUser(),
MostRequestedUserTv = (await userTv).FirstOrDefault()?.RequestedUser ?? new OmbiUser(), MostRequestedUserTv = userTv.FirstOrDefault()?.RequestedUser ?? new OmbiUser(),
}; };
} }
} }

@ -21,7 +21,7 @@ namespace Ombi.Controllers.V1
private readonly IUserStatsEngine _statsEngine; private readonly IUserStatsEngine _statsEngine;
[HttpGet] [HttpGet]
public async Task<UserStatsSummary> GetUserStats(SummaryRequest req) public async Task<UserStatsSummary> GetUserStats([FromQuery]SummaryRequest req)
{ {
return await _statsEngine.GetSummary(req); return await _statsEngine.GetSummary(req);
} }

Loading…
Cancel
Save