aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Web/Controllers/PostController.cs
diff options
context:
space:
mode:
authorSyndamia <kamen.d.mladenov@protonmail.com>2021-01-30 11:31:21 +0200
committerSyndamia <kamen.d.mladenov@protonmail.com>2021-01-30 11:31:21 +0200
commitff91162eb83dcf19402240ae8fa06f70cbf2b9e0 (patch)
tree2948559f7326c8221f799d4aaf794c5e00c06bd9 /src/DevHive.Web/Controllers/PostController.cs
parentdde27f48caf455f9b342d68b0a4a5c95f302b9f7 (diff)
downloadDevHive-ff91162eb83dcf19402240ae8fa06f70cbf2b9e0.tar
DevHive-ff91162eb83dcf19402240ae8fa06f70cbf2b9e0.tar.gz
DevHive-ff91162eb83dcf19402240ae8fa06f70cbf2b9e0.zip
Separated comment models, controler and service from post's
Diffstat (limited to 'src/DevHive.Web/Controllers/PostController.cs')
-rw-r--r--src/DevHive.Web/Controllers/PostController.cs67
1 files changed, 3 insertions, 64 deletions
diff --git a/src/DevHive.Web/Controllers/PostController.cs b/src/DevHive.Web/Controllers/PostController.cs
index fe71519..53adfce 100644
--- a/src/DevHive.Web/Controllers/PostController.cs
+++ b/src/DevHive.Web/Controllers/PostController.cs
@@ -2,16 +2,14 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using AutoMapper;
using System;
-using DevHive.Web.Models.Post.Post;
-using DevHive.Services.Models.Post.Post;
-using DevHive.Web.Models.Post.Comment;
-using DevHive.Services.Models.Post.Comment;
+using DevHive.Web.Models.Post;
+using DevHive.Services.Models.Post;
using Microsoft.AspNetCore.Authorization;
using DevHive.Services.Interfaces;
namespace DevHive.Web.Controllers
{
- [ApiController]
+ [ApiController]
[Route("/api/[controller]")]
[Authorize(Roles = "User,Admin")]
public class PostController
@@ -42,24 +40,6 @@ namespace DevHive.Web.Controllers
new BadRequestObjectResult("Could not create post!") :
new OkObjectResult(new { Id = id });
}
-
- [HttpPost]
- [Route("Comment")]
- public async Task<IActionResult> AddComment(Guid userId, [FromBody] CreateCommentWebModel createCommentWebModel, [FromHeader] string authorization)
- {
- if (!await this._postService.ValidateJwtForCreating(userId, authorization))
- return new UnauthorizedResult();
-
- CreateCommentServiceModel createCommentServiceModel =
- this._postMapper.Map<CreateCommentServiceModel>(createCommentWebModel);
- createCommentServiceModel.CreatorId = userId;
-
- Guid id = await this._postService.AddComment(createCommentServiceModel);
-
- return id == Guid.Empty ?
- new BadRequestObjectResult("Could not create comment!") :
- new OkObjectResult(new { Id = id });
- }
#endregion
#region Read
@@ -72,17 +52,6 @@ namespace DevHive.Web.Controllers
return new OkObjectResult(postWebModel);
}
-
- [HttpGet]
- [Route("Comment")]
- [AllowAnonymous]
- public async Task<IActionResult> GetCommentById(Guid id)
- {
- ReadCommentServiceModel readCommentServiceModel = await this._postService.GetCommentById(id);
- ReadCommentWebModel readCommentWebModel = this._postMapper.Map<ReadCommentWebModel>(readCommentServiceModel);
-
- return new OkObjectResult(readCommentWebModel);
- }
#endregion
#region Update
@@ -102,24 +71,6 @@ namespace DevHive.Web.Controllers
new BadRequestObjectResult("Unable to update post!") :
new OkObjectResult(new { Id = id });
}
-
- [HttpPut]
- [Route("Comment")]
- public async Task<IActionResult> UpdateComment(Guid userId, [FromBody] UpdateCommentWebModel updateCommentWebModel, [FromHeader] string authorization)
- {
- if (!await this._postService.ValidateJwtForComment(updateCommentWebModel.CommentId, authorization))
- return new UnauthorizedResult();
-
- UpdateCommentServiceModel updateCommentServiceModel =
- this._postMapper.Map<UpdateCommentServiceModel>(updateCommentWebModel);
- updateCommentServiceModel.CreatorId = userId;
-
- Guid id = await this._postService.UpdateComment(updateCommentServiceModel);
-
- return id == Guid.Empty ?
- new BadRequestObjectResult("Unable to update comment!") :
- new OkObjectResult(new { Id = id });
- }
#endregion
#region Delete
@@ -133,18 +84,6 @@ namespace DevHive.Web.Controllers
new OkResult() :
new BadRequestObjectResult("Could not delete Comment");
}
-
- [HttpDelete]
- [Route("Comment")]
- public async Task<IActionResult> DeleteComment(Guid id, [FromHeader] string authorization)
- {
- if (!await this._postService.ValidateJwtForComment(id, authorization))
- return new UnauthorizedResult();
-
- return await this._postService.DeleteComment(id) ?
- new OkResult() :
- new BadRequestObjectResult("Could not delete Comment");
- }
#endregion
}
}