diff --git a/RMuseum/Controllers/ContributionStatsController.cs b/RMuseum/Controllers/ContributionStatsController.cs index 7bf0992e..99bc462f 100644 --- a/RMuseum/Controllers/ContributionStatsController.cs +++ b/RMuseum/Controllers/ContributionStatsController.cs @@ -316,6 +316,79 @@ namespace RMuseum.Controllers return Ok(result); } + /// + /// approved quoted poems daily + /// + /// + /// + /// + [HttpGet("quoteds/daily")] + [AllowAnonymous] + [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(IEnumerable))] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + public async Task GetApprovedQuotedPoemsGroupedByDateAsync([FromQuery] PagingParameterModel paging, Guid? userId = null) + { + var cacheKey = $"quoteds/daily/{DateTime.Now.Date}/{paging.PageSize}/{paging.PageNumber}/{userId ?? Guid.Empty}"; + if (!_memoryCache.TryGetValue(cacheKey, out (PaginationMetadata PagingMeta, GroupedByDateViewModel[] Tracks) pagedResult)) + { + var res = await _service.GetApprovedQuotedPoemsGroupedByDateAsync(paging, userId); + if (!string.IsNullOrEmpty(res.ExceptionString)) + return BadRequest(res.ExceptionString); + pagedResult = res.Result; + } + // Paging Header + HttpContext.Response.Headers.Append("paging-headers", JsonConvert.SerializeObject(pagedResult.PagingMeta)); + + return Ok(pagedResult.Tracks); + } + + /// + /// approved quoted poems grouped by user + /// + /// + /// + /// + /// + [HttpGet("quoteds/by/user")] + [AllowAnonymous] + [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(IEnumerable))] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + public async Task GetApprovedQuotedPoemsGroupedByUserAsync([FromQuery] PagingParameterModel paging, DateTime? day, Guid? userId) + { + var cacheKey = $"quoteds/by/user/{(day ?? DateTime.Now).Date}/{paging.PageSize}/{paging.PageNumber}/{userId ?? Guid.Empty}"; + if (!_memoryCache.TryGetValue(cacheKey, out (PaginationMetadata PagingMeta, GroupedByUserViewModel[] Tracks) pagedResult)) + { + var res = await _service.GetApprovedQuotedPoemsGroupedByUserAsync(paging, day, userId); + if (!string.IsNullOrEmpty(res.ExceptionString)) + return BadRequest(res.ExceptionString); + pagedResult = res.Result; + } + + // Paging Header + HttpContext.Response.Headers.Append("paging-headers", JsonConvert.SerializeObject(pagedResult.PagingMeta)); + + return Ok(pagedResult.Tracks); + } + + /// + /// summed up stats of quoted poems + /// + /// + [HttpGet("quoteds")] + [AllowAnonymous] + [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(SummedUpViewModel))] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + public async Task GetApprovedQuotedPoemsSummedUpStatsAsync() + { + if (!_memoryCache.TryGetValue($"quoteds/{DateTime.Now.Date}", out SummedUpViewModel result)) + { + var res = await _service.GetApprovedQuotedPoemsSummedUpStatsAsync(); + if (!string.IsNullOrEmpty(res.ExceptionString)) + return BadRequest(res.ExceptionString); + result = res.Result; + } + return Ok(result); + } diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index 8db9c6e8..4a0002c9 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -854,6 +854,29 @@ + + + approved quoted poems daily + + + + + + + + approved quoted poems grouped by user + + + + + + + + + summed up stats of quoted poems + + + service