aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/DevHive.Services/Models/Identity/Role/RoleServiceModel.cs10
-rw-r--r--src/DevHive.Services/Services/RoleService.cs20
-rw-r--r--src/DevHive.Web/Configurations/Mapping/RoleMappings.cs15
-rw-r--r--src/DevHive.Web/Controllers/RoleController.cs34
-rw-r--r--src/DevHive.Web/Models/Identity/Role/UpdateRoleWebModel.cs4
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; }
}
}