From 17c78b48a5b5f82ac3044321b8ee0144987d282e Mon Sep 17 00:00:00 2001 From: TidusJar Date: Thu, 2 Aug 2018 13:34:28 +0100 Subject: [PATCH] Added more to the stats, user stats is now available via the api !wip --- src/Ombi.Core/Engine/IUserStatsEngine.cs | 9 ++++++ src/Ombi.Core/Engine/UserStatsEngine.cs | 25 ++--------------- src/Ombi.DependencyInjection/IocExtensions.cs | 1 + src/Ombi/Controllers/StatsController.cs | 28 +++++++++++++++++++ 4 files changed, 40 insertions(+), 23 deletions(-) create mode 100644 src/Ombi.Core/Engine/IUserStatsEngine.cs create mode 100644 src/Ombi/Controllers/StatsController.cs diff --git a/src/Ombi.Core/Engine/IUserStatsEngine.cs b/src/Ombi.Core/Engine/IUserStatsEngine.cs new file mode 100644 index 000000000..3b8474749 --- /dev/null +++ b/src/Ombi.Core/Engine/IUserStatsEngine.cs @@ -0,0 +1,9 @@ +using System.Threading.Tasks; + +namespace Ombi.Core.Engine +{ + public interface IUserStatsEngine + { + Task GetSummary(SummaryRequest request); + } +} \ No newline at end of file diff --git a/src/Ombi.Core/Engine/UserStatsEngine.cs b/src/Ombi.Core/Engine/UserStatsEngine.cs index f416d56e3..06ab65f92 100644 --- a/src/Ombi.Core/Engine/UserStatsEngine.cs +++ b/src/Ombi.Core/Engine/UserStatsEngine.cs @@ -10,7 +10,7 @@ using Ombi.Store.Repository.Requests; namespace Ombi.Core.Engine { - public class UserStatsEngine + public class UserStatsEngine : IUserStatsEngine { public UserStatsEngine(OmbiUserManager um, IMovieRequestRepository movieRequest, ITvRequestRepository tvRequest) { @@ -25,27 +25,6 @@ namespace Ombi.Core.Engine public async Task GetSummary(SummaryRequest request) { - /* What do we want? - - This is Per week/month/all time (filter by date) - - 1. Total Requests - 2. Total Movie Requests - 3. Total Tv Requests - 4. Total Issues (If enabled) - 5. Total Requests fufilled (now available) - - Then - - 2. Most requested user Movie - 3. Most requested user tv - - Then - - 1. - - */ - // get all movie requests var movies = _movieRequest.GetWithUser(); var filteredMovies = movies.Where(x => x.RequestedDate >= request.From && x.RequestedDate <= request.To); @@ -84,7 +63,7 @@ namespace Ombi.Core.Engine public class UserStatsSummary { - public int TotalRequests => TotalTvRequests + TotalTvRequests; + public int TotalRequests => TotalTvRequests + TotalMovieRequests; public int TotalMovieRequests { get; set; } public int TotalTvRequests { get; set; } public int TotalIssues { get; set; } diff --git a/src/Ombi.DependencyInjection/IocExtensions.cs b/src/Ombi.DependencyInjection/IocExtensions.cs index dcae39cb0..2644fa9c7 100644 --- a/src/Ombi.DependencyInjection/IocExtensions.cs +++ b/src/Ombi.DependencyInjection/IocExtensions.cs @@ -79,6 +79,7 @@ namespace Ombi.DependencyInjection services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/src/Ombi/Controllers/StatsController.cs b/src/Ombi/Controllers/StatsController.cs new file mode 100644 index 000000000..0d871d80f --- /dev/null +++ b/src/Ombi/Controllers/StatsController.cs @@ -0,0 +1,28 @@ +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Ombi.Attributes; +using Ombi.Core.Engine; + +namespace Ombi.Controllers +{ + [ApiV1] + [Admin] + [Authorize] + [Produces("application/json")] + public class StatsController : Controller + { + public StatsController(IUserStatsEngine eng) + { + _statsEngine = eng; + } + + private readonly IUserStatsEngine _statsEngine; + + [HttpGet] + public async Task GetUserStats(SummaryRequest req) + { + return await _statsEngine.GetSummary(req); + } + } +} \ No newline at end of file