aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Web/Controllers/CommentController.cs
diff options
context:
space:
mode:
authorKamen Mladenov <kamen.d.mladenov@protonmail.com>2021-04-09 19:51:35 +0300
committerGitHub <noreply@github.com>2021-04-09 19:51:35 +0300
commit233f38915ba0079079233eff55434ef349c05c45 (patch)
tree6c5f69017865bcab87355e910c87339453da1406 /src/DevHive.Web/Controllers/CommentController.cs
parentf4a70c6430db923af9fa9958a11c2d6612cb52cc (diff)
parenta992357efcf1bc1ece81b95ecee5e05a0b73bfdc (diff)
downloadDevHive-heroku/main.tar
DevHive-heroku/main.tar.gz
DevHive-heroku/main.zip
Merge pull request #28 from Team-Kaleidoscope/devHEADv0.2mainheroku/main
Second stage: Complete
Diffstat (limited to 'src/DevHive.Web/Controllers/CommentController.cs')
-rw-r--r--src/DevHive.Web/Controllers/CommentController.cs83
1 files changed, 0 insertions, 83 deletions
diff --git a/src/DevHive.Web/Controllers/CommentController.cs b/src/DevHive.Web/Controllers/CommentController.cs
deleted file mode 100644
index c38e300..0000000
--- a/src/DevHive.Web/Controllers/CommentController.cs
+++ /dev/null
@@ -1,83 +0,0 @@
-using System.Threading.Tasks;
-using Microsoft.AspNetCore.Mvc;
-using AutoMapper;
-using System;
-using DevHive.Web.Models.Comment;
-using DevHive.Services.Models.Comment;
-using Microsoft.AspNetCore.Authorization;
-using DevHive.Services.Interfaces;
-
-namespace DevHive.Web.Controllers
-{
- [ApiController]
- [Route("/api/[controller]")]
- [Authorize(Roles = "User,Admin")]
- public class CommentController
- {
- private readonly ICommentService _commentService;
- private readonly IMapper _commentMapper;
-
- public CommentController(ICommentService commentService, IMapper commentMapper)
- {
- this._commentService = commentService;
- this._commentMapper = commentMapper;
- }
-
- [HttpPost]
- public async Task<IActionResult> AddComment(Guid userId, [FromBody] CreateCommentWebModel createCommentWebModel, [FromHeader] string authorization)
- {
- if (!await this._commentService.ValidateJwtForCreating(userId, authorization))
- return new UnauthorizedResult();
-
- CreateCommentServiceModel createCommentServiceModel =
- this._commentMapper.Map<CreateCommentServiceModel>(createCommentWebModel);
- createCommentServiceModel.CreatorId = userId;
-
- Guid id = await this._commentService.AddComment(createCommentServiceModel);
-
- return id == Guid.Empty ?
- new BadRequestObjectResult("Could not create comment!") :
- new OkObjectResult(new { Id = id });
- }
-
- [HttpGet]
- [AllowAnonymous]
- public async Task<IActionResult> GetCommentById(Guid id)
- {
- ReadCommentServiceModel readCommentServiceModel = await this._commentService.GetCommentById(id);
- ReadCommentWebModel readCommentWebModel = this._commentMapper.Map<ReadCommentWebModel>(readCommentServiceModel);
-
- return new OkObjectResult(readCommentWebModel);
- }
-
- [HttpPut]
- public async Task<IActionResult> UpdateComment(Guid userId, [FromBody] UpdateCommentWebModel updateCommentWebModel, [FromHeader] string authorization)
- {
- if (!await this._commentService.ValidateJwtForComment(updateCommentWebModel.CommentId, authorization))
- return new UnauthorizedResult();
-
- UpdateCommentServiceModel updateCommentServiceModel =
- this._commentMapper.Map<UpdateCommentServiceModel>(updateCommentWebModel);
- updateCommentServiceModel.CreatorId = userId;
-
- Guid id = await this._commentService.UpdateComment(updateCommentServiceModel);
-
- return id == Guid.Empty ?
- new BadRequestObjectResult("Unable to update comment!") :
- new OkObjectResult(new { Id = id });
- }
-
- [HttpDelete]
- public async Task<IActionResult> DeleteComment(Guid id, [FromHeader] string authorization)
- {
- if (!await this._commentService.ValidateJwtForComment(id, authorization))
- return new UnauthorizedResult();
-
- return await this._commentService.DeleteComment(id) ?
- new OkResult() :
- new BadRequestObjectResult("Could not delete Comment");
- }
-
- }
-}
-