Add project files.
This commit is contained in:
		
							
								
								
									
										6
									
								
								Core.Cerberos.Service.API/Cerberos.Service.API.http
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								Core.Cerberos.Service.API/Cerberos.Service.API.http
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | ||||
| @Core.Cerberos.Service.API_HostAddress = http://localhost:5145 | ||||
|  | ||||
| GET {{Core.Cerberos.Service.API_HostAddress}}/weatherforecast/ | ||||
| Accept: application/json | ||||
|  | ||||
| ### | ||||
							
								
								
									
										200
									
								
								Core.Cerberos.Service.API/Controllers/ModuleController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										200
									
								
								Core.Cerberos.Service.API/Controllers/ModuleController.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,200 @@ | ||||
| using Asp.Versioning; | ||||
| using Core.Cerberos.Adapters; | ||||
| using Core.Cerberos.Adapters.Attributes; | ||||
| using Core.Cerberos.Adapters.Common.Constants; | ||||
| using Core.Cerberos.Application.UseCases.Modules.Input; | ||||
| using Core.Cerberos.Application.UseCases.Modules.Ports; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Microsoft.AspNetCore.Authorization; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
|  | ||||
| namespace Core.Cerberos.Service.API.Controllers | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Handles all services and business rules related to <see cref="ModuleController"/>. | ||||
|     /// </summary> | ||||
|     [ApiVersion("1.0")] | ||||
|     [Route("api/v{api-version:apiVersion}/[controller]")] | ||||
|     [Produces("application/json")] | ||||
|     [ApiController] | ||||
|     public class ModuleController : ControllerBase | ||||
|     { | ||||
|         private readonly IComponentHandler<GetModuleRequest> getModuleHandler; | ||||
|         private readonly IComponentHandler<GetAllModulesRequest> getAllModulesHandler; | ||||
|         private readonly IComponentHandler<GetAllModulesByListRequest> getAllModulesByListHandler; | ||||
|         private readonly IComponentHandler<CreateModuleRequest> createModuleHandler; | ||||
|         private readonly IComponentHandler<UpdateModuleRequest> updateModuleHandler; | ||||
|         private readonly IComponentHandler<ChangeModuleStatusRequest> changeModuleStatusHandler; | ||||
|         private readonly IModulePort port; | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Handles all services and business rules related to <see cref="ModuleController"/>. | ||||
|         /// </summary> | ||||
|         public ModuleController( | ||||
|             IComponentHandler<GetModuleRequest> getModuleHandler, | ||||
|             IComponentHandler<GetAllModulesRequest> getAllModulesHandler, | ||||
|             IComponentHandler<GetAllModulesByListRequest> getAllModulesByListHandler, | ||||
|             IComponentHandler<CreateModuleRequest> createModuleHandler, | ||||
|             IComponentHandler<UpdateModuleRequest> updateModuleHandler, | ||||
|             IComponentHandler<ChangeModuleStatusRequest> changeModuleStatusHandler, | ||||
|             IModulePort port | ||||
|             ) | ||||
|         { | ||||
|             this.createModuleHandler = createModuleHandler; | ||||
|             this.updateModuleHandler = updateModuleHandler; | ||||
|             this.changeModuleStatusHandler = changeModuleStatusHandler; | ||||
|             this.getAllModulesHandler = getAllModulesHandler; | ||||
|             this.getModuleHandler = getModuleHandler; | ||||
|             this.getAllModulesByListHandler = getAllModulesByListHandler; | ||||
|             this.port = port; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets all the modules. | ||||
|         /// </summary> | ||||
|         [HttpGet("GetAll")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Permission("ModuleManagement.Read, RoleManagement.Read")] | ||||
|         public async Task<IActionResult> GetAllModulesAsync(CancellationToken cancellationToken) | ||||
|         { | ||||
|             await getAllModulesHandler.ExecuteAsync(new GetAllModulesRequest { }, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets all the modules by module identifiers. | ||||
|         /// </summary> | ||||
|         /// <param name="request">The request containing the list of module identifiers.</param> | ||||
|         /// <param name="cancellationToken">Cancellation token for the asynchronous operation.</param> | ||||
|         /// <returns>The <see cref="IActionResult"/> representing the result of the service call.</returns> | ||||
|         /// <response code="200">The modules found.</response> | ||||
|         /// <response code="204">No content if no modules are found.</response> | ||||
|         /// <response code="400">Bad request if the module identifiers are missing or invalid.</response> | ||||
|         /// <response code="401">Unauthorized if the user is not authenticated.</response> | ||||
|         /// <response code="412">Precondition failed if the request does not meet expected conditions.</response> | ||||
|         /// <response code="422">Unprocessable entity if the request cannot be processed.</response> | ||||
|         /// <response code="500">Internal server error if an unexpected error occurs.</response> | ||||
|         [HttpPost] | ||||
|         [Route(Routes.GetModuleList)] | ||||
|         [ProducesResponseType(typeof(IEnumerable<ModuleAdapter>), StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Permission("ModuleManagement.Read")] | ||||
|         public async Task<IActionResult> GetAllModulesByListAsync([FromBody] GetAllModulesByListRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|  | ||||
|             if (request == null || request.Modules == null || !request.Modules.Any()) | ||||
|             { | ||||
|                 return BadRequest("Module identifiers are required."); | ||||
|             } | ||||
|  | ||||
|             await getAllModulesByListHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets the module by identifier. | ||||
|         /// </summary> | ||||
|         [HttpPost] | ||||
|         [Route("GetById")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Permission("ModuleManagement.Read")] | ||||
|         public async Task<IActionResult> GetModuleById([FromBody] GetModuleRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|  | ||||
|             if (request.Id == null || !request.Id.Any()) | ||||
|             { | ||||
|                 return BadRequest("Invalid Module Id"); | ||||
|             } | ||||
|  | ||||
|             await getModuleHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Creates a new module. | ||||
|         /// </summary> | ||||
|         [HttpPost("Create")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Permission("ModuleManagement.Write")] | ||||
|         public async Task<IActionResult> CreateModuleAsync([FromBody] CreateModuleRequest newModule, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             await createModuleHandler.ExecuteAsync(newModule, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Updates a full module by identifier. | ||||
|         /// </summary> | ||||
|         [HttpPut("Update")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Permission("ModuleManagement.Write")] | ||||
|         public async Task<IActionResult> UpdateModuleAsync([FromBody] UpdateModuleRequest request, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             await updateModuleHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Changes the status of the module. | ||||
|         /// </summary> | ||||
|         [HttpPatch] | ||||
|         [Route("ChangeStatus")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Permission("ModuleManagement.Write")] | ||||
|         public async Task<IActionResult> ChangeModuleStatusAsync([FromBody] ChangeModuleStatusRequest request, | ||||
|                                                                      CancellationToken cancellationToken) | ||||
|         { | ||||
|             if (string.IsNullOrEmpty(request.Id)) { return BadRequest("Invalid module identifier"); } | ||||
|  | ||||
|             await changeModuleStatusHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										200
									
								
								Core.Cerberos.Service.API/Controllers/PermissionController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										200
									
								
								Core.Cerberos.Service.API/Controllers/PermissionController.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,200 @@ | ||||
| using Asp.Versioning; | ||||
| using Core.Cerberos.Adapters; | ||||
| using Core.Cerberos.Adapters.Attributes; | ||||
| using Core.Cerberos.Adapters.Common.Constants; | ||||
| using Core.Cerberos.Application.UseCases.Permissions.Input; | ||||
| using Core.Cerberos.Application.UseCases.Permissions.Ports; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Microsoft.AspNetCore.Authorization; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
|  | ||||
| namespace Core.Cerberos.Service.API.Controllers | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Handles all services and business rules related to <see cref="PermissionController"/>. | ||||
|     /// </summary> | ||||
|     [ApiVersion("1.0")] | ||||
|     [Route("api/v{api-version:apiVersion}/[controller]")] | ||||
|     [Produces("application/json")] | ||||
|     [ApiController] | ||||
|     public class PermissionController : ControllerBase | ||||
|     { | ||||
|         private readonly IComponentHandler<GetPermissionRequest> getPermissionHandler; | ||||
|         private readonly IComponentHandler<GetAllPermissionsRequest> getAllPermissionsHandler; | ||||
|         private readonly IComponentHandler<GetAllPermissionsByListRequest> getAllPermissionsByListHandler; | ||||
|         private readonly IComponentHandler<CreatePermissionRequest> createPermissionHandler; | ||||
|         private readonly IComponentHandler<UpdatePermissionRequest> updatePermissionHandler; | ||||
|         private readonly IComponentHandler<ChangePermissionStatusRequest> changePermissionStatusHandler; | ||||
|         private readonly IPermissionPort port; | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Handles all services and business rules related to <see cref="PermissionController"/>. | ||||
|         /// </summary> | ||||
|         public PermissionController( | ||||
|             IComponentHandler<GetPermissionRequest> getPermissionHandler, | ||||
|             IComponentHandler<GetAllPermissionsRequest> getAllPermissionsHandler, | ||||
|             IComponentHandler<GetAllPermissionsByListRequest> getAllPermissionsByListHandler, | ||||
|             IComponentHandler<CreatePermissionRequest> createPermissionHandler, | ||||
|             IComponentHandler<UpdatePermissionRequest> updatePermissionHandler, | ||||
|             IComponentHandler<ChangePermissionStatusRequest> changePermissionStatusHandler, | ||||
|             IPermissionPort port | ||||
|             ) | ||||
|         { | ||||
|             this.createPermissionHandler = createPermissionHandler; | ||||
|             this.updatePermissionHandler = updatePermissionHandler; | ||||
|             this.changePermissionStatusHandler = changePermissionStatusHandler; | ||||
|             this.getAllPermissionsHandler = getAllPermissionsHandler; | ||||
|             this.getPermissionHandler = getPermissionHandler; | ||||
|             this.getAllPermissionsByListHandler = getAllPermissionsByListHandler; | ||||
|             this.port = port; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets all the permissions. | ||||
|         /// </summary> | ||||
|         [HttpGet("GetAll")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Permission("PermissionManagement.Read, RoleManagement.Read")] | ||||
|         public async Task<IActionResult> GetAllPermissionsAsync(CancellationToken cancellationToken) | ||||
|         { | ||||
|             await getAllPermissionsHandler.ExecuteAsync(new GetAllPermissionsRequest { }, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets all the permissions by permission identifiers. | ||||
|         /// </summary> | ||||
|         /// <param name="request">The request containing the list of permission identifiers.</param> | ||||
|         /// <param name="cancellationToken">Cancellation token for the asynchronous operation.</param> | ||||
|         /// <returns>The <see cref="IActionResult"/> representing the result of the service call.</returns> | ||||
|         /// <response code="200">The permissions found.</response> | ||||
|         /// <response code="204">No content if no permissions are found.</response> | ||||
|         /// <response code="400">Bad request if the permission identifiers are missing or invalid.</response> | ||||
|         /// <response code="401">Unauthorized if the user is not authenticated.</response> | ||||
|         /// <response code="412">Precondition failed if the request does not meet expected conditions.</response> | ||||
|         /// <response code="422">Unprocessable entity if the request cannot be processed.</response> | ||||
|         /// <response code="500">Internal server error if an unexpected error occurs.</response> | ||||
|         [HttpPost] | ||||
|         [Route(Routes.GetPermissionList)] | ||||
|         [ProducesResponseType(typeof(IEnumerable<PermissionAdapter>), StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Permission("PermissionManagement.Read")] | ||||
|         public async Task<IActionResult> GetAllPermissionsByListAsync([FromBody] GetAllPermissionsByListRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|  | ||||
|             if (request == null || request.Permissions == null || !request.Permissions.Any()) | ||||
|             { | ||||
|                 return BadRequest("Permission identifiers are required."); | ||||
|             } | ||||
|  | ||||
|             await getAllPermissionsByListHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets the permission by identifier. | ||||
|         /// </summary> | ||||
|         [HttpPost] | ||||
|         [Route("GetById")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Permission("PermissionManagement.Read")] | ||||
|         public async Task<IActionResult> GetPermissionById([FromBody] GetPermissionRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|  | ||||
|             if (request.Id == null || !request.Id.Any()) | ||||
|             { | ||||
|                 return BadRequest("Invalid Permission Id"); | ||||
|             } | ||||
|  | ||||
|             await getPermissionHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Creates a new permission. | ||||
|         /// </summary> | ||||
|         [HttpPost("Create")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Permission("PermissionManagement.Write")] | ||||
|         public async Task<IActionResult> CreatePermissionAsync([FromBody] CreatePermissionRequest newPermission, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             await createPermissionHandler.ExecuteAsync(newPermission, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Updates a full permission by identifier. | ||||
|         /// </summary> | ||||
|         [HttpPut("Update")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Permission("PermissionManagement.Write")] | ||||
|         public async Task<IActionResult> UpdatePermissionAsync([FromBody] UpdatePermissionRequest request, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             await updatePermissionHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Changes the status of the permission. | ||||
|         /// </summary> | ||||
|         [HttpPatch] | ||||
|         [Route("ChangeStatus")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Permission("PermissionManagement.Write")] | ||||
|         public async Task<IActionResult> ChangePermissionStatusAsync([FromBody] ChangePermissionStatusRequest request, | ||||
|                                                                      CancellationToken cancellationToken) | ||||
|         { | ||||
|             if (string.IsNullOrEmpty(request.Id)) { return BadRequest("Invalid permission identifier"); } | ||||
|  | ||||
|             await changePermissionStatusHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										208
									
								
								Core.Cerberos.Service.API/Controllers/RoleController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										208
									
								
								Core.Cerberos.Service.API/Controllers/RoleController.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,208 @@ | ||||
| using Asp.Versioning; | ||||
| using Core.Cerberos.Adapters.Attributes; | ||||
| using Core.Cerberos.Adapters.Common.Constants; | ||||
| using Core.Cerberos.Application.UseCases.Roles.Input; | ||||
| using Core.Cerberos.Application.UseCases.Roles.Ports; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Microsoft.AspNetCore.Authorization; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
|  | ||||
| namespace Core.Cerberos.Service.API.Controllers | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Handles all requests for role authentication. | ||||
|     /// </summary> | ||||
|     [ApiVersion("1.0")] | ||||
|     [Route("api/v{api-version:apiVersion}/[controller]")] | ||||
|     [Produces("application/json")] | ||||
|     [ApiController] | ||||
|     [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|     public class RoleController : ControllerBase | ||||
|     { | ||||
|         private readonly IComponentHandler<GetRoleRequest> getRoleHandler; | ||||
|         private readonly IComponentHandler<GetAllRolesRequest> getAllRolesHandler; | ||||
|         private readonly IComponentHandler<CreateRoleRequest> createRoleHandler; | ||||
|         private readonly IComponentHandler<UpdateRoleRequest> updateRoleHandler; | ||||
|         private readonly IComponentHandler<ChangeRoleStatusRequest> changeStatusRoleHandler; | ||||
|         private readonly IComponentHandler<AddApplicationToRoleRequest> addApplicationToRoleHandler; | ||||
|         private readonly IComponentHandler<RemoveApplicationFromRoleRequest> removeApplicationToRoleHandler; | ||||
|         private readonly IRolePort port; | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Handles all requests for role authentication. | ||||
|         /// </summary> | ||||
|         public RoleController( | ||||
|             IComponentHandler<GetRoleRequest> getRoleHandler, | ||||
|             IComponentHandler<GetAllRolesRequest> getAllRolesHandler, | ||||
|             IComponentHandler<CreateRoleRequest> createRoleHandler, | ||||
|             IComponentHandler<UpdateRoleRequest> updateRoleHandler, | ||||
|             IComponentHandler<ChangeRoleStatusRequest> changeRoleStatusHandler, | ||||
|             IComponentHandler<AddApplicationToRoleRequest> addApplicationToRoleHandler, | ||||
|             IComponentHandler<RemoveApplicationFromRoleRequest> removeApplicationToRoleHandler, | ||||
|             IRolePort port | ||||
|             ) | ||||
|         { | ||||
|             this.createRoleHandler = createRoleHandler; | ||||
|             this.updateRoleHandler = updateRoleHandler; | ||||
|             this.changeStatusRoleHandler = changeRoleStatusHandler; | ||||
|             this.getAllRolesHandler = getAllRolesHandler; | ||||
|             this.getRoleHandler = getRoleHandler; | ||||
|             this.addApplicationToRoleHandler = addApplicationToRoleHandler; | ||||
|             this.removeApplicationToRoleHandler = removeApplicationToRoleHandler; | ||||
|             this.port = port; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets all the roles. | ||||
|         /// </summary> | ||||
|         [HttpGet("GetAll")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Permission("RoleManagement.Read")] | ||||
|         public async Task<IActionResult> GetAllRolesAsync(CancellationToken cancellationToken) | ||||
|         { | ||||
|             await getAllRolesHandler.ExecuteAsync(new GetAllRolesRequest { }, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets the role by identifier. | ||||
|         /// </summary> | ||||
|         [HttpPost] | ||||
|         [Route("GetById")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Permission("RoleManagement.Read")] | ||||
|         public async Task<IActionResult> GetRoleById([FromBody] GetRoleRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|             if (string.IsNullOrEmpty(request.Id)) { return BadRequest("Invalid role identifier"); } | ||||
|  | ||||
|             await getRoleHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Creates a new role. | ||||
|         /// </summary> | ||||
|         [HttpPost("Create")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Permission("RoleManagement.Write")] | ||||
|         public async Task<IActionResult> CreateRoleAsync([FromBody] CreateRoleRequest newRole, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             await createRoleHandler.ExecuteAsync(newRole, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Updates a full role by identifier. | ||||
|         /// </summary> | ||||
|         [HttpPut("Update")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Permission("RoleManagement.Write")] | ||||
|         public async Task<IActionResult> UpdateRoleAsync([FromBody] UpdateRoleRequest entity, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             await updateRoleHandler.ExecuteAsync(entity, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Changes the status of the role. | ||||
|         /// </summary> | ||||
|         [HttpPatch] | ||||
|         [Route("ChangeStatus")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Permission("RoleManagement.Write")] | ||||
|         public async Task<IActionResult> ChageRoleStatusAsync(ChangeRoleStatusRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|             if (string.IsNullOrEmpty(request.Id)) { return BadRequest("Invalid role identifier"); } | ||||
|  | ||||
|             await changeStatusRoleHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Adds an application to the role's list of applications. | ||||
|         /// </summary> | ||||
|         [HttpPost] | ||||
|         [Route("AddApplication")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Permission("RoleManagement.Write")] | ||||
|         public async Task<IActionResult> AddApplicationToRoleAsync(AddApplicationToRoleRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|             if (string.IsNullOrEmpty(request.RoleId)) { return BadRequest("Invalid role identifier"); } | ||||
|  | ||||
|             await addApplicationToRoleHandler.ExecuteAsync(request, cancellationToken); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Removes an application from the role's list of applications. | ||||
|         /// </summary> | ||||
|         [HttpDelete] | ||||
|         [Route("RemoveApplication")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Permission("RoleManagement.Write")] | ||||
|         public async Task<IActionResult> RemoveApplicationToRoleAsync(RemoveApplicationFromRoleRequest request, | ||||
|                                                                    CancellationToken cancellationToken) | ||||
|         { | ||||
|             if (string.IsNullOrEmpty(request.RoleId)) { return BadRequest("Invalid role identifier"); } | ||||
|  | ||||
|             await removeApplicationToRoleHandler.ExecuteAsync(request, cancellationToken); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										432
									
								
								Core.Cerberos.Service.API/Controllers/UserController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										432
									
								
								Core.Cerberos.Service.API/Controllers/UserController.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,432 @@ | ||||
| using Asp.Versioning; | ||||
| using Core.Cerberos.Adapters; | ||||
| using Core.Cerberos.Adapters.Attributes; | ||||
| using Core.Cerberos.Adapters.Common.Constants; | ||||
| using Core.Cerberos.Application.UseCases.Users.Input; | ||||
| using Core.Cerberos.Application.UseCases.Users.Ports; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Microsoft.AspNetCore.Authorization; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
|  | ||||
| namespace Core.Cerberos.Service.API.Controllers | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Handles all requests for user. | ||||
|     /// </summary> | ||||
|     [ApiVersion("1.0")] | ||||
|     [Route("api/v{api-version:apiVersion}/[controller]")] | ||||
|     [Produces("application/json")] | ||||
|     [ApiController] | ||||
|     public class UserController : ControllerBase | ||||
|     { | ||||
|         private readonly IComponentHandler<GetUserRequest> getUserHandler; | ||||
|         private readonly IComponentHandler<GetUserByEmailRequest> getUserByEmailHandler; | ||||
|         private readonly IComponentHandler<GetAllUsersRequest> getAllUsersHandler; | ||||
|         private readonly IComponentHandler<CreateUserRequest> createUserHandler; | ||||
|         private readonly IComponentHandler<UpdateUserRequest> updateUserHandler; | ||||
|         private readonly IComponentHandler<ChangeUserStatusRequest> ChangeUserStatusHandler; | ||||
|         private readonly IComponentHandler<AddCompanyToUserRequest> addCompanyToUserHandler; | ||||
|         private readonly IComponentHandler<RemoveCompanyFromUserRequest> removeCompanyFromUserHandler; | ||||
|         private readonly IComponentHandler<AddProjectToUserRequest> addProjectToUserHandler; | ||||
|         private readonly IComponentHandler<RemoveProjectFromUserRequest> removeProjectFromUserHandler; | ||||
|         private readonly IComponentHandler<LoginUserRequest> loginUserHandler; | ||||
|         private readonly IComponentHandler<LogoutUserRequest> logoutUserHandler; | ||||
|         private readonly IComponentHandler<ValidateUserExistenceRequest> validateUserHandler; | ||||
|         private readonly IComponentHandler<GetTokenAdapterRequest> getTokenAdapterHandler; | ||||
|         private readonly IComponentHandler<GetConsentFormPDFRequest> getConsentFormPDFHandler; | ||||
|         private readonly IComponentHandler<AcceptUserConsentFormRequest> acceptUserConsentFormHandler; | ||||
|         private readonly IUserPort port; | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Creates a new instance of UserController. | ||||
|         /// </summary> | ||||
|         public UserController( | ||||
|             IComponentHandler<GetUserRequest> getUserHandler, | ||||
|             IComponentHandler<GetUserByEmailRequest> getUserByEmailHandler, | ||||
|             IComponentHandler<GetAllUsersRequest> getAllUsersHandler, | ||||
|             IComponentHandler<CreateUserRequest> createUserHandler, | ||||
|             IComponentHandler<UpdateUserRequest> updateUserHandler, | ||||
|             IComponentHandler<ChangeUserStatusRequest> changeUserStatusHandler, | ||||
|             IComponentHandler<AddCompanyToUserRequest> addCompanyToUserHandler, | ||||
|             IComponentHandler<RemoveCompanyFromUserRequest> removeCompanyFromUserHandler, | ||||
|             IComponentHandler<AddProjectToUserRequest> addProjectToUserHandler, | ||||
|             IComponentHandler<RemoveProjectFromUserRequest> removeProjectFromUserHandler, | ||||
|             IComponentHandler<LoginUserRequest> loginUserHandler, | ||||
|             IComponentHandler<LogoutUserRequest> logoutUserHandler, | ||||
|             IComponentHandler<ValidateUserExistenceRequest> validateUserHandler, | ||||
|             IComponentHandler<GetTokenAdapterRequest> getTokenAdapterHandler, | ||||
|             IComponentHandler<GetConsentFormPDFRequest> getConsentFormPDFHandler, | ||||
|             IComponentHandler<AcceptUserConsentFormRequest> acceptUserConsentFormHandler, | ||||
|             IUserPort port | ||||
|             ) | ||||
|         { | ||||
|             this.createUserHandler = createUserHandler; | ||||
|             this.updateUserHandler = updateUserHandler; | ||||
|             this.ChangeUserStatusHandler = changeUserStatusHandler; | ||||
|             this.getAllUsersHandler = getAllUsersHandler; | ||||
|             this.getUserHandler = getUserHandler; | ||||
|             this.getUserByEmailHandler = getUserByEmailHandler; | ||||
|             this.addCompanyToUserHandler = addCompanyToUserHandler; | ||||
|             this.removeCompanyFromUserHandler = removeCompanyFromUserHandler; | ||||
|             this.addProjectToUserHandler = addProjectToUserHandler; | ||||
|             this.removeProjectFromUserHandler = removeProjectFromUserHandler; | ||||
|             this.loginUserHandler = loginUserHandler; | ||||
|             this.logoutUserHandler = logoutUserHandler; | ||||
|             this.validateUserHandler = validateUserHandler; | ||||
|             this.getTokenAdapterHandler = getTokenAdapterHandler; | ||||
|             this.getConsentFormPDFHandler = getConsentFormPDFHandler; | ||||
|             this.acceptUserConsentFormHandler = acceptUserConsentFormHandler; | ||||
|             this.port = port; | ||||
|         } | ||||
|         /// <summary> | ||||
|         /// Gets all the users. | ||||
|         /// </summary> | ||||
|         [HttpGet] | ||||
|         [Route("GetAll")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Permission("UserManagement.Read")] | ||||
|         public async Task<IActionResult> GetAllUsersAsync(CancellationToken cancellationToken) | ||||
|         { | ||||
|             await getAllUsersHandler.ExecuteAsync(new GetAllUsersRequest { }, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets the user by identifier. | ||||
|         /// </summary> | ||||
|         [HttpPost] | ||||
|         [Route("GetById")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Permission("UserManagement.Read")] | ||||
|         public async Task<IActionResult> GetUserById([FromBody] GetUserRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|             if (string.IsNullOrEmpty(request.Id)) { return BadRequest("Invalid user identifier"); } | ||||
|  | ||||
|             await getUserHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets the user by email. | ||||
|         /// </summary> | ||||
|         [HttpPost] | ||||
|         [Route("GetByEmail")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [Authorize(AuthenticationSchemes = $"{Schemes.HeathScheme}, {Schemes.AzureScheme}")] | ||||
|         public async Task<IActionResult> GetUserByEmail([FromBody] GetUserByEmailRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|             if (string.IsNullOrEmpty(request.Email)) { return BadRequest("Invalid user email"); } | ||||
|  | ||||
|             await getUserByEmailHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Creates a new user. | ||||
|         /// </summary> | ||||
|         [HttpPost] | ||||
|         [Route("Create")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Permission("UserManagement.Write")] | ||||
|         public async Task<IActionResult> CreateUserAsync([FromBody] CreateUserRequest newUser, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             await createUserHandler.ExecuteAsync(newUser, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Updates a full user by identifier. | ||||
|         /// </summary> | ||||
|         [HttpPut("Update")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Permission("UserManagement.Write")] | ||||
|         public async Task<IActionResult> UpdateUserAsync([FromBody] UpdateUserRequest request, | ||||
|                                                          CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             await updateUserHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Logs in the user. | ||||
|         /// </summary> | ||||
|         [HttpPatch("LoginUser")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [Authorize(AuthenticationSchemes = $"{Schemes.HeathScheme}, {Schemes.AzureScheme}")] | ||||
|         public async Task<IActionResult> LoginUserAsync([FromBody] LoginUserRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|             if (string.IsNullOrEmpty(request.Email)) { return BadRequest("Invalid user email"); } | ||||
|  | ||||
|             await loginUserHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Logs in the user. | ||||
|         /// </summary> | ||||
|         [HttpPatch("LogOutUser")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         public async Task<IActionResult> LogOutUserSessionAsync([FromBody] LogoutUserRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|             if (string.IsNullOrEmpty(request.Email)) { return BadRequest("Invalid user email"); } | ||||
|  | ||||
|             await logoutUserHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Changes the status of the user. | ||||
|         /// </summary> | ||||
|         [HttpPatch] | ||||
|         [Route("ChangeStatus")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Permission("UserManagement.Write")] | ||||
|         public async Task<IActionResult> ChangeUserStatusAsync([FromBody] ChangeUserStatusRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|             if (string.IsNullOrEmpty(request.Id)) { return BadRequest("Invalid user identifier"); } | ||||
|  | ||||
|             await ChangeUserStatusHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Adds a company to the user's list of companies. | ||||
|         /// </summary> | ||||
|         [HttpPost] | ||||
|         [Route("AddCompany")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Permission("UserManagement.Write")] | ||||
|         public async Task<IActionResult> AddCompanyToUserAsync([FromBody] AddCompanyToUserRequest request, | ||||
|                                                                CancellationToken cancellationToken) | ||||
|         { | ||||
|             if (string.IsNullOrEmpty(request.UserId)) { return BadRequest("Invalid user identifier"); } | ||||
|             if (string.IsNullOrEmpty(request.CompanyId)) { return BadRequest("Invalid company identifier"); } | ||||
|  | ||||
|             await addCompanyToUserHandler.ExecuteAsync(request, cancellationToken); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Removes a company from the user's list of companies. | ||||
|         /// </summary> | ||||
|         [HttpDelete] | ||||
|         [Route("RemoveCompany")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Permission("UserManagement.Write")] | ||||
|         public async Task<IActionResult> RemoveCompanyFromUserAsync([FromBody] RemoveCompanyFromUserRequest request, | ||||
|                                                                    CancellationToken cancellationToken) | ||||
|         { | ||||
|             if (string.IsNullOrEmpty(request.UserId)) { return BadRequest("Invalid user identifier"); } | ||||
|             if (string.IsNullOrEmpty(request.CompanyId)) { return BadRequest("Invalid company identifier"); } | ||||
|  | ||||
|             await removeCompanyFromUserHandler.ExecuteAsync(request, cancellationToken); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Adds a project to the user's list of projects. | ||||
|         /// </summary> | ||||
|         [HttpPost] | ||||
|         [Route("AddProject")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Permission("UserManagement.Write")] | ||||
|         public async Task<IActionResult> AddProjectToUserAsync([FromBody] AddProjectToUserRequest request, | ||||
|                                                               CancellationToken cancellationToken) | ||||
|         { | ||||
|             if (string.IsNullOrEmpty(request.UserId)) { return BadRequest("Invalid user identifier"); } | ||||
|             if (string.IsNullOrEmpty(request.ProjectId)) { return BadRequest("Invalid project identifier"); } | ||||
|  | ||||
|             await addProjectToUserHandler.ExecuteAsync(request, cancellationToken); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Removes a project from the user's list of projects. | ||||
|         /// </summary> | ||||
|         [HttpDelete] | ||||
|         [Route("RemoveProject")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Permission("UserManagement.Write")] | ||||
|         public async Task<IActionResult> RemoveProjectFromUserAsync([FromBody] RemoveProjectFromUserRequest request, | ||||
|                                                                    CancellationToken cancellationToken) | ||||
|         { | ||||
|  | ||||
|             if (string.IsNullOrEmpty(request.UserId)) { return BadRequest("Invalid user identifier"); } | ||||
|             if (string.IsNullOrEmpty(request.ProjectId)) { return BadRequest("Invalid project identifier"); } | ||||
|  | ||||
|             await removeProjectFromUserHandler.ExecuteAsync(request, cancellationToken); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Validates if a user exists on the database. | ||||
|         /// </summary> | ||||
|         [HttpPost] | ||||
|         [Route("ValidateExistence")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [AllowAnonymous] | ||||
|         public async Task<IActionResult> ValidateUserExistenceAsync([FromBody] ValidateUserExistenceRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|             if (string.IsNullOrEmpty(request.Email)) { return BadRequest("Invalid user email"); } | ||||
|  | ||||
|             await validateUserHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets a token for the user, including roles, permissions, and modules. | ||||
|         /// </summary> | ||||
|         [HttpPost] | ||||
|         [Route("GetTokenAdapter")] | ||||
|         [ProducesResponseType(typeof(TokenAdapter), StatusCodes.Status200OK)] | ||||
|         [Authorize(AuthenticationSchemes = $"{Schemes.HeathScheme}, {Schemes.AzureScheme}")] | ||||
|         public async Task<IActionResult> GetTokenAdapter([FromBody] GetTokenAdapterRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|             if (string.IsNullOrEmpty(request.Email)) { return BadRequest("Invalid user email"); } | ||||
|  | ||||
|             await getTokenAdapterHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Get Consent Form PDF. | ||||
|         /// </summary> | ||||
|         [HttpGet] | ||||
|         [Route("GetConsentFormPDF")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Permission("UserManagement.Read")] | ||||
|         public async Task<IActionResult> GetConsentFormPDFAsync(CancellationToken cancellationToken) | ||||
|         { | ||||
|             await getConsentFormPDFHandler.ExecuteAsync(new GetConsentFormPDFRequest { }, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Accept user consent form. | ||||
|         /// </summary> | ||||
|         [HttpPatch("AcceptUserConsentForm")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [Authorize(AuthenticationSchemes = $"{Schemes.HeathScheme}, {Schemes.AzureScheme}")] | ||||
|         public async Task<IActionResult> AcceptUserConsentFormAsync(CancellationToken cancellationToken) | ||||
|         { | ||||
|             await acceptUserConsentFormHandler.ExecuteAsync(new AcceptUserConsentFormRequest { }, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										27
									
								
								Core.Cerberos.Service.API/Core.Cerberos.Service.API.csproj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								Core.Cerberos.Service.API/Core.Cerberos.Service.API.csproj
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,27 @@ | ||||
| <Project Sdk="Microsoft.NET.Sdk.Web"> | ||||
|  | ||||
|   <PropertyGroup> | ||||
|     <TargetFramework>net8.0</TargetFramework> | ||||
|     <Nullable>enable</Nullable> | ||||
|     <ImplicitUsings>enable</ImplicitUsings> | ||||
|     <GenerateDocumentationFile>True</GenerateDocumentationFile> | ||||
|   </PropertyGroup> | ||||
|  | ||||
|   <ItemGroup> | ||||
|     <PackageReference Include="Core.Cerberos.Adapters" Version="0.3.0-alpha0042" /> | ||||
|   </ItemGroup> | ||||
|  | ||||
|   <ItemGroup> | ||||
|     <ProjectReference Include="..\Core.Cerberos.Application\Core.Cerberos.Application.csproj" /> | ||||
|     <ProjectReference Include="..\Core.Cerberos.External\Core.Cerberos.External.csproj" /> | ||||
|   </ItemGroup> | ||||
|  | ||||
|   <ItemGroup> | ||||
|     <Content Update="appsettings.Local.json"> | ||||
|       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||||
|       <ExcludeFromSingleFile>true</ExcludeFromSingleFile> | ||||
|       <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory> | ||||
|     </Content> | ||||
|   </ItemGroup> | ||||
|  | ||||
| </Project> | ||||
							
								
								
									
										99
									
								
								Core.Cerberos.Service.API/Extensions/SwaggerExtensions.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										99
									
								
								Core.Cerberos.Service.API/Extensions/SwaggerExtensions.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,99 @@ | ||||
| using Asp.Versioning.ApiExplorer; | ||||
| using Microsoft.Extensions.Options; | ||||
| using Microsoft.OpenApi.Models; | ||||
| using Swashbuckle.AspNetCore.SwaggerGen; | ||||
| using Swashbuckle.AspNetCore.SwaggerUI; | ||||
|  | ||||
| namespace Core.Cerberos.Service.API.Extensions | ||||
| { | ||||
|     public static class SwaggerExtensions | ||||
|     { | ||||
|         public static void AddSwagger(this IServiceCollection services, IConfiguration configuration) | ||||
|         { | ||||
|             services.AddEndpointsApiExplorer(); | ||||
|             AddSwaggerGen(services, configuration); | ||||
|             services.AddTransient<IConfigureOptions<SwaggerGenOptions>, ConfigureSwaggerOptions>(); | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Configures Swagger generation with OAuth2 security and XML comments. | ||||
|         /// </summary> | ||||
|         /// <param name="services">The <see cref="IServiceCollection"/> to add the services to.</param> | ||||
|         /// <param name="configuration">The <see cref="IConfiguration"/> containing Swagger and OAuth2 configuration settings.</param> | ||||
|         public static void AddSwaggerGen(this IServiceCollection services, IConfiguration configuration) | ||||
|         { | ||||
|             services.AddSwaggerGen(c => | ||||
|             { | ||||
|                 c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme | ||||
|                 { | ||||
|                     Description = "JWT Authorization header using the Bearer scheme", | ||||
|                     Name = "Authorization", | ||||
|                     In = ParameterLocation.Header, | ||||
|                     Type = SecuritySchemeType.Http, | ||||
|                     Scheme = "bearer", | ||||
|                     BearerFormat = "JWT" | ||||
|                 }); | ||||
|  | ||||
|                 c.AddSecurityRequirement(new OpenApiSecurityRequirement | ||||
|                 { | ||||
|                     { | ||||
|                         new OpenApiSecurityScheme | ||||
|                         { | ||||
|                             Reference = new OpenApiReference | ||||
|                             { | ||||
|                                 Type = ReferenceType.SecurityScheme, | ||||
|                                 Id = "Bearer" | ||||
|                             } | ||||
|                         }, | ||||
|                         Array.Empty<string>() | ||||
|                     } | ||||
|                 }); | ||||
|             }); | ||||
|         } | ||||
|         public static void ConfigureSwagger(this WebApplication app) | ||||
|         { | ||||
|             //Swagger Stuff Goes Here | ||||
|  | ||||
|             app.UseSwagger(); | ||||
|             app.UseSwaggerUI(options => | ||||
|             { | ||||
|                 foreach (var version in app.DescribeApiVersions().Select(version => version.GroupName)) | ||||
|                     options.SwaggerEndpoint($"/swagger/{version}/swagger.json", version); | ||||
|  | ||||
|                 options.DisplayRequestDuration(); | ||||
|                 options.EnableTryItOutByDefault(); | ||||
|                 options.DocExpansion(DocExpansion.None); | ||||
|             }); | ||||
|  | ||||
|             //  app.MapGet("/", () => Results.Redirect("/swagger/index.html")).WithTags(string.Empty); | ||||
|         } | ||||
|         public static IServiceCollection AddVersioning(this IServiceCollection services) | ||||
|         { | ||||
|             services.AddApiVersioning(options => options.ReportApiVersions = true) | ||||
|                    .AddApiExplorer(options => | ||||
|                    { | ||||
|                        options.GroupNameFormat = "'v'VVV"; | ||||
|                        options.SubstituteApiVersionInUrl = true; | ||||
|                    }); | ||||
|  | ||||
|             return services; | ||||
|         } | ||||
|     } | ||||
|     public class ConfigureSwaggerOptions(IApiVersionDescriptionProvider provider) : IConfigureOptions<SwaggerGenOptions> | ||||
|     { | ||||
|         private readonly IApiVersionDescriptionProvider _provider = provider; | ||||
|  | ||||
|         public void Configure(SwaggerGenOptions options) | ||||
|         { | ||||
|             foreach (var description in _provider.ApiVersionDescriptions) | ||||
|                 options.SwaggerDoc(description.GroupName, new() | ||||
|                 { | ||||
|                     Title = AppDomain.CurrentDomain.FriendlyName, | ||||
|                     Version = description.ApiVersion.ToString() | ||||
|                 }); | ||||
|  | ||||
|  | ||||
|             options.CustomSchemaIds(type => type.ToString().Replace("+", ".")); | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										170
									
								
								Core.Cerberos.Service.API/Program.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										170
									
								
								Core.Cerberos.Service.API/Program.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,170 @@ | ||||
| using Core.Cerberos.Adapters.Extensions; | ||||
| using Core.Cerberos.Adapters.Helpers; | ||||
| using Core.Cerberos.Application.UseCases.Modules; | ||||
| using Core.Cerberos.Application.UseCases.Modules.Adapter; | ||||
| using Core.Cerberos.Application.UseCases.Modules.Input; | ||||
| using Core.Cerberos.Application.UseCases.Modules.Ports; | ||||
| using Core.Cerberos.Application.UseCases.Modules.Validator; | ||||
| using Core.Cerberos.Application.UseCases.Permissions; | ||||
| using Core.Cerberos.Application.UseCases.Permissions.Adapter; | ||||
| using Core.Cerberos.Application.UseCases.Permissions.Input; | ||||
| using Core.Cerberos.Application.UseCases.Permissions.Ports; | ||||
| using Core.Cerberos.Application.UseCases.Permissions.Validator; | ||||
| using Core.Cerberos.Application.UseCases.Role; | ||||
| using Core.Cerberos.Application.UseCases.Roles.Adapter; | ||||
| using Core.Cerberos.Application.UseCases.Roles.Input; | ||||
| using Core.Cerberos.Application.UseCases.Roles.Ports; | ||||
| using Core.Cerberos.Application.UseCases.Roles.Validator; | ||||
| using Core.Cerberos.Application.UseCases.Users; | ||||
| using Core.Cerberos.Application.UseCases.Users.Adapter; | ||||
| using Core.Cerberos.Application.UseCases.Users.Input; | ||||
| using Core.Cerberos.Application.UseCases.Users.Ports; | ||||
| using Core.Cerberos.Application.UseCases.Users.Validator; | ||||
| using Core.Cerberos.External.ClientConfiguration; | ||||
| using Core.Cerberos.Service.API.Extensions; | ||||
| using FluentValidation; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Microsoft.AspNetCore.ResponseCompression; | ||||
| using System.IO.Compression; | ||||
|  | ||||
| var builder = WebApplication.CreateBuilder(args); | ||||
|  | ||||
| var authSettings = AuthHelper.GetAuthSettings(builder, "cerberos_service"); | ||||
|  | ||||
| builder.Services.ConfigureAuthentication(builder.Configuration, authSettings); | ||||
|  | ||||
| builder.Host.ConfigureServices((context, services) => | ||||
| { | ||||
|     services.AddCors(options => | ||||
|     { | ||||
|         options.AddPolicy("AllowAll", policyBuilder => | ||||
|             policyBuilder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod()); | ||||
|     }); | ||||
|     services.AddMvc().AddJsonOptions(options => | ||||
|     { | ||||
|         options.JsonSerializerOptions.WriteIndented = true; | ||||
|         options.JsonSerializerOptions.MaxDepth = 20; | ||||
|         options.JsonSerializerOptions.NumberHandling = System.Text.Json.Serialization.JsonNumberHandling.AllowNamedFloatingPointLiterals; | ||||
|     }); | ||||
|     services.Configure<BrotliCompressionProviderOptions>(options => | ||||
|     { | ||||
|         options.Level = CompressionLevel.SmallestSize; | ||||
|     }); | ||||
|     services.Configure<GzipCompressionProviderOptions>(options => | ||||
|     { | ||||
|         options.Level = CompressionLevel.SmallestSize; | ||||
|     }); | ||||
|     services.AddResponseCompression(options => | ||||
|     { | ||||
|         options.EnableForHttps = true; | ||||
|         options.Providers.Add<BrotliCompressionProvider>(); | ||||
|         options.Providers.Add<GzipCompressionProvider>(); | ||||
|     }); | ||||
|  | ||||
|     services.AddResponseCaching(); | ||||
|     services.AddControllers(); | ||||
|     services.AddEndpointsApiExplorer(); | ||||
|     builder.Services.AddSwagger(builder.Configuration, "Core.Cerberos.Service.API.xml", authSettings); | ||||
|     builder.Services.AddVersioning(builder.Configuration); | ||||
|     services.AddLogging(); | ||||
|     services.AddProblemDetails(); | ||||
|  | ||||
|     //Register Stuff | ||||
|     services.RegisterExternalLayer(builder.Configuration); | ||||
|  | ||||
|     services.AddScoped<IUserPort, UserPort>(); | ||||
|     services.AddScoped<IComponentHandler<GetAllUsersRequest>, UserHandler>(); | ||||
|     services.AddScoped<IComponentHandler<GetUserRequest>, UserHandler>(); | ||||
|     services.AddScoped<IComponentHandler<LoginUserRequest>, UserHandler>(); | ||||
|     services.AddScoped<IComponentHandler<LogoutUserRequest>, UserHandler>(); | ||||
|     services.AddScoped<IComponentHandler<GetUserByEmailRequest>, UserHandler>(); | ||||
|     services.AddScoped<IComponentHandler<AddCompanyToUserRequest>, UserHandler>(); | ||||
|     services.AddScoped<IComponentHandler<RemoveCompanyFromUserRequest>, UserHandler>(); | ||||
|     services.AddScoped<IComponentHandler<AddProjectToUserRequest>, UserHandler>(); | ||||
|     services.AddScoped<IComponentHandler<RemoveProjectFromUserRequest>, UserHandler>(); | ||||
|     services.AddScoped<IComponentHandler<ValidateUserExistenceRequest>, UserHandler>(); | ||||
|     services.AddScoped<IComponentHandler<GetTokenAdapterRequest>, UserHandler>(); | ||||
|     services.AddScoped<IComponentHandler<GetConsentFormPDFRequest>, UserHandler>(); | ||||
|     services.AddScoped<IComponentHandler<AcceptUserConsentFormRequest>, UserHandler>(); | ||||
|  | ||||
|  | ||||
|     services.AddValidatorsFromAssemblyContaining<CreateUserValidator>(); | ||||
|     services.AddScoped<IValidator<CreateUserRequest>, CreateUserValidator>(); | ||||
|     services.AddScoped<IComponentHandler<CreateUserRequest>, UserHandler>(); | ||||
|  | ||||
|     services.AddValidatorsFromAssemblyContaining<UpdateUserValidator>(); | ||||
|     services.AddScoped<IValidator<UpdateUserRequest>, UpdateUserValidator>(); | ||||
|     services.AddScoped<IComponentHandler<UpdateUserRequest>, UserHandler>(); | ||||
|  | ||||
|     services.AddValidatorsFromAssemblyContaining<ChangeUserStatusValidator>(); | ||||
|     services.AddScoped<IValidator<ChangeUserStatusRequest>, ChangeUserStatusValidator>(); | ||||
|     services.AddScoped<IComponentHandler<ChangeUserStatusRequest>, UserHandler>(); | ||||
|  | ||||
|     services.AddScoped<IRolePort, RolePort>(); | ||||
|     services.AddScoped<IComponentHandler<GetAllRolesRequest>, RoleHandler>(); | ||||
|     services.AddScoped<IComponentHandler<GetRoleRequest>, RoleHandler>(); | ||||
|     services.AddScoped<IComponentHandler<AddApplicationToRoleRequest>, RoleHandler>(); | ||||
|     services.AddScoped<IComponentHandler<RemoveApplicationFromRoleRequest>, RoleHandler>(); | ||||
|  | ||||
|     services.AddValidatorsFromAssemblyContaining<CreateRoleValidator>(); | ||||
|     services.AddScoped<IValidator<CreateRoleRequest>, CreateRoleValidator>(); | ||||
|     services.AddScoped<IComponentHandler<CreateRoleRequest>, RoleHandler>(); | ||||
|  | ||||
|     services.AddValidatorsFromAssemblyContaining<UpdateRoleValidator>(); | ||||
|     services.AddScoped<IValidator<UpdateRoleRequest>, UpdateRoleValidator>(); | ||||
|     services.AddScoped<IComponentHandler<UpdateRoleRequest>, RoleHandler>(); | ||||
|  | ||||
|     services.AddValidatorsFromAssemblyContaining<ChangeRoleStatusValidator>(); | ||||
|     services.AddScoped<IValidator<ChangeRoleStatusRequest>, ChangeRoleStatusValidator>(); | ||||
|     services.AddScoped<IComponentHandler<ChangeRoleStatusRequest>, RoleHandler>(); | ||||
|  | ||||
|     services.AddScoped<IPermissionPort, PermissionPort>(); | ||||
|     services.AddScoped<IComponentHandler<GetAllPermissionsRequest>, PermissionHandler>(); | ||||
|     services.AddScoped<IComponentHandler<GetPermissionRequest>, PermissionHandler>(); | ||||
|     services.AddScoped<IComponentHandler<GetAllPermissionsByListRequest>, PermissionHandler>(); | ||||
|  | ||||
|     services.AddValidatorsFromAssemblyContaining<CreatePermissionValidator>(); | ||||
|     services.AddScoped<IValidator<CreatePermissionRequest>, CreatePermissionValidator>(); | ||||
|     services.AddScoped<IComponentHandler<CreatePermissionRequest>, PermissionHandler>(); | ||||
|  | ||||
|     services.AddValidatorsFromAssemblyContaining<UpdatePermissionValidator>(); | ||||
|     services.AddScoped<IValidator<UpdatePermissionRequest>, UpdatePermissionValidator>(); | ||||
|     services.AddScoped<IComponentHandler<UpdatePermissionRequest>, PermissionHandler>(); | ||||
|  | ||||
|     services.AddValidatorsFromAssemblyContaining<ChangePermissionStatusValidator>(); | ||||
|     services.AddScoped<IValidator<ChangePermissionStatusRequest>, ChangePermissionStatusValidator>(); | ||||
|     services.AddScoped<IComponentHandler<ChangePermissionStatusRequest>, PermissionHandler>(); | ||||
|  | ||||
|     services.AddScoped<IModulePort, ModulePort>(); | ||||
|     services.AddScoped<IComponentHandler<GetAllModulesRequest>, ModuleHandler>(); | ||||
|     services.AddScoped<IComponentHandler<GetModuleRequest>, ModuleHandler>(); | ||||
|  | ||||
|     services.AddValidatorsFromAssemblyContaining<GetAllModulesByListValidator>(); | ||||
|     services.AddScoped<IValidator<GetAllModulesByListRequest>, GetAllModulesByListValidator>(); | ||||
|     services.AddScoped<IComponentHandler<GetAllModulesByListRequest>, ModuleHandler>(); | ||||
|  | ||||
|     services.AddValidatorsFromAssemblyContaining<CreateModuleValidator>(); | ||||
|     services.AddScoped<IValidator<CreateModuleRequest>, CreateModuleValidator>(); | ||||
|     services.AddScoped<IComponentHandler<CreateModuleRequest>, ModuleHandler>(); | ||||
|  | ||||
|     services.AddValidatorsFromAssemblyContaining<UpdateModuleValidator>(); | ||||
|     services.AddScoped<IValidator<UpdateModuleRequest>, UpdateModuleValidator>(); | ||||
|     services.AddScoped<IComponentHandler<UpdateModuleRequest>, ModuleHandler>(); | ||||
|  | ||||
|     services.AddValidatorsFromAssemblyContaining<ChangeModuleStatusValidator>(); | ||||
|     services.AddScoped<IValidator<ChangeModuleStatusRequest>, ChangeModuleStatusValidator>(); | ||||
|     services.AddScoped<IComponentHandler<ChangeModuleStatusRequest>, ModuleHandler>(); | ||||
| }); | ||||
|  | ||||
| var app = builder.Build(); | ||||
| app.UseSwaggerUI(builder.Configuration, authSettings); | ||||
| app.ConfigureSwagger(builder.Configuration); | ||||
| app.UseResponseCompression(); | ||||
| app.UseResponseCaching(); | ||||
| app.UseHttpsRedirection(); | ||||
| app.UseCors("AllowAll"); | ||||
| app.UseAuthorization(); | ||||
| app.MapControllers(); | ||||
|  | ||||
| app.Run(); | ||||
|  | ||||
							
								
								
									
										41
									
								
								Core.Cerberos.Service.API/Properties/launchSettings.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								Core.Cerberos.Service.API/Properties/launchSettings.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,41 @@ | ||||
| { | ||||
|   "$schema": "http://json.schemastore.org/launchsettings.json", | ||||
|   "iisSettings": { | ||||
|     "windowsAuthentication": false, | ||||
|     "anonymousAuthentication": true, | ||||
|     "iisExpress": { | ||||
|       "applicationUrl": "http://localhost:56379", | ||||
|       "sslPort": 44312 | ||||
|     } | ||||
|   }, | ||||
|   "profiles": { | ||||
|     "http": { | ||||
|       "commandName": "Project", | ||||
|       "dotnetRunMessages": true, | ||||
|       "launchBrowser": true, | ||||
|       "launchUrl": "swagger", | ||||
|       "applicationUrl": "http://localhost:5145", | ||||
|       "environmentVariables": { | ||||
|         "ASPNETCORE_ENVIRONMENT": "Local" | ||||
|       } | ||||
|     }, | ||||
|     "https": { | ||||
|       "commandName": "Project", | ||||
|       "dotnetRunMessages": true, | ||||
|       "launchBrowser": true, | ||||
|       "launchUrl": "swagger", | ||||
|       "applicationUrl": "https://localhost:7253;http://localhost:5145", | ||||
|       "environmentVariables": { | ||||
|         "ASPNETCORE_ENVIRONMENT": "Local" | ||||
|       } | ||||
|     }, | ||||
|     "IIS Express": { | ||||
|       "commandName": "IISExpress", | ||||
|       "launchBrowser": true, | ||||
|       "launchUrl": "swagger", | ||||
|       "environmentVariables": { | ||||
|         "ASPNETCORE_ENVIRONMENT": "Local" | ||||
|       } | ||||
|     } | ||||
|   } | ||||
| } | ||||
							
								
								
									
										9
									
								
								Core.Cerberos.Service.API/appsettings.Development.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								Core.Cerberos.Service.API/appsettings.Development.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| { | ||||
|   "Logging": { | ||||
|     "LogLevel": { | ||||
|       "Default": "Information", | ||||
|       "Microsoft.AspNetCore": "Warning" | ||||
|     } | ||||
|   }, | ||||
|   "AllowedHosts": "*" | ||||
| } | ||||
							
								
								
									
										12
									
								
								Core.Cerberos.Service.API/appsettings.Local.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								Core.Cerberos.Service.API/appsettings.Local.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | ||||
| { | ||||
|   "Logging": { | ||||
|     "LogLevel": { | ||||
|       "Default": "Information", | ||||
|       "Microsoft.AspNetCore": "Warning" | ||||
|     } | ||||
|   }, | ||||
|   "AllowedHosts": "*", | ||||
|   "LocalGateways": { | ||||
|     "CerberosDAL": "https://localhost:7031/api" | ||||
|   } | ||||
| } | ||||
							
								
								
									
										12
									
								
								Core.Cerberos.Service.API/appsettings.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								Core.Cerberos.Service.API/appsettings.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | ||||
| { | ||||
|   "Logging": { | ||||
|     "LogLevel": { | ||||
|       "Default": "Information", | ||||
|       "Microsoft.AspNetCore": "Warning" | ||||
|     } | ||||
|   }, | ||||
|   "AllowedHosts": "*", | ||||
|   "Endpoints": { | ||||
|     "AppConfigurationURI": "https://sandbox-hci-usc-appcg.azconfig.io" | ||||
|   } | ||||
| } | ||||
							
								
								
									
										30
									
								
								Core.Cerberos.Service.API/sample.settings.Development.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								Core.Cerberos.Service.API/sample.settings.Development.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,30 @@ | ||||
| { | ||||
|   "Gateways": { | ||||
|     "CerberosDAL": "" // Data access layer endpoint | ||||
|   }, | ||||
|   "ConnectionStrings": { | ||||
|     "KeyVault": "" //KeyVault Uri | ||||
|   }, | ||||
|   "JwtIssuerOptions": { | ||||
|     "Audience": "", // Audience for token creation, specifies intended recipients | ||||
|     "Issuer": "" // Issuer for token creation, identifies the issuer of the token | ||||
|   }, | ||||
|   "AzureAdB2C": { | ||||
|     "Instance": "", // Azure AD instance URL (STORED IN KEY VAULT) | ||||
|     "TenantId": "", // Azure AD tenant ID (STORED IN KEY VAULT) | ||||
|     "ClientId": "", // Azure AD application client ID (STORED IN KEY VAULT) | ||||
|     "ClientSecret": "", // Azure AD application client secret (STORED IN KEY VAULT) | ||||
|     "CallbackPath": "", // Path for redirect after authentication | ||||
|     "Scopes": "" // Access scopes for user permissions | ||||
|   }, | ||||
|   "HeathCerberosApp": { | ||||
|     "AuthorizationUrl": "", // URL for authorization endpoint (STORED IN KEY VAULT) | ||||
|     "TokenUrl": "", // URL for token endpoint (STORED IN KEY VAULT) | ||||
|     "Scope": "", // Scope for application permissions (STORED IN KEY VAULT) | ||||
|     "ClientId": "" // Client ID for Cerberos application (STORED IN KEY VAULT) | ||||
|   }, | ||||
|   "MicrosoftGraph": { | ||||
|     "Scopes": "", // Scopes for Microsoft Graph API access | ||||
|     "BaseUrl": "" // Base URL for Microsoft Graph API | ||||
|   } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Sergio Matias Urquin
					Sergio Matias Urquin