From e0f5927c81ea2ec453867bb2a4d2cb6210f4d0b9 Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Mon, 28 Mar 2022 13:15:01 +0430 Subject: [PATCH] docs: api for deleting a category --- RMuseum/Controllers/GanjoorController.cs | 20 +++++++++++++ RMuseum/RMuseum.xml | 21 +++++++++++++ RMuseum/Services/IGanjoorService.cs | 7 +++++ .../Services/Implementation/GanjoorService.cs | 30 +++++++++++++++++++ 4 files changed, 78 insertions(+) diff --git a/RMuseum/Controllers/GanjoorController.cs b/RMuseum/Controllers/GanjoorController.cs index 79177dc6..f1fe1f22 100644 --- a/RMuseum/Controllers/GanjoorController.cs +++ b/RMuseum/Controllers/GanjoorController.cs @@ -541,6 +541,26 @@ namespace RMuseum.Controllers return Ok(res.Result); } + /// + /// delete a category + /// + /// + /// + + [HttpDelete] + [Route("cat/{id}")] + [Authorize(Policy = RMuseumSecurableItem.GanjoorEntityShortName + ":" + SecurableItem.ModifyOperationShortName)] + [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorPageCompleteViewModel))] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + [ProducesResponseType((int)HttpStatusCode.NotFound)] + public async Task DeleteCategoryAsync(int id) + { + var res = await _ganjoorService.DeleteCategoryAsync(id); + if (!string.IsNullOrEmpty(res.ExceptionString)) + return BadRequest(res.ExceptionString); + return Ok(); + } + /// /// Start Finding Missing Rhythms /// diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index cdc933a0..019aff7e 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -997,6 +997,13 @@ + + + delete a category + + + + Start Finding Missing Rhythms @@ -11389,6 +11396,13 @@ + + + delete a category + + + + set category poems language tag @@ -13643,6 +13657,13 @@ + + + delete a category + + + + chaneg poet image diff --git a/RMuseum/Services/IGanjoorService.cs b/RMuseum/Services/IGanjoorService.cs index 5ae1105f..f708cf3a 100644 --- a/RMuseum/Services/IGanjoorService.cs +++ b/RMuseum/Services/IGanjoorService.cs @@ -840,6 +840,13 @@ namespace RMuseum.Services /// Task> RejectPoetSuggestedSpecLinesAsync(int id, Guid deleteUserId, string rejectionCause); + /// + /// delete a category + /// + /// + /// + Task> DeleteCategoryAsync(int id); + /// /// set category poems language tag /// diff --git a/RMuseum/Services/Implementation/GanjoorService.cs b/RMuseum/Services/Implementation/GanjoorService.cs index e480f2cb..95f7134f 100644 --- a/RMuseum/Services/Implementation/GanjoorService.cs +++ b/RMuseum/Services/Implementation/GanjoorService.cs @@ -2889,6 +2889,36 @@ namespace RMuseum.Services.Implementation } } + /// + /// delete a category + /// + /// + /// + public async Task> DeleteCategoryAsync(int id) + { + try + { + if(true == await _context.GanjoorPoems.Where(p => p.CatId == id).AnyAsync()) + { + return new RServiceResult(false, "cat has poems!"); + } + + var page = await _context.GanjoorPages.Where(p => p.GanjoorPageType == GanjoorPageType.CatPage && p.CatId == id).SingleAsync(); + _context.Remove(page); + await _context.SaveChangesAsync(); + + var cat = await _context.GanjoorCategories.Where(c => c.Id == id).SingleAsync(); + _context.Remove(cat); + await _context.SaveChangesAsync(); + + return new RServiceResult(true); + } + catch (Exception exp) + { + return new RServiceResult(false, exp.ToString()); + } + } + /// /// chaneg poet image ///