diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2020-12-15 11:02:54 +0200 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2020-12-15 11:02:54 +0200 |
| commit | 1f84b7d7da1464fab8178188f97164e4718527ed (patch) | |
| tree | b99b06f8b1e86e6087dd548be62ae62d7674aa01 /src | |
| parent | 6bfc34a142279743df82bdb2d3913cafa3051651 (diff) | |
| download | DevHive-1f84b7d7da1464fab8178188f97164e4718527ed.tar DevHive-1f84b7d7da1464fab8178188f97164e4718527ed.tar.gz DevHive-1f84b7d7da1464fab8178188f97164e4718527ed.zip | |
Updated role controller and role service to use custom models and implemented role mapping
Diffstat (limited to 'src')
5 files changed, 69 insertions, 14 deletions
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/Services/RoleService.cs b/src/DevHive.Services/Services/RoleService.cs index 202c611..9077a47 100644 --- a/src/DevHive.Services/Services/RoleService.cs +++ b/src/DevHive.Services/Services/RoleService.cs @@ -1,26 +1,38 @@ using System; using System.Threading.Tasks; using DevHive.Data.Repositories; +using DevHive.Services.Models.Identity.Role; +using Microsoft.AspNetCore.Mvc; namespace DevHive.Services.Services { public class RoleService { - /* private readonly DevHiveContext _context; + private readonly DevHiveContext _context; public RoleService(DevHiveContext context) { this._context = context; } - public Task<IActionResult> CreatePost(string name) + public Task<IActionResult> CreateRole(RoleServiceModel roleServiceModel) { throw new NotImplementedException(); } - public Task<IActionResult> GetPostById(uint postId) + public Task<IActionResult> GetRoleById(Guid id) { throw new NotImplementedException(); - }*/ + } + + public Task<IActionResult> UpdateRole(RoleServiceModel roleServiceModel) + { + throw new NotImplementedException(); + } + + public Task<IActionResult> DeleteRole(Guid id) + { + throw new NotImplementedException(); + } } } diff --git a/src/DevHive.Web/Configurations/Mapping/RoleMappings.cs b/src/DevHive.Web/Configurations/Mapping/RoleMappings.cs new file mode 100644 index 0000000..9ccb7d7 --- /dev/null +++ b/src/DevHive.Web/Configurations/Mapping/RoleMappings.cs @@ -0,0 +1,15 @@ +using AutoMapper; +using DevHive.Web.Models.Identity.Role; +using DevHive.Services.Models.Identity.Role; + +namespace DevHive.Web.Configurations.Mapping +{ + public class RoleMappings : Profile + { + public RoleMappings() + { + CreateMap<CreateRoleWebModel, RoleServiceModel>(); + CreateMap<UpdateRoleWebModel, RoleServiceModel>(); + } + } +} diff --git a/src/DevHive.Web/Controllers/RoleController.cs b/src/DevHive.Web/Controllers/RoleController.cs index fda8bb2..e39d858 100644 --- a/src/DevHive.Web/Controllers/RoleController.cs +++ b/src/DevHive.Web/Controllers/RoleController.cs @@ -1,34 +1,50 @@ -using System; using System.Threading.Tasks; using DevHive.Data.Repositories; using DevHive.Services.Services; using Microsoft.AspNetCore.Mvc; +using DevHive.Web.Models.Identity.Role; +using AutoMapper; +using DevHive.Services.Models.Identity.Role; +using System; namespace DevHive.Web.Controllers { - [ApiController] + [ApiController] [Route("/api/[controller]")] public class RoleController { private readonly RoleService _service; + private readonly IMapper _roleMapper; public RoleController(DevHiveContext context) { - //this._service = new RoleService(context); + this._service = new RoleService(context); } [HttpPost] - public Task<IActionResult> Create(string name) + public Task<IActionResult> Create(CreateRoleWebModel createRoleWebModel) { - //return this._service.CreatePost(name); - throw new NotImplementedException(); + RoleServiceModel roleServiceModel = this._roleMapper.Map<RoleServiceModel>(createRoleWebModel); + return this._service.CreateRole(roleServiceModel); } [HttpGet] - public Task<IActionResult> ShowPost(uint postId) + public Task<IActionResult> Get(Guid id) + { + return this._service.GetRoleById(id); + } + + [HttpPut] + public Task<IActionResult> Update(UpdateRoleWebModel updateRoleWebModel) + { + RoleServiceModel roleServiceModel = this._roleMapper.Map<RoleServiceModel>(updateRoleWebModel); + return this._service.UpdateRole(roleServiceModel); + } + + [HttpDelete] + public Task<IActionResult> Delete(Guid id) { - //return this._service.GetPostById(postId); - throw new NotImplementedException(); + return this._service.DeleteRole(id); } } } diff --git a/src/DevHive.Web/Models/Identity/Role/UpdateRoleWebModel.cs b/src/DevHive.Web/Models/Identity/Role/UpdateRoleWebModel.cs index 58eef1f..b970dd5 100644 --- a/src/DevHive.Web/Models/Identity/Role/UpdateRoleWebModel.cs +++ b/src/DevHive.Web/Models/Identity/Role/UpdateRoleWebModel.cs @@ -1,8 +1,10 @@ +using System; + namespace DevHive.Web.Models.Identity.Role { public class UpdateRoleWebModel { - public string OldName { get; set; } + public Guid Id { get; set; } public string NewName { get; set; } } } |
