|
1 | | -using Microsoft.AspNetCore.Http; |
2 | | -using Microsoft.AspNetCore.Mvc; |
3 | | -using System; |
4 | | -using TaleEngine.CQRS.Contracts; |
5 | | - |
6 | | -namespace TaleEngine.API.Controllers.V2 |
7 | | -{ |
8 | | - /// <summary> |
9 | | - /// Roles management |
10 | | - /// </summary> |
11 | | - [ApiController] |
12 | | - [ProducesResponseType(StatusCodes.Status400BadRequest)] |
13 | | - [ProducesResponseType(StatusCodes.Status401Unauthorized)] |
14 | | - [ProducesResponseType(StatusCodes.Status403Forbidden)] |
15 | | - [ProducesResponseType(StatusCodes.Status404NotFound)] |
16 | | - [ProducesResponseType(StatusCodes.Status500InternalServerError)] |
17 | | - [ControllerName("Management roles and permissions associated")] |
18 | | - [Route("api/v2/[controller]")] |
19 | | - public class RolesController : Controller |
20 | | - { |
21 | | - private IRoleQueries query; |
22 | | - |
23 | | - /// <summary> |
24 | | - /// Constructor for roles controller |
25 | | - /// </summary> |
26 | | - /// <param name="command">Role service</param> |
27 | | - public RolesController(IRoleQueries command) |
28 | | - { |
29 | | - query = command ?? throw new ArgumentNullException(nameof(command)); |
30 | | - } |
31 | | - |
32 | | - /// <summary> |
33 | | - /// Gets all the roles in the app |
34 | | - /// </summary> |
35 | | - /// <returns>All the roles</returns> |
36 | | - [HttpGet("[action]")] |
37 | | - [ProducesResponseType(StatusCodes.Status200OK)] |
38 | | - [ProducesResponseType(StatusCodes.Status204NoContent)] |
39 | | - public IActionResult GetAllRoles() |
40 | | - { |
41 | | - var result = query.AllRolesQuery(); |
42 | | - |
43 | | - if (result == null || result.Count == 0) |
44 | | - { |
45 | | - return NoContent(); |
46 | | - } |
47 | | - |
48 | | - return Ok(result); |
49 | | - } |
50 | | - |
51 | | - /// <summary> |
52 | | - /// Gets a single role with permissions |
53 | | - /// </summary> |
54 | | - /// <param name="roleId">Role identifier</param> |
55 | | - /// <returns>The selected role with permissions</returns> |
56 | | - [HttpGet("[action]/{roleId:int}")] |
57 | | - [ProducesResponseType(StatusCodes.Status200OK)] |
58 | | - [ProducesResponseType(StatusCodes.Status204NoContent)] |
59 | | - public IActionResult GetRole(int roleId) |
60 | | - { |
61 | | - var result = query.GetRoleQuery(roleId); |
62 | | - return Ok(result); |
63 | | - } |
64 | | - |
65 | | - } |
66 | | -} |
| 1 | +using Microsoft.AspNetCore.Http; |
| 2 | +using Microsoft.AspNetCore.Mvc; |
| 3 | +using System; |
| 4 | +using TaleEngine.CQRS.Contracts; |
| 5 | + |
| 6 | +namespace TaleEngine.API.Controllers.Backoffice |
| 7 | +{ |
| 8 | + /// <summary> |
| 9 | + /// Roles management |
| 10 | + /// </summary> |
| 11 | + [ApiController] |
| 12 | + [ProducesResponseType(StatusCodes.Status400BadRequest)] |
| 13 | + [ProducesResponseType(StatusCodes.Status401Unauthorized)] |
| 14 | + [ProducesResponseType(StatusCodes.Status403Forbidden)] |
| 15 | + [ProducesResponseType(StatusCodes.Status404NotFound)] |
| 16 | + [ProducesResponseType(StatusCodes.Status500InternalServerError)] |
| 17 | + [ControllerName("Management roles and permissions associated")] |
| 18 | + [Route("api/[controller]")] |
| 19 | + public class RolesController : Controller |
| 20 | + { |
| 21 | + private IRoleQueries query; |
| 22 | + |
| 23 | + /// <summary> |
| 24 | + /// Constructor for roles controller |
| 25 | + /// </summary> |
| 26 | + /// <param name="command">Role service</param> |
| 27 | + public RolesController(IRoleQueries command) |
| 28 | + { |
| 29 | + query = command ?? throw new ArgumentNullException(nameof(command)); |
| 30 | + } |
| 31 | + |
| 32 | + /// <summary> |
| 33 | + /// Gets all the roles in the app |
| 34 | + /// </summary> |
| 35 | + /// <returns>All the roles</returns> |
| 36 | + [HttpGet("[action]")] |
| 37 | + [ProducesResponseType(StatusCodes.Status200OK)] |
| 38 | + [ProducesResponseType(StatusCodes.Status204NoContent)] |
| 39 | + public IActionResult GetAllRoles() |
| 40 | + { |
| 41 | + var result = query.AllRolesQuery(); |
| 42 | + |
| 43 | + if (result == null || result.Count == 0) |
| 44 | + { |
| 45 | + return NoContent(); |
| 46 | + } |
| 47 | + |
| 48 | + return Ok(result); |
| 49 | + } |
| 50 | + |
| 51 | + /// <summary> |
| 52 | + /// Gets a single role with permissions |
| 53 | + /// </summary> |
| 54 | + /// <param name="roleId">Role identifier</param> |
| 55 | + /// <returns>The selected role with permissions</returns> |
| 56 | + [HttpGet("[action]/{roleId:int}")] |
| 57 | + [ProducesResponseType(StatusCodes.Status200OK)] |
| 58 | + [ProducesResponseType(StatusCodes.Status204NoContent)] |
| 59 | + public IActionResult GetRole(int roleId) |
| 60 | + { |
| 61 | + var result = query.GetRoleQuery(roleId); |
| 62 | + return Ok(result); |
| 63 | + } |
| 64 | + |
| 65 | + |
| 66 | + } |
| 67 | +} |
0 commit comments