diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index 93cd02b4..8db9c6e8 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -16068,6 +16068,29 @@ + + + approved quoted poems daily + + + + + + + + approved quoted poems grouped by user + + + + + + + + + summed up stats of approved quoted poems + + + donation service @@ -19066,6 +19089,29 @@ + + + approved quoted poems daily + + + + + + + + approved quoted poems grouped by user + + + + + + + + + summed up stats of approved quoted poems + + + Database Context diff --git a/RMuseum/Services/IContributionStatsService.cs b/RMuseum/Services/IContributionStatsService.cs index e5d761f5..fa2460f2 100644 --- a/RMuseum/Services/IContributionStatsService.cs +++ b/RMuseum/Services/IContributionStatsService.cs @@ -102,5 +102,28 @@ namespace RMuseum.Services /// Task> GetApprovedRelatedSongsSummedUpStatsAsync(); + /// + /// approved quoted poems daily + /// + /// + /// + /// + Task> GetApprovedQuotedPoemsGroupedByDateAsync(PagingParameterModel paging, Guid? userId); + + /// + /// approved quoted poems grouped by user + /// + /// + /// + /// + /// + Task> GetApprovedQuotedPoemsGroupedByUserAsync(PagingParameterModel paging, DateTime? day, Guid? userId); + + /// + /// summed up stats of approved quoted poems + /// + /// + Task> GetApprovedQuotedPoemsSummedUpStatsAsync(); + } } diff --git a/RMuseum/Services/Implementation/ContributionStatsService.cs b/RMuseum/Services/Implementation/ContributionStatsService.cs index 6d499150..58a3d1c0 100644 --- a/RMuseum/Services/Implementation/ContributionStatsService.cs +++ b/RMuseum/Services/Implementation/ContributionStatsService.cs @@ -468,6 +468,120 @@ namespace RMuseum.Services.Implementation } } + /// + /// approved quoted poems daily + /// + /// + /// + /// + public async Task> GetApprovedQuotedPoemsGroupedByDateAsync(PagingParameterModel paging, Guid? userId) + { + try + { + return new RServiceResult<(PaginationMetadata PagingMeta, GroupedByDateViewModel[] Tracks)>( + await QueryablePaginator.Paginate( + _context.GanjoorQuotedPoems + .Where(c => + c.Published && c.SuggestionDate != null + && + (userId == null || c.SuggestedById == userId) + ) + .GroupBy(a => a.SuggestionDate!.Value.Date) + .Select(a => new GroupedByDateViewModel() + { + Date = a.Key.Date.ToString(), + Number = a.Count(), + }).OrderByDescending(s => s.Date) + , paging)); + } + catch (Exception e) + { + return new RServiceResult<(PaginationMetadata PagingMeta, GroupedByDateViewModel[] Tracks)>((null, null), e.ToString()); + } + } + + /// + /// approved quoted poems grouped by user + /// + /// + /// + /// + /// + public async Task> GetApprovedQuotedPoemsGroupedByUserAsync(PagingParameterModel paging, DateTime? day, Guid? userId) + { + try + { + return new RServiceResult<(PaginationMetadata PagingMeta, GroupedByUserViewModel[] Tracks)>( + await QueryablePaginator.Paginate( + _context.GanjoorQuotedPoems + .Join + ( + _context.Users, + correction => correction.SuggestedById, + user => user.Id, + (correction, user) => new + { + correction.SuggestionDate, + UserId = user.Id, + UserName = user.NickName, + correction.Published, + } + ) + .Where(f => + f.Published && f.SuggestionDate != null + && + (day == null || f.SuggestionDate!.Value.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()); + } + } + + /// + /// summed up stats of approved quoted poems + /// + /// + public async Task> GetApprovedQuotedPoemsSummedUpStatsAsync() + { + try + { + return new RServiceResult + ( + new SummedUpViewModel() + { + Days = await _context.GanjoorQuotedPoems + .Where(f => f.Published && f.SuggestionDate != null + ) + .GroupBy(f => f.SuggestionDate!.Value.Date).CountAsync(), + TotalCount = await _context.GanjoorQuotedPoems + + .Where(f => f.Published + ) + .CountAsync(), + UserIds = await _context.GanjoorQuotedPoems + .Where(f => f.Published + ) + .GroupBy(f => f.SuggestedById).CountAsync(), + } + ); + + } + catch (Exception e) + { + return new RServiceResult(null, e.ToString()); + } + } + + ///