diff options
Diffstat (limited to 'src/DevHive.Web')
| -rw-r--r-- | src/DevHive.Web/Configurations/Mapping/RoleMappings.cs | 15 | ||||
| -rw-r--r-- | src/DevHive.Web/Controllers/RoleController.cs | 34 | ||||
| -rw-r--r-- | src/DevHive.Web/Models/Identity/Role/UpdateRoleWebModel.cs | 4 |
3 files changed, 43 insertions, 10 deletions
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; } } } |
