From 8d1d0b40d56f90248f948e474330258bf57cf0b6 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 17 Jan 2021 14:45:48 +0200 Subject: Fixed role implementation by bringing back and improving all role models --- src/DevHive.Web/Controllers/RoleController.cs | 28 +++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/DevHive.Web/Controllers') diff --git a/src/DevHive.Web/Controllers/RoleController.cs b/src/DevHive.Web/Controllers/RoleController.cs index 8ea2711..5b3dca5 100644 --- a/src/DevHive.Web/Controllers/RoleController.cs +++ b/src/DevHive.Web/Controllers/RoleController.cs @@ -3,12 +3,12 @@ using Microsoft.AspNetCore.Mvc; using DevHive.Web.Models.Identity.Role; using AutoMapper; using System; -using DevHive.Common.Models.Identity; using DevHive.Services.Interfaces; +using DevHive.Services.Models.Identity.Role; namespace DevHive.Web.Controllers { - [ApiController] + [ApiController] [Route("/api/[controller]")] //[Authorize(Roles = "Admin")] public class RoleController @@ -23,33 +23,33 @@ namespace DevHive.Web.Controllers } [HttpPost] - public async Task Create([FromBody] CreateRoleModel createRoleModel) + public async Task Create([FromBody] CreateRoleWebModel createRoleWebModel) { - RoleModel roleServiceModel = - this._roleMapper.Map(createRoleModel); + RoleServiceModel roleServiceModel = + this._roleMapper.Map(createRoleWebModel); - bool result = await this._roleService.CreateRole(roleServiceModel); + Guid id = await this._roleService.CreateRole(roleServiceModel); - if (!result) - return new BadRequestObjectResult("Could not create role!"); + return id == Guid.Empty ? + new BadRequestObjectResult($"Could not create role {createRoleWebModel.Name}") : + new OkObjectResult(new { Id = id }); - return new OkResult(); } [HttpGet] public async Task GetById(Guid id) { - RoleModel roleServiceModel = await this._roleService.GetRoleById(id); - RoleModel roleWebModel = this._roleMapper.Map(roleServiceModel); + RoleServiceModel roleServiceModel = await this._roleService.GetRoleById(id); + RoleWebModel roleWebModel = this._roleMapper.Map(roleServiceModel); return new OkObjectResult(roleWebModel); } [HttpPut] - public async Task Update(Guid id, [FromBody] UpdateRoleModel updateRoleModel) + public async Task Update(Guid id, [FromBody] UpdateRoleWebModel updateRoleWebModel) { - RoleModel roleServiceModel = - this._roleMapper.Map(updateRoleModel); + RoleServiceModel roleServiceModel = + this._roleMapper.Map(updateRoleWebModel); roleServiceModel.Id = id; bool result = await this._roleService.UpdateRole(roleServiceModel); -- cgit v1.2.3