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/DevHive.Web/Controllers | |
| 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/DevHive.Web/Controllers')
| -rw-r--r-- | src/DevHive.Web/Controllers/RoleController.cs | 34 |
1 files changed, 25 insertions, 9 deletions
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); } } } |
