From 01f3569c20e18d77f5c532abc005b8b8db801d39 Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Wed, 26 Mar 2025 19:25:45 +0330 Subject: [PATCH] #478 GetApprovedEditsGroupedByDateAndUserAsync --- .../ViewModels/GroupedByDateUserViewModel.cs | 30 +++++++++++++ RMuseum/RMuseum.xml | 41 ++++++++++++++++- RMuseum/Services/IContributionStatsService.cs | 10 ++++- .../ContributionStatsService.cs | 44 +++++++++++++++++++ 4 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 RMuseum/Models/Generic/ViewModels/GroupedByDateUserViewModel.cs diff --git a/RMuseum/Models/Generic/ViewModels/GroupedByDateUserViewModel.cs b/RMuseum/Models/Generic/ViewModels/GroupedByDateUserViewModel.cs new file mode 100644 index 00000000..f829843a --- /dev/null +++ b/RMuseum/Models/Generic/ViewModels/GroupedByDateUserViewModel.cs @@ -0,0 +1,30 @@ +using System; + +namespace RMuseum.Models.Generic.ViewModels +{ + /// + /// grouped by date / user + /// + public class GroupedByDateUserViewModel + { + /// + /// date (day date or month or ...) + /// + public string Date { get; set; } + + /// + /// number of clicks + /// + public int Number { get; set; } + + /// + /// user id + /// + public Guid UserId { get; set; } + + /// + /// user name + /// + public string UserName { get; set; } + } +} diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index 8d3d9b60..a5901374 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -13362,6 +13362,31 @@ rejected + + + grouped by date / user + + + + + date (day date or month or ...) + + + + + number of clicks + + + + + user id + + + + + user name + + date (day date or month or ...) @@ -15804,12 +15829,19 @@ - get approved edits daily + approved edits daily + + + approved edits grouped by user / daily + + + + donation service @@ -18724,6 +18756,13 @@ + + + get approved edits grouped by user / daily + + + + Database Context diff --git a/RMuseum/Services/IContributionStatsService.cs b/RMuseum/Services/IContributionStatsService.cs index b6f6c9d3..7b1c531b 100644 --- a/RMuseum/Services/IContributionStatsService.cs +++ b/RMuseum/Services/IContributionStatsService.cs @@ -11,11 +11,19 @@ namespace RMuseum.Services public interface IContributionStatsService { /// - /// get approved edits daily + /// approved edits daily /// /// /// /// Task> GetApprovedEditsGroupedByDateAsync(PagingParameterModel paging, Guid? userId); + + /// + /// approved edits grouped by user / daily + /// + /// + /// + Task> GetApprovedEditsGroupedByDateAndUserAsync(PagingParameterModel paging); + } } diff --git a/RMuseum/Services/Implementation/ContributionStatsService.cs b/RMuseum/Services/Implementation/ContributionStatsService.cs index 723d40d7..5d1c31fd 100644 --- a/RMuseum/Services/Implementation/ContributionStatsService.cs +++ b/RMuseum/Services/Implementation/ContributionStatsService.cs @@ -45,6 +45,50 @@ namespace RMuseum.Services.Implementation } } + /// + /// get approved edits grouped by user / daily + /// + /// + /// + public async Task> GetApprovedEditsGroupedByDateAndUserAsync(PagingParameterModel paging) + { + try + { + return new RServiceResult<(PaginationMetadata PagingMeta, GroupedByDateUserViewModel[] Tracks)>( + await QueryablePaginator.Paginate( + _context.GanjoorPoemCorrections + .Join + ( + _context.Users, + correction => correction.UserId, + user => user.Id, + (correction, user) => new + { + correction.Id, + UserId = user.Id, + UserName = user.NickName, + DateTime = correction.Date, + correction.AffectedThePoem, + } + ) + .Where(f => f.AffectedThePoem) + .GroupBy(a => new { a.DateTime.Date, a.UserId, a.UserName }) + .Select(a => new GroupedByDateUserViewModel() + { + Date = a.Key.Date.ToString(), + UserId = a.Key.UserId, + UserName = a.Key.UserName, + Number = a.Count(), + }).OrderByDescending(s => s.Date).ThenBy(s => s.Number) + , paging)); + + } + catch (Exception e) + { + return new RServiceResult<(PaginationMetadata PagingMeta, GroupedByDateUserViewModel[] Tracks)>((null, null), e.ToString()); + } + } + /// /// Database Context ///