diff --git a/RMuseum/Controllers/GanjoorController.cs b/RMuseum/Controllers/GanjoorController.cs index 335dfb54..7760834d 100644 --- a/RMuseum/Controllers/GanjoorController.cs +++ b/RMuseum/Controllers/GanjoorController.cs @@ -498,6 +498,40 @@ namespace RMuseum.Controllers return Ok(res.Result); } + /// + /// edit user's own comment + /// + /// + /// + /// + [HttpPut] + [Route("comment/{id}")] + [Authorize] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + [ProducesResponseType((int)HttpStatusCode.NotFound)] + [ProducesResponseType((int)HttpStatusCode.Forbidden)] + public async Task EditMyComment(int id, [FromBody]string comment) + { + + Guid userId = + new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value); + Guid sessionId = + new Guid(User.Claims.FirstOrDefault(c => c.Type == "SessionId").Value); + RServiceResult sessionCheckResult = await _appUserService.SessionExists(userId, sessionId); + if (!string.IsNullOrEmpty(sessionCheckResult.ExceptionString)) + { + return StatusCode((int)HttpStatusCode.Forbidden); + } + + var res = + await _ganjoorService.EditMyComment(userId, id, comment); + if (!string.IsNullOrEmpty(res.ExceptionString)) + return BadRequest(res.ExceptionString); + if (!res.Result) + return NotFound(); + return Ok(); + } + /// /// delete user's own comment /// diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index 5daf1089..47dc125e 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -772,6 +772,14 @@ + + + edit user's own comment + + + + + delete user's own comment @@ -6062,6 +6070,15 @@ + + + update user's own comment + + + + + + delete user own comment @@ -6892,6 +6909,15 @@ + + + update user's own comment + + + + + + delete user own comment diff --git a/RMuseum/Services/IGanjoorService.cs b/RMuseum/Services/IGanjoorService.cs index db6b47c3..bf20264c 100644 --- a/RMuseum/Services/IGanjoorService.cs +++ b/RMuseum/Services/IGanjoorService.cs @@ -170,6 +170,15 @@ namespace RMuseum.Services /// Task> NewComment(Guid userId, string ip, int poemId, string content, int? inReplyTo); + /// + /// update user's own comment + /// + /// + /// + /// + /// + Task> EditMyComment(Guid userId, int commentId, string htmlComment); + /// /// delete user own comment /// diff --git a/RMuseum/Services/Implementation/GanjoorService.cs b/RMuseum/Services/Implementation/GanjoorService.cs index b15d5937..735d873f 100644 --- a/RMuseum/Services/Implementation/GanjoorService.cs +++ b/RMuseum/Services/Implementation/GanjoorService.cs @@ -581,6 +581,36 @@ namespace RMuseum.Services.Implementation } } + /// + /// update user's own comment + /// + /// + /// + /// + /// + public async Task> EditMyComment(Guid userId, int commentId, string htmlComment) + { + try + { + GanjoorComment comment = await _context.GanjoorComments.Where(c => c.Id == commentId && c.UserId == userId).SingleOrDefaultAsync();//userId is not part of key but it helps making call secure + if (comment == null) + { + return new RServiceResult(false); //not found + } + + comment.HtmlComment = htmlComment; + + _context.GanjoorComments.Update(comment); + await _context.SaveChangesAsync(); + + return new RServiceResult(true); + } + catch (Exception exp) + { + return new RServiceResult(false, exp.ToString()); + } + } + /// /// delete user own comment ///