aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Web/Controllers/RoleController.cs
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2021-02-13 16:20:18 +0200
committertranstrike <transtrike@gmail.com>2021-02-13 16:20:18 +0200
commit98e17766b203734a1817eed94338e2d25f4395f7 (patch)
tree1266385a56cba56fd55c7faf661dd844bbdf5705 /src/DevHive.Web/Controllers/RoleController.cs
parent1ab34accfda22ee3ce5c7700e3b97ff3e932d649 (diff)
downloadDevHive-98e17766b203734a1817eed94338e2d25f4395f7.tar
DevHive-98e17766b203734a1817eed94338e2d25f4395f7.tar.gz
DevHive-98e17766b203734a1817eed94338e2d25f4395f7.zip
Project Restructure P.1
Diffstat (limited to 'src/DevHive.Web/Controllers/RoleController.cs')
-rw-r--r--src/DevHive.Web/Controllers/RoleController.cs77
1 files changed, 0 insertions, 77 deletions
diff --git a/src/DevHive.Web/Controllers/RoleController.cs b/src/DevHive.Web/Controllers/RoleController.cs
deleted file mode 100644
index 0d2a2eb..0000000
--- a/src/DevHive.Web/Controllers/RoleController.cs
+++ /dev/null
@@ -1,77 +0,0 @@
-using System.Threading.Tasks;
-using Microsoft.AspNetCore.Mvc;
-using DevHive.Web.Models.Identity.Role;
-using AutoMapper;
-using System;
-using DevHive.Services.Interfaces;
-using DevHive.Services.Models.Identity.Role;
-using Microsoft.AspNetCore.Authorization;
-
-namespace DevHive.Web.Controllers
-{
- [ApiController]
- [Route("/api/[controller]")]
- public class RoleController
- {
- private readonly IRoleService _roleService;
- private readonly IMapper _roleMapper;
-
- public RoleController(IRoleService roleService, IMapper mapper)
- {
- this._roleService = roleService;
- this._roleMapper = mapper;
- }
-
- [HttpPost]
- [Authorize(Roles = "Admin")]
- public async Task<IActionResult> Create([FromBody] CreateRoleWebModel createRoleWebModel)
- {
- CreateRoleServiceModel roleServiceModel =
- this._roleMapper.Map<CreateRoleServiceModel>(createRoleWebModel);
-
- Guid id = await this._roleService.CreateRole(roleServiceModel);
-
- return id == Guid.Empty ?
- new BadRequestObjectResult($"Could not create role {createRoleWebModel.Name}") :
- new OkObjectResult(new { Id = id });
- }
-
- [HttpGet]
- [Authorize(Roles = "User,Admin")]
- public async Task<IActionResult> GetById(Guid id)
- {
- RoleServiceModel roleServiceModel = await this._roleService.GetRoleById(id);
- RoleWebModel roleWebModel = this._roleMapper.Map<RoleWebModel>(roleServiceModel);
-
- return new OkObjectResult(roleWebModel);
- }
-
- [HttpPut]
- [Authorize(Roles = "Admin")]
- public async Task<IActionResult> Update(Guid id, [FromBody] UpdateRoleWebModel updateRoleWebModel)
- {
- UpdateRoleServiceModel updateRoleServiceModel =
- this._roleMapper.Map<UpdateRoleServiceModel>(updateRoleWebModel);
- updateRoleServiceModel.Id = id;
-
- bool result = await this._roleService.UpdateRole(updateRoleServiceModel);
-
- if (!result)
- return new BadRequestObjectResult("Could not update role!");
-
- return new OkResult();
- }
-
- [HttpDelete]
- [Authorize(Roles = "Admin")]
- public async Task<IActionResult> Delete(Guid id)
- {
- bool result = await this._roleService.DeleteRole(id);
-
- if (!result)
- return new BadRequestObjectResult("Could not delete role!");
-
- return new OkResult();
- }
- }
-}