diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-01-17 14:45:48 +0200 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-01-17 14:45:48 +0200 |
| commit | 8d1d0b40d56f90248f948e474330258bf57cf0b6 (patch) | |
| tree | ab4431208ea495c6b8c5de0b91cb85cdef66d20e /src/DevHive.Services | |
| parent | 83f63ad729d585d597bdcf0afc05b7d56344223e (diff) | |
| download | DevHive-8d1d0b40d56f90248f948e474330258bf57cf0b6.tar DevHive-8d1d0b40d56f90248f948e474330258bf57cf0b6.tar.gz DevHive-8d1d0b40d56f90248f948e474330258bf57cf0b6.zip | |
Fixed role implementation by bringing back and improving all role models
Diffstat (limited to 'src/DevHive.Services')
6 files changed, 46 insertions, 19 deletions
diff --git a/src/DevHive.Services/Configurations/Mapping/RoleMapings.cs b/src/DevHive.Services/Configurations/Mapping/RoleMapings.cs index 65b0b5a..4ddd253 100644 --- a/src/DevHive.Services/Configurations/Mapping/RoleMapings.cs +++ b/src/DevHive.Services/Configurations/Mapping/RoleMapings.cs @@ -1,15 +1,15 @@ using DevHive.Data.Models; using AutoMapper; -using DevHive.Common.Models.Identity; +using DevHive.Services.Models.Identity.Role; namespace DevHive.Services.Configurations.Mapping { - public class RoleMappings : Profile + public class RoleMappings : Profile { public RoleMappings() { - CreateMap<RoleModel, Role>(); - CreateMap<Role, RoleModel>(); + CreateMap<RoleServiceModel, Role>(); + CreateMap<Role, RoleServiceModel>(); } } } diff --git a/src/DevHive.Services/Interfaces/IRoleService.cs b/src/DevHive.Services/Interfaces/IRoleService.cs index 2c7195c..a7a0e47 100644 --- a/src/DevHive.Services/Interfaces/IRoleService.cs +++ b/src/DevHive.Services/Interfaces/IRoleService.cs @@ -1,16 +1,16 @@ using System; using System.Threading.Tasks; -using DevHive.Common.Models.Identity; +using DevHive.Services.Models.Identity.Role; namespace DevHive.Services.Interfaces { - public interface IRoleService + public interface IRoleService { - Task<bool> CreateRole(RoleModel roleServiceModel); + Task<Guid> CreateRole(RoleServiceModel roleServiceModel); - Task<RoleModel> GetRoleById(Guid id); + Task<RoleServiceModel> GetRoleById(Guid id); - Task<bool> UpdateRole(RoleModel roleServiceModel); + Task<bool> UpdateRole(RoleServiceModel roleServiceModel); Task<bool> DeleteRole(Guid id); } diff --git a/src/DevHive.Services/Models/Identity/Role/RoleServiceModel.cs b/src/DevHive.Services/Models/Identity/Role/RoleServiceModel.cs new file mode 100644 index 0000000..3f834ef --- /dev/null +++ b/src/DevHive.Services/Models/Identity/Role/RoleServiceModel.cs @@ -0,0 +1,10 @@ +using System; + +namespace DevHive.Services.Models.Identity.Role +{ + public class RoleServiceModel + { + public Guid Id { get; set; } + public string Name { get; set; } + } +} diff --git a/src/DevHive.Services/Models/Identity/Role/UpdateRoleServiceModel.cs b/src/DevHive.Services/Models/Identity/Role/UpdateRoleServiceModel.cs new file mode 100644 index 0000000..be71771 --- /dev/null +++ b/src/DevHive.Services/Models/Identity/Role/UpdateRoleServiceModel.cs @@ -0,0 +1,7 @@ +namespace DevHive.Services.Models.Identity.Role +{ + public class UpdateRoleServiceModel + { + public string Name { get; set; } + } +} diff --git a/src/DevHive.Services/Models/Identity/User/UserServiceModel.cs b/src/DevHive.Services/Models/Identity/User/UserServiceModel.cs index ecf8c42..aa77a0c 100644 --- a/src/DevHive.Services/Models/Identity/User/UserServiceModel.cs +++ b/src/DevHive.Services/Models/Identity/User/UserServiceModel.cs @@ -1,13 +1,13 @@ using System.Collections.Generic; -using DevHive.Common.Models.Identity; +using DevHive.Services.Models.Identity.Role; using DevHive.Services.Models.Language; using DevHive.Services.Models.Technology; namespace DevHive.Services.Models.Identity.User { - public class UserServiceModel : BaseUserServiceModel + public class UserServiceModel : BaseUserServiceModel { - public IList<RoleModel> Roles { get; set; } = new List<RoleModel>(); + public IList<RoleServiceModel> Roles { get; set; } = new List<RoleServiceModel>(); public IList<UserServiceModel> Friends { get; set; } = new List<UserServiceModel>(); diff --git a/src/DevHive.Services/Services/RoleService.cs b/src/DevHive.Services/Services/RoleService.cs index c38ac74..0945624 100644 --- a/src/DevHive.Services/Services/RoleService.cs +++ b/src/DevHive.Services/Services/RoleService.cs @@ -1,14 +1,15 @@ using System; using System.Threading.Tasks; using AutoMapper; -using DevHive.Common.Models.Identity; using DevHive.Data.Interfaces.Repositories; using DevHive.Data.Models; using DevHive.Services.Interfaces; +using DevHive.Services.Models.Identity.Role; +using DevHive.Services.Models.Language; namespace DevHive.Services.Services { - public class RoleService : IRoleService + public class RoleService : IRoleService { private readonly IRoleRepository _roleRepository; private readonly IMapper _roleMapper; @@ -19,25 +20,34 @@ namespace DevHive.Services.Services this._roleMapper = mapper; } - public async Task<bool> CreateRole(RoleModel roleServiceModel) + public async Task<Guid> CreateRole(RoleServiceModel roleServiceModel) { if (await this._roleRepository.DoesNameExist(roleServiceModel.Name)) throw new ArgumentException("Role already exists!"); + Role role = this._roleMapper.Map<Role>(roleServiceModel); + bool success = await this._roleRepository.AddAsync(role); + + if(success) + { + Role newRole = await this._roleRepository.GetByNameAsync(roleServiceModel.Name); + return newRole.Id; + } + else + return Guid.Empty; - return await this._roleRepository.AddAsync(role); } - public async Task<RoleModel> GetRoleById(Guid id) + public async Task<RoleServiceModel> GetRoleById(Guid id) { Role role = await this._roleRepository.GetByIdAsync(id) ?? throw new ArgumentException("Role does not exist!"); - return this._roleMapper.Map<RoleModel>(role); + return this._roleMapper.Map<RoleServiceModel>(role); } - public async Task<bool> UpdateRole(RoleModel roleServiceModel) + public async Task<bool> UpdateRole(RoleServiceModel roleServiceModel) { if (!await this._roleRepository.DoesRoleExist(roleServiceModel.Id)) throw new ArgumentException("Role does not exist!"); |
