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