aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Services
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.Services
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.Services')
-rw-r--r--src/DevHive.Services/Configurations/Mapping/RoleMapings.cs1
-rw-r--r--src/DevHive.Services/Services/RoleService.cs39
2 files changed, 16 insertions, 24 deletions
diff --git a/src/DevHive.Services/Configurations/Mapping/RoleMapings.cs b/src/DevHive.Services/Configurations/Mapping/RoleMapings.cs
index 0e06523..25b314a 100644
--- a/src/DevHive.Services/Configurations/Mapping/RoleMapings.cs
+++ b/src/DevHive.Services/Configurations/Mapping/RoleMapings.cs
@@ -9,6 +9,7 @@ namespace DevHive.Services.Configurations.Mapping
public RoleMappings()
{
CreateMap<RoleServiceModel, Role>();
+ CreateMap<Role, RoleServiceModel>();
}
}
}
diff --git a/src/DevHive.Services/Services/RoleService.cs b/src/DevHive.Services/Services/RoleService.cs
index c04bf31..d5c1848 100644
--- a/src/DevHive.Services/Services/RoleService.cs
+++ b/src/DevHive.Services/Services/RoleService.cs
@@ -4,7 +4,6 @@ using AutoMapper;
using DevHive.Data.Models;
using DevHive.Data.Repositories;
using DevHive.Services.Models.Identity.Role;
-using Microsoft.AspNetCore.Mvc;
namespace DevHive.Services.Services
{
@@ -19,51 +18,43 @@ namespace DevHive.Services.Services
this._roleMapper = mapper;
}
- public async Task<IActionResult> CreateRole(RoleServiceModel roleServiceModel)
+ public async Task<bool> CreateRole(RoleServiceModel roleServiceModel)
{
if (await this._roleRepository.DoesNameExist(roleServiceModel.Name))
- return new BadRequestObjectResult("Role already exists!");
+ throw new ArgumentException("Role already exists!");
Role role = this._roleMapper.Map<Role>(roleServiceModel);
- await this._roleRepository.AddAsync(role);
-
- return new CreatedResult("CreateRole", role);
+ return await this._roleRepository.AddAsync(role);
}
- public async Task<IActionResult> GetRoleById(Guid id)
+ public async Task<RoleServiceModel> GetRoleById(Guid id)
{
- Role role = await this._roleRepository.GetByIdAsync(id);
-
- if (role == null)
- return new NotFoundObjectResult("Role does not exist!");
+ Role role = await this._roleRepository.GetByIdAsync(id)
+ ?? throw new ArgumentException("Role does not exist!");
- return new ObjectResult(role);
+ return this._roleMapper.Map<RoleServiceModel>(role);
}
- public async Task<IActionResult> UpdateRole(RoleServiceModel roleServiceModel)
+ public async Task<bool> UpdateRole(RoleServiceModel roleServiceModel)
{
if (!await this._roleRepository.DoesRoleExist(roleServiceModel.Id))
- return new NotFoundObjectResult("Role does not exist!");
+ throw new ArgumentException("Role does not exist!");
- if (!await this._roleRepository.DoesNameExist(roleServiceModel.Name))
- return new BadRequestObjectResult("Role name already exists!");
+ if (await this._roleRepository.DoesNameExist(roleServiceModel.Name))
+ throw new ArgumentException("Role name already exists!");
Role role = this._roleMapper.Map<Role>(roleServiceModel);
- await this._roleRepository.EditAsync(role);
-
- return new AcceptedResult("UpdateRole", role);
+ return await this._roleRepository.EditAsync(role);
}
- public async Task<IActionResult> DeleteRole(Guid id)
+ public async Task<bool> DeleteRole(Guid id)
{
if (!await this._roleRepository.DoesRoleExist(id))
- return new NotFoundObjectResult("Role does not exist!");
+ throw new ArgumentException("Role does not exist!");
Role role = await this._roleRepository.GetByIdAsync(id);
- await this._roleRepository.DeleteAsync(role);
-
- return new OkResult();
+ return await this._roleRepository.DeleteAsync(role);
}
}
}