-
-
Notifications
You must be signed in to change notification settings - Fork 752
Expand file tree
/
Copy pathRoleController.cs
More file actions
85 lines (78 loc) · 2.74 KB
/
RoleController.cs
File metadata and controls
85 lines (78 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System.Threading.Tasks;
using BlazorHero.CleanArchitecture.Application.Interfaces.Services.Identity;
using BlazorHero.CleanArchitecture.Application.Requests.Identity;
using BlazorHero.CleanArchitecture.Shared.Constants.Permission;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace BlazorHero.CleanArchitecture.Server.Controllers.Identity
{
[Route("api/identity/role")]
[ApiController]
public class RoleController : ControllerBase
{
private readonly IRoleService _roleService;
public RoleController(IRoleService roleService)
{
_roleService = roleService;
}
/// <summary>
/// Get All Roles (basic, admin etc.)
/// </summary>
/// <returns>Status 200 OK</returns>
[Authorize(Policy = Permissions.Roles.View)]
[HttpGet]
public async Task<IActionResult> GetAll()
{
var roles = await _roleService.GetAllAsync();
return Ok(roles);
}
/// <summary>
/// Add a Role
/// </summary>
/// <param name="request"></param>
/// <returns>Status 200 OK</returns>
[Authorize(Policy = Permissions.Roles.Create)]
[HttpPost]
public async Task<IActionResult> Post(RoleRequest request)
{
var response = await _roleService.SaveAsync(request);
return Ok(response);
}
/// <summary>
/// Delete a Role
/// </summary>
/// <param name="id"></param>
/// <returns>Status 200 OK</returns>
[Authorize(Policy = Permissions.Roles.Delete)]
[HttpDelete("{id}")]
public async Task<IActionResult> Delete(string id)
{
var response = await _roleService.DeleteAsync(id);
return Ok(response);
}
/// <summary>
/// Get Permissions By Role Id
/// </summary>
/// <param name="roleId"></param>
/// <returns>Status 200 Ok</returns>
[Authorize(Policy = Permissions.RoleClaims.View)]
[HttpGet("permissions/{roleId}")]
public async Task<IActionResult> GetPermissionsByRoleId([FromRoute] string roleId)
{
var response = await _roleService.GetAllPermissionsAsync(roleId);
return Ok(response);
}
/// <summary>
/// Edit a Role Claim
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
[Authorize(Policy = Permissions.RoleClaims.Edit)]
[HttpPut("permissions/update")]
public async Task<IActionResult> Update(PermissionRequest model)
{
var response = await _roleService.UpdatePermissionsAsync(model);
return Ok(response);
}
}
}