From c734ce9f5df93662e1daaa092aa72dd7ad899c52 Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Tue, 29 Mar 2022 11:17:19 +0430 Subject: [PATCH] docs: #302 API for manually modfiying duplicates data --- RMuseum/Controllers/GanjoorController.cs | 36 +++++++++++++ RMuseum/RMuseum.xml | 48 +++++++++++++++++ RMuseum/Services/IGanjoorService.cs | 16 ++++++ .../Services/Implementation/GanjoorService.cs | 52 +++++++++++++++++++ 4 files changed, 152 insertions(+) diff --git a/RMuseum/Controllers/GanjoorController.cs b/RMuseum/Controllers/GanjoorController.cs index f1fe1f22..efa19d11 100644 --- a/RMuseum/Controllers/GanjoorController.cs +++ b/RMuseum/Controllers/GanjoorController.cs @@ -2673,6 +2673,42 @@ namespace RMuseum.Controllers return Ok(); } + /// + /// manually add a duplicate for a poems + /// + /// + /// + /// + /// + [HttpPost("duplicates/manual/{srcCatId}/{srcPoemId}/{destPoemId}")] + [Authorize(Policy = RMuseumSecurableItem.GanjoorEntityShortName + ":" + SecurableItem.ModifyOperationShortName)] + [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + public async Task AdDuplicateAsync(int srcCatId, int srcPoemId, int destPoemId) + { + var res = await _ganjoorService.AdDuplicateAsync(srcCatId, srcPoemId, destPoemId); + if (!string.IsNullOrEmpty(res.ExceptionString)) + return BadRequest(res.ExceptionString); + return Ok(); + } + + /// + /// delete a duplicate + /// + /// + /// + [HttpDelete("duplicates/{id}")] + [Authorize(Policy = RMuseumSecurableItem.GanjoorEntityShortName + ":" + SecurableItem.ModifyOperationShortName)] + [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + public async Task DeleteDuplicateAsync(int id) + { + var res = await _ganjoorService.DeleteDuplicateAsync(id); + if (!string.IsNullOrEmpty(res.ExceptionString)) + return BadRequest(res.ExceptionString); + return Ok(); + } + /// /// list of category saved duplicated poems /// diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index 019aff7e..02e3b1bc 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -1648,6 +1648,22 @@ + + + manually add a duplicate for a poems + + + + + + + + + delete a duplicate + + + + list of category saved duplicated poems @@ -11433,6 +11449,22 @@ + + + manually add a duplicate for a poems + + + + + + + + + delete duplicate + + + + start removing category duplicates @@ -13718,6 +13750,22 @@ + + + manually add a duplicate for a poems + + + + + + + + + delete duplicate + + + + aggressive cache diff --git a/RMuseum/Services/IGanjoorService.cs b/RMuseum/Services/IGanjoorService.cs index f708cf3a..e203b32b 100644 --- a/RMuseum/Services/IGanjoorService.cs +++ b/RMuseum/Services/IGanjoorService.cs @@ -877,6 +877,22 @@ namespace RMuseum.Services /// Task> GetCategoryDuplicates(int catId); + /// + /// manually add a duplicate for a poems + /// + /// + /// + /// + /// + Task> AdDuplicateAsync(int srcCatId, int srcPoemId, int destPoemId); + + /// + /// delete duplicate + /// + /// + /// + Task> DeleteDuplicateAsync(int id); + /// /// start removing category duplicates /// diff --git a/RMuseum/Services/Implementation/GanjoorService.cs b/RMuseum/Services/Implementation/GanjoorService.cs index 95f7134f..d481daea 100644 --- a/RMuseum/Services/Implementation/GanjoorService.cs +++ b/RMuseum/Services/Implementation/GanjoorService.cs @@ -3294,6 +3294,58 @@ namespace RMuseum.Services.Implementation } } + /// + /// manually add a duplicate for a poems + /// + /// + /// + /// + /// + public async Task> AdDuplicateAsync(int srcCatId, int srcPoemId, int destPoemId) + { + try + { + var alreadyDup = await _context.GanjoorDuplicates.AsNoTracking().Where(p => p.SrcPoemId == srcPoemId).FirstOrDefaultAsync(); + if(alreadyDup != null) + { + return new RServiceResult(false, $"already dupped : {alreadyDup.DestPoemId}"); + } + var dup = new GanjoorDuplicate() + { + SrcCatId = srcCatId, + SrcPoemId = srcPoemId, + DestPoemId = destPoemId + }; + _context.GanjoorDuplicates.Add(dup); + + return new RServiceResult(true); + } + catch (Exception exp) + { + return new RServiceResult(false, exp.ToString()); + } + } + + /// + /// delete duplicate + /// + /// + /// + public async Task> DeleteDuplicateAsync(int id) + { + try + { + var dup = await _context.GanjoorDuplicates.Where(d => d.Id == id).SingleAsync(); + _context.Remove(dup); + await _context.SaveChangesAsync(); + return new RServiceResult(false); + } + catch (Exception exp) + { + return new RServiceResult(false, exp.ToString()); + } + } + /// /// aggressive cache ///