diff --git a/RMuseum/Controllers/GanjoorController.cs b/RMuseum/Controllers/GanjoorController.cs index 4c08f707..55c7c4b2 100644 --- a/RMuseum/Controllers/GanjoorController.cs +++ b/RMuseum/Controllers/GanjoorController.cs @@ -3863,6 +3863,32 @@ namespace RMuseum.Controllers return Ok(res.Result); } + /// + /// get list of user suggested corrections + /// + /// + /// + [HttpGet] + [Route("quoted/suggest")] + [Authorize] + [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(IEnumerable))] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + public async Task GetUserQuotedSuggestionsAsync([FromQuery] PagingParameterModel paging) + { + Guid userId = + new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value); + + var res = + await _ganjoorService.GetUserQuotedSuggestionsAsync(userId, paging); + + // Paging Header + HttpContext.Response.Headers.Append("paging-headers", JsonConvert.SerializeObject(res.Result.PagingMeta)); + + if (!string.IsNullOrEmpty(res.ExceptionString)) + return BadRequest(res.ExceptionString); + return Ok(res.Result.Items); + } + /// /// next unmoderated quoted poem /// diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index 6d6d57ad..5bfb7408 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -2099,6 +2099,13 @@ + + + get list of user suggested corrections + + + + next unmoderated quoted poem @@ -15938,6 +15945,14 @@ + + + get user or all quoted suggestions + + if sent empty returns all suggestions + + + next unmoderated quoted poem @@ -17951,6 +17966,14 @@ + + + get user or all quoted suggestions + + if sent empty returns all suggestions + + + next unmoderated quoted poem diff --git a/RMuseum/Services/IGanjoorService.cs b/RMuseum/Services/IGanjoorService.cs index 512a7dd8..c7427731 100644 --- a/RMuseum/Services/IGanjoorService.cs +++ b/RMuseum/Services/IGanjoorService.cs @@ -1308,6 +1308,14 @@ namespace RMuseum.Services /// Task> SuggestGanjoorQuotedPoemAsync(GanjoorQuotedPoemViewModel quoted, Guid userId); + /// + /// get user or all quoted suggestions + /// + /// if sent empty returns all suggestions + /// + /// + Task> GetUserQuotedSuggestionsAsync(Guid userId, PagingParameterModel paging); + /// /// next unmoderated quoted poem /// diff --git a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-QuotedPoems.cs b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-QuotedPoems.cs index 1689f114..e486e18d 100644 --- a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-QuotedPoems.cs +++ b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-QuotedPoems.cs @@ -156,6 +156,37 @@ namespace RMuseum.Services.Implementation } } + /// + /// get user or all quoted suggestions + /// + /// if sent empty returns all suggestions + /// + /// + public async Task> GetUserQuotedSuggestionsAsync(Guid userId, PagingParameterModel paging) + { + var source = from dbSuggestion in + _context.GanjoorQuotedPoems.AsNoTracking() + where userId == Guid.Empty || dbSuggestion.SuggestedById == userId + orderby dbSuggestion.Id descending + select + dbSuggestion; + + (PaginationMetadata PagingMeta, GanjoorQuotedPoem[] Items) dbPaginatedResult = + await QueryablePaginator.Paginate(source, paging); + + List list = new List(); + foreach (var dbCorrection in dbPaginatedResult.Items) + { + list.Add + ( + new GanjoorQuotedPoemViewModel(dbCorrection) + ); + } + + return new RServiceResult<(PaginationMetadata, GanjoorQuotedPoemViewModel[])> + ((dbPaginatedResult.PagingMeta, list.ToArray())); + } + /// /// next unmoderated quoted poem ///