From 5fd10b2bb157ff9308cb1d7c89701a932c49dcef Mon Sep 17 00:00:00 2001 From: jvyden Date: Fri, 29 Oct 2021 19:13:22 -0400 Subject: [PATCH] Add ability to remove comments. Closes #24. --- .../Controllers/CommentController.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/ProjectLighthouse/Controllers/CommentController.cs b/ProjectLighthouse/Controllers/CommentController.cs index 5881cc79..524e601b 100644 --- a/ProjectLighthouse/Controllers/CommentController.cs +++ b/ProjectLighthouse/Controllers/CommentController.cs @@ -58,5 +58,22 @@ namespace LBPUnion.ProjectLighthouse.Controllers { await this.database.SaveChangesAsync(); return this.Ok(); } + + [HttpPost("deleteUserComment/{username}")] + public async Task DeleteComment([FromQuery] int commentId, string username) { + User user = await this.database.UserFromRequest(this.Request); + if(user == null) return this.StatusCode(403, ""); + + Comment comment = await this.database.Comments + .FirstOrDefaultAsync(c => c.CommentId == commentId); + + if(comment.TargetUserId != user.UserId && comment.PosterUserId != user.UserId) + return this.StatusCode(403, ""); + + this.database.Comments.Remove(comment); + await this.database.SaveChangesAsync(); + + return this.Ok(); + } } } \ No newline at end of file