From 3d2560440eaab5a4740bce7ace5da6c88d9a443f Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Wed, 26 Mar 2025 19:36:27 +0330 Subject: [PATCH] #478 GetApprovedEditsGroupedByUserAsync --- .../ViewModels/GroupedByUserViewModel.cs | 25 +++++++++ RMuseum/RMuseum.xml | 42 ++++++++++++++- RMuseum/Services/IContributionStatsService.cs | 9 ++++ .../ContributionStatsService.cs | 51 +++++++++++++++++-- 4 files changed, 122 insertions(+), 5 deletions(-) create mode 100644 RMuseum/Models/Generic/ViewModels/GroupedByUserViewModel.cs diff --git a/RMuseum/Models/Generic/ViewModels/GroupedByUserViewModel.cs b/RMuseum/Models/Generic/ViewModels/GroupedByUserViewModel.cs new file mode 100644 index 00000000..15ee11cf --- /dev/null +++ b/RMuseum/Models/Generic/ViewModels/GroupedByUserViewModel.cs @@ -0,0 +1,25 @@ +using System; + +namespace RMuseum.Models.Generic.ViewModels +{ + /// + /// grouped by user view model + /// + public class GroupedByUserViewModel + { + /// + /// 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 a5901374..d3a28941 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -13397,6 +13397,26 @@ number of clicks + + + grouped by user view model + + + + + number of clicks + + + + + user id + + + + + user name + + Import Job @@ -15842,6 +15862,15 @@ + + + approved edits grouped by user + + + + + + donation service @@ -18750,7 +18779,7 @@ - get approved edits daily + approved edits daily @@ -18758,11 +18787,20 @@ - get approved edits grouped by user / daily + approved edits grouped by user / daily + + + approved edits grouped by user + + + + + + Database Context diff --git a/RMuseum/Services/IContributionStatsService.cs b/RMuseum/Services/IContributionStatsService.cs index 7b1c531b..c02619c9 100644 --- a/RMuseum/Services/IContributionStatsService.cs +++ b/RMuseum/Services/IContributionStatsService.cs @@ -25,5 +25,14 @@ namespace RMuseum.Services /// Task> GetApprovedEditsGroupedByDateAndUserAsync(PagingParameterModel paging); + /// + /// approved edits grouped by user + /// + /// + /// + /// + /// + Task> GetApprovedEditsGroupedByUserAsync(PagingParameterModel paging, DateTime? day, Guid? userId); + } } diff --git a/RMuseum/Services/Implementation/ContributionStatsService.cs b/RMuseum/Services/Implementation/ContributionStatsService.cs index 5d1c31fd..2b6f5d93 100644 --- a/RMuseum/Services/Implementation/ContributionStatsService.cs +++ b/RMuseum/Services/Implementation/ContributionStatsService.cs @@ -14,7 +14,7 @@ namespace RMuseum.Services.Implementation public class ContributionStatsService : IContributionStatsService { /// - /// get approved edits daily + /// approved edits daily /// /// /// @@ -46,7 +46,7 @@ namespace RMuseum.Services.Implementation } /// - /// get approved edits grouped by user / daily + /// approved edits grouped by user / daily /// /// /// @@ -64,7 +64,6 @@ namespace RMuseum.Services.Implementation user => user.Id, (correction, user) => new { - correction.Id, UserId = user.Id, UserName = user.NickName, DateTime = correction.Date, @@ -89,6 +88,52 @@ namespace RMuseum.Services.Implementation } } + /// + /// approved edits grouped by user + /// + /// + /// + /// + /// + public async Task> GetApprovedEditsGroupedByUserAsync(PagingParameterModel paging, DateTime? day, Guid? userId) + { + try + { + return new RServiceResult<(PaginationMetadata PagingMeta, GroupedByUserViewModel[] Tracks)>( + await QueryablePaginator.Paginate( + _context.GanjoorPoemCorrections + .Join + ( + _context.Users, + correction => correction.UserId, + user => user.Id, + (correction, user) => new + { + correction.Date, + UserId = user.Id, + UserName = user.NickName, + correction.AffectedThePoem, + } + ) + .Where(f => + f.AffectedThePoem + && + (day == null || f.Date.Date == day) && (userId == null || f.UserId == userId)) + .GroupBy(a => new { a.UserId, a.UserName }).Select(a => new GroupedByUserViewModel() + { + UserId = a.Key.UserId, + UserName = a.Key.UserName, + Number = a.Count(), + }).OrderByDescending(s => s.Number) + , paging)); + + } + catch (Exception e) + { + return new RServiceResult<(PaginationMetadata PagingMeta, GroupedByUserViewModel[] Tracks)>((null, null), e.ToString()); + } + } + /// /// Database Context ///