aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Web/Controllers/RoleController.cs
diff options
context:
space:
mode:
authorSyndamia <kamen.d.mladenov@protonmail.com>2020-12-17 11:59:52 +0200
committerSyndamia <kamen.d.mladenov@protonmail.com>2020-12-17 11:59:52 +0200
commitfadb0fd1b7a13d1c6210e11f2db2add7c8fd45a9 (patch)
tree58ac9249044012c5754cc5bfbb7ee0c51740ccc6 /src/DevHive.Web/Controllers/RoleController.cs
parent9346dc469481c7ec07a36700180c7008a2d9cb45 (diff)
downloadDevHive-fadb0fd1b7a13d1c6210e11f2db2add7c8fd45a9.tar
DevHive-fadb0fd1b7a13d1c6210e11f2db2add7c8fd45a9.tar.gz
DevHive-fadb0fd1b7a13d1c6210e11f2db2add7c8fd45a9.zip
Reworked RoleController and RoleService to be consistent with the app structure
Diffstat (limited to 'src/DevHive.Web/Controllers/RoleController.cs')
-rw-r--r--src/DevHive.Web/Controllers/RoleController.cs35
1 files changed, 27 insertions, 8 deletions
diff --git a/src/DevHive.Web/Controllers/RoleController.cs b/src/DevHive.Web/Controllers/RoleController.cs
index 610d370..1664f4f 100644
--- a/src/DevHive.Web/Controllers/RoleController.cs
+++ b/src/DevHive.Web/Controllers/RoleController.cs
@@ -25,33 +25,52 @@ namespace DevHive.Web.Controllers
}
[HttpPost]
- public Task<IActionResult> Create(CreateRoleWebModel createRoleWebModel)
+ public async Task<IActionResult> Create([FromBody] CreateRoleWebModel createRoleWebModel)
{
RoleServiceModel roleServiceModel =
this._roleMapper.Map<RoleServiceModel>(createRoleWebModel);
- return this._roleService.CreateRole(roleServiceModel);
+ bool result = await this._roleService.CreateRole(roleServiceModel);
+
+ if (!result)
+ return new BadRequestObjectResult("Could not create role!");
+
+ return new OkResult();
}
[HttpGet]
- public Task<IActionResult> GetById(Guid id)
+ public async Task<IActionResult> GetById(Guid id)
{
- return this._roleService.GetRoleById(id);
+ RoleServiceModel roleServiceModel = await this._roleService.GetRoleById(id);
+ RoleWebModel roleWebModel = this._roleMapper.Map<RoleWebModel>(roleServiceModel);
+
+ return new OkObjectResult(roleWebModel);
}
[HttpPut]
- public Task<IActionResult> Update(UpdateRoleWebModel updateRoleWebModel)
+ public async Task<IActionResult> Update(Guid id, [FromBody] UpdateRoleWebModel updateRoleWebModel)
{
RoleServiceModel roleServiceModel =
this._roleMapper.Map<RoleServiceModel>(updateRoleWebModel);
+ roleServiceModel.Id = id;
+
+ bool result = await this._roleService.UpdateRole(roleServiceModel);
- return this._roleService.UpdateRole(roleServiceModel);
+ if (!result)
+ return new BadRequestObjectResult("Could not update role!");
+
+ return new OkResult();
}
[HttpDelete]
- public Task<IActionResult> Delete(Guid id)
+ public async Task<IActionResult> Delete(Guid id)
{
- return this._roleService.DeleteRole(id);
+ bool result = await this._roleService.DeleteRole(id);
+
+ if (!result)
+ return new BadRequestObjectResult("Could nor delete role!");
+
+ return new OkResult();
}
}
}