From 23bf337841d73f927d29fbad9dc5536030b9e819 Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Fri, 14 Feb 2025 21:23:29 +0330 Subject: [PATCH] #467 api --- RMuseum/Controllers/GanjoorController.cs | 245 +++++++++++++++++++++++ RMuseum/RMuseum.xml | 74 +++++++ RMuseum/Services/IGanjoorService.cs | 11 + 3 files changed, 330 insertions(+) diff --git a/RMuseum/Controllers/GanjoorController.cs b/RMuseum/Controllers/GanjoorController.cs index 8f88d037..b398273d 100644 --- a/RMuseum/Controllers/GanjoorController.cs +++ b/RMuseum/Controllers/GanjoorController.cs @@ -4506,6 +4506,251 @@ namespace RMuseum.Controllers } + /// + /// send cat corrections + /// + /// + /// + [HttpPost] + [Route("cat/correction")] + [Authorize] + [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorCatCorrectionViewModel))] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + [ProducesResponseType((int)HttpStatusCode.NotFound)] + public async Task SuggestCatCorrectionAsync([FromBody] GanjoorCatCorrectionViewModel correction) + { + if (ReadOnlyMode) + return BadRequest("سایت به دلایل فنی مثل انتقال سرور موقتاً در حالت فقط خواندنی قرار دارد. لطفاً ساعاتی دیگر مجدداً تلاش کنید."); + + correction.UserId = + new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value); + + RServiceResult res = + await _ganjoorService.SuggestCatCorrectionAsync(correction); + if (!string.IsNullOrEmpty(res.ExceptionString)) + return BadRequest(res.ExceptionString); + if (res.Result == null) + return NotFound(); + return Ok(res.Result); + } + + /// + /// delete unreviewed user cat corrections for a poem + /// + /// + /// + [HttpDelete] + [Route("cat/correction/{id}")] + [Authorize] + [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + [ProducesResponseType((int)HttpStatusCode.NotFound)] + public async Task DeleteCatCorrectionsAsync(int id) + { + if (ReadOnlyMode) + return BadRequest("سایت به دلایل فنی مثل انتقال سرور موقتاً در حالت فقط خواندنی قرار دارد. لطفاً ساعاتی دیگر مجدداً تلاش کنید."); + + var userId = + new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value); + + var res = + await _ganjoorService.DeleteCatCorrectionsAsync(userId, id); + if (!string.IsNullOrEmpty(res.ExceptionString)) + return BadRequest(res.ExceptionString); + return Ok(); + } + + /// + /// returns last unreviewed correction from the user for a cat + /// + /// + /// + [HttpGet] + [Route("cat/correction/last/{id}")] + [Authorize] + [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorCatCorrectionViewModel))] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + [ProducesResponseType((int)HttpStatusCode.NotFound)] + public async Task GetLastUnreviewedUserCorrectionForCatAsync(int id) + { + Guid userId = + new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value); + + RServiceResult res = + await _ganjoorService.GetLastUnreviewedUserCorrectionForCatAsync(userId, id); + if (!string.IsNullOrEmpty(res.ExceptionString)) + return BadRequest(res.ExceptionString); + return Ok(res.Result);//might be null + } + + /// + /// get list of user suggested cat corrections + /// + /// + /// + [HttpGet] + [Route("cat/corrections/mine")] + [Authorize] + [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(IEnumerable))] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + public async Task GetUserCatCorrectionsAsync([FromQuery] PagingParameterModel paging) + { + Guid userId = + new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value); + + var res = + await _ganjoorService.GetUserCatCorrectionsAsync(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); + } + + /// + /// get list of all suggested cat corrections + /// + /// + /// userId + /// + [HttpGet] + [Route("cat/corrections/all")] + [Authorize(Policy = RMuseumSecurableItem.GanjoorEntityShortName + ":" + SecurableItem.ModifyOperationShortName)] + [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(IEnumerable))] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + public async Task GetAllCatCorrectionsAsync([FromQuery] PagingParameterModel paging, Guid? userId = null) + { + + var res = + await _ganjoorService.GetUserCatCorrectionsAsync(userId ?? Guid.Empty, 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); + } + + /// + /// effective corrections for a cat + /// + /// + /// + /// + + [HttpGet] + [Route("cat/{id}/corrections/effective")] + [AllowAnonymous] + [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(IEnumerable))] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + [ProducesResponseType((int)HttpStatusCode.NotFound)] + public async Task GetCatEffectiveCorrectionsAsync(int id, [FromQuery] PagingParameterModel paging) + { + var res = + await _ganjoorService.GetCatEffectiveCorrectionsAsync(id, 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); + } + + /// + /// get cat correction by id + /// + /// + /// + [HttpGet] + [Route("cat/correction/{id}")] + [Authorize(Policy = RMuseumSecurableItem.GanjoorEntityShortName + ":" + SecurableItem.ModifyOperationShortName)] + [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorCatCorrectionViewModel))] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + [ProducesResponseType((int)HttpStatusCode.NotFound)] + public async Task GetCatCorrectionByIdAsync(int id) + { + Guid userId = + new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value); + + RServiceResult res = + await _ganjoorService.GetCatCorrectionByIdAsync(id); + if (!string.IsNullOrEmpty(res.ExceptionString)) + return BadRequest(res.ExceptionString); + return Ok(res.Result);//might be null + } + + /// + /// get next unreviewed cat correction + /// + /// + /// + /// + [HttpGet] + [Route("cat/correction/next")] + [Authorize(Policy = RMuseumSecurableItem.GanjoorEntityShortName + ":" + SecurableItem.ModifyOperationShortName)] + [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorCatCorrectionViewModel))] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + [ProducesResponseType((int)HttpStatusCode.NotFound)] + public async Task GetNextUnreviewedCatCorrectionAsync(int skip = 0, bool onlyUserCorrections = false) + { + RServiceResult res = + await _ganjoorService.GetNextUnreviewedCatCorrectionAsync(skip, onlyUserCorrections); + if (!string.IsNullOrEmpty(res.ExceptionString)) + return BadRequest(res.ExceptionString); + + var resCount = await _ganjoorService.GetUnreviewedCatCorrectionCountAsync(onlyUserCorrections); + if (!string.IsNullOrEmpty(resCount.ExceptionString)) + return BadRequest(resCount.ExceptionString); + + // Paging Header + HttpContext.Response.Headers.Append("paging-headers", + JsonConvert.SerializeObject( + new PaginationMetadata() + { + totalCount = resCount.Result, + pageSize = -1, + currentPage = -1, + hasNextPage = false, + hasPreviousPage = false, + totalPages = -1 + }) + ); + + return Ok(res.Result);//might be null + } + + /// + /// moderate cat correction + /// + /// + /// + [HttpPost] + [Route("cat/correction/moderate")] + [Authorize(Policy = RMuseumSecurableItem.GanjoorEntityShortName + ":" + SecurableItem.ModifyOperationShortName)] + [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorCatCorrectionViewModel))] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + [ProducesResponseType((int)HttpStatusCode.NotFound)] + public async Task ModerateCatCorrectionAsync([FromBody] GanjoorCatCorrectionViewModel correction) + { + if (ReadOnlyMode) + return BadRequest("سایت به دلایل فنی مثل انتقال سرور موقتاً در حالت فقط خواندنی قرار دارد. لطفاً ساعاتی دیگر مجدداً تلاش کنید."); + + Guid userId = + new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value); + + RServiceResult res = + await _ganjoorService.ModerateCatCorrectionAsync(userId, correction); + if (!string.IsNullOrEmpty(res.ExceptionString)) + return BadRequest(res.ExceptionString); + if (res.Result == null) + return NotFound(); + return Ok(res.Result); + } + /// diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index dd051afe..44c5d21a 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -2378,6 +2378,72 @@ + + + send cat corrections + + + + + + + delete unreviewed user cat corrections for a poem + + + + + + + returns last unreviewed correction from the user for a cat + + + + + + + get list of user suggested cat corrections + + + + + + + get list of all suggested cat corrections + + + userId + + + + + effective corrections for a cat + + + + + + + + get cat correction by id + + + + + + + get next unreviewed cat correction + + + + + + + + moderate cat correction + + + + readonly mode @@ -17472,6 +17538,14 @@ + + + moderate cat correction + + + + + translation service implementation diff --git a/RMuseum/Services/IGanjoorService.cs b/RMuseum/Services/IGanjoorService.cs index 47b37ee1..b054f92c 100644 --- a/RMuseum/Services/IGanjoorService.cs +++ b/RMuseum/Services/IGanjoorService.cs @@ -1617,5 +1617,16 @@ namespace RMuseum.Services /// Task> GetUnreviewedCatCorrectionCountAsync(bool onlyUserCorrections); + + /// + /// moderate cat correction + /// + /// + /// + /// + Task> ModerateCatCorrectionAsync(Guid userId, + GanjoorCatCorrectionViewModel moderation); + + } }