Add project files.
This commit is contained in:
		
							
								
								
									
										107
									
								
								Core.Cerberos.BFF.Api/Controllers/AuthenticationController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										107
									
								
								Core.Cerberos.BFF.Api/Controllers/AuthenticationController.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,107 @@ | ||||
| using Asp.Versioning; | ||||
| using Core.Cerberos.Adapters; | ||||
| using Core.Cerberos.Adapters.Common.Constants; | ||||
| using Core.Cerberos.Adapters.Contracts; | ||||
| using Core.Cerberos.Application.UseCases.Users.Input; | ||||
| using Core.Cerberos.External.Clients.Cerberos.Requests.Users; | ||||
| using LSA.Dashboard.External.Clients.Dashboard; | ||||
| using Microsoft.AspNetCore.Authorization; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
|  | ||||
| namespace Core.Cerberos.BFF.Api.Controllers | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Handles all requests for Authentication. | ||||
|     /// </summary> | ||||
|     [ApiVersion(MimeTypes.ApplicationVersion)] | ||||
|     [Route("api/v{api-version:apiVersion}/[controller]")] | ||||
|     [Produces(MimeTypes.ApplicationJson)] | ||||
|     [Consumes(MimeTypes.ApplicationJson)] | ||||
|     [ApiController] | ||||
|     public class AuthenticationController(ICerberosServiceClient cerberosServiceClient, ILogger<AuthenticationController> logger, ITokenService tokenService) : BaseController(logger) | ||||
|     { | ||||
|         /// <summary> | ||||
|         /// Get token for user. | ||||
|         /// </summary> | ||||
|         /// <returns>A <see cref="UserAdapter"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         /// <response code="200">The Token was generated.</response> | ||||
|         /// <response code="500">The service internal error.</response> | ||||
|         [HttpGet] | ||||
|         [Route(Routes.GenerateToken)] | ||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.AzureScheme)] | ||||
|         public async Task<IActionResult> GenerateTokenService(CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 logger.LogInformation($"{nameof(GenerateTokenService)} - Request received - Payload: {null}"); | ||||
|  | ||||
|                 var tokenAdapter = new TokenAdapter(); | ||||
|  | ||||
|                 var email = tokenService.GetEmailClaim(this.HttpContext); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(email)) return BadRequest("An error ocurred while desearializing the token"); | ||||
|  | ||||
|                 var tokenResult = await Handle(() => cerberosServiceClient.GetTokenAdapterService(new GetTokenAdapterRequest { Email = email }, cancellationToken)).ConfigureAwait(false); | ||||
|  | ||||
|                 if (tokenResult is ObjectResult tokenOkResult && tokenOkResult.StatusCode == 200) | ||||
|                     tokenAdapter = tokenOkResult.Value as TokenAdapter; | ||||
|                 else | ||||
|                     return tokenResult; | ||||
|  | ||||
|                 if (tokenAdapter is not null && tokenAdapter.User is not null) | ||||
|                 { | ||||
|                     tokenAdapter.User.Token = tokenService.GenerateAccessToken(tokenAdapter); | ||||
|  | ||||
|                     await Handle(() => cerberosServiceClient.LoginUserService(new LoginUserRequest { Email = email }, cancellationToken)).ConfigureAwait(false); | ||||
|  | ||||
|                     return Ok(tokenAdapter.User); | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     return BadRequest("An error ocurred"); | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError($"{nameof(GenerateTokenService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload : {null}"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Refreshes the custom access token. | ||||
|         /// </summary> | ||||
|         /// <returns>A <see cref="UserAdapter"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         /// <response code="200">The user with it's new token.</response> | ||||
|         /// <response code="500">The service internal error.</response> | ||||
|         [HttpGet] | ||||
|         [Route(Routes.RefreshToken)] | ||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         public async Task<IActionResult> RefreshCustomTokenAsync(CancellationToken cancellationToken) | ||||
|         { | ||||
|             var tokenAdapter = new TokenAdapter(); | ||||
|             var email = tokenService.GetEmailClaim(this.HttpContext); | ||||
|  | ||||
|             var tokenResult = await Handle(() => cerberosServiceClient.GetTokenAdapterService(new GetTokenAdapterRequest { Email = email }, cancellationToken)).ConfigureAwait(false); | ||||
|  | ||||
|             if (tokenResult is ObjectResult tokenOkResult && tokenOkResult.StatusCode == 200) | ||||
|             { | ||||
|                 tokenAdapter = tokenOkResult.Value as TokenAdapter; | ||||
|  | ||||
|                 if (tokenAdapter != null) | ||||
|                 { | ||||
|                     var result = tokenService.RefreshAccessToken(HttpContext, tokenAdapter); | ||||
|                     return result; | ||||
|                 } | ||||
|             } | ||||
|             else return tokenResult; | ||||
|  | ||||
|             return new UnauthorizedObjectResult("Error in refreshToken"); | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										30
									
								
								Core.Cerberos.BFF.Api/Controllers/BaseController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								Core.Cerberos.BFF.Api/Controllers/BaseController.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,30 @@ | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
| using Newtonsoft.Json; | ||||
| using Refit; | ||||
|  | ||||
| namespace Core.Cerberos.BFF.Api.Controllers | ||||
| { | ||||
|     [Route("api/[controller]")] | ||||
|     [ApiController] | ||||
|     public class BaseController(ILogger<BaseController> logger) : ControllerBase | ||||
|     { | ||||
|         private readonly ILogger<BaseController> _logger = logger; | ||||
|  | ||||
|         protected Guid TrackingId => (Guid)(HttpContext.Items["TrackingId"] ?? Guid.NewGuid()); | ||||
|  | ||||
|         protected async Task<IActionResult> Handle<T>(Func<Task<ApiResponse<T>>> apiCall) where T : class | ||||
|         { | ||||
|             var response = await apiCall().ConfigureAwait(false); | ||||
|  | ||||
|             _logger.LogInformation($"{TrackingId} - {response.RequestMessage?.Method} {response.RequestMessage?.RequestUri} - Status: {response.StatusCode}"); | ||||
|  | ||||
|             return FromAPIResponse(response); | ||||
|         } | ||||
|  | ||||
|         private IActionResult FromAPIResponse<T>(ApiResponse<T> response) where T : class | ||||
|         { | ||||
|             var errorContent = JsonConvert.DeserializeObject<string>(response.Error?.Content ?? string.Empty) ?? string.Empty; | ||||
|             return StatusCode((int)response.StatusCode, (response.Content is not null) ? response.Content : errorContent); | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										219
									
								
								Core.Cerberos.BFF.Api/Controllers/ModuleController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										219
									
								
								Core.Cerberos.BFF.Api/Controllers/ModuleController.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,219 @@ | ||||
| using Asp.Versioning; | ||||
| using Core.Cerberos.Adapters; | ||||
| using Core.Cerberos.Adapters.Attributes; | ||||
| using Core.Cerberos.Adapters.Common.Constants; | ||||
| using Core.Cerberos.External.Clients.Cerberos.Requests.Permissions; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using LSA.Dashboard.External.Clients.Dashboard; | ||||
| using Microsoft.AspNetCore.Authorization; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
| using System.Text.Json; | ||||
|  | ||||
| namespace Core.Cerberos.BFF.Api.Controllers | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Handles all requests for module authentication. | ||||
|     /// </summary> | ||||
|     [ApiVersion("1.0")] | ||||
|     [Route("api/v{version:apiVersion}/[controller]")] | ||||
|     [Consumes("application/json")] | ||||
|     [Produces("application/json")] | ||||
|     [ApiController] | ||||
|     [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|     public class ModuleController(ICerberosServiceClient cerberosServiceClient, ILogger<ModuleController> logger) : BaseController(logger) | ||||
|     { | ||||
|         /// <summary> | ||||
|         /// Gets all the modules. | ||||
|         /// </summary> | ||||
|         [HttpGet("GetAll")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [Permission("ModuleManagement.Read, RoleManagement.Read")] | ||||
|         public async Task<IActionResult> GetAllModulesService(CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 logger.LogInformation($"{nameof(GetAllModulesService)} - Request received - Payload: "); | ||||
|  | ||||
|                 return await Handle(() => cerberosServiceClient.GetAllModulesService(new GetAllModulesRequest { }, cancellationToken)).ConfigureAwait(false); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError($"{nameof(GetAllModulesService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <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="500">Internal server error if an unexpected error occurs.</response> | ||||
|         [HttpPost("GetAllByList")] | ||||
|         [ProducesResponseType(typeof(IEnumerable<ModuleAdapter>), StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [Permission("ModuleManagement.Read")] | ||||
|         public async Task<IActionResult> GetAllModulesByListAsync([FromBody] GetAllModulesByListRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 logger.LogInformation($"{nameof(GetAllModulesByListAsync)} - Request received - Payload: {request}"); | ||||
|  | ||||
|                 if (request == null || request.Modules == null || !request.Modules.Any()) | ||||
|                 { | ||||
|                     return BadRequest("Module identifiers are required."); | ||||
|                 } | ||||
|  | ||||
|                 return await Handle(() => cerberosServiceClient.GetAllModulesByListService(request, cancellationToken)).ConfigureAwait(false); | ||||
|  | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError(ex, $"{nameof(GetAllModulesByListAsync)} - An error occurred - {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload: {request}"); | ||||
|                 return StatusCode(StatusCodes.Status500InternalServerError, "Internal server error"); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Creates a new module. | ||||
|         /// </summary> | ||||
|         [HttpPost("Create")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [Permission("ModuleManagement.Write")] | ||||
|         public async Task<IActionResult> CreateModuleService(CreateModuleRequest newModule, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 logger.LogInformation($"{nameof(CreateModuleService)} - Request received - Payload: {JsonSerializer.Serialize(newModule)}"); | ||||
|  | ||||
|                 if (newModule == null) return BadRequest("Invalid module object"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(newModule.Name)) return BadRequest("Invalid module name"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(newModule.Description)) return BadRequest("Invalid module description"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(newModule.Route)) return BadRequest("Invalid module route"); | ||||
|  | ||||
|                 return await Handle(() => cerberosServiceClient.CreateModuleService(newModule, cancellationToken)).ConfigureAwait(false); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError($"{nameof(CreateModuleService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(newModule)}"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets the module by identifier. | ||||
|         /// </summary> | ||||
|         [HttpPost("GetById")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [Permission("ModuleManagement.Read")] | ||||
|         public async Task<IActionResult> GetModuleByIdService(GetModuleRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 logger.LogInformation($"{nameof(GetModuleByIdService)} - Request received - Payload: {JsonSerializer.Serialize(request)}"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(request.Id)) return BadRequest("Invalid module identifier"); | ||||
|  | ||||
|                 return await Handle(() => cerberosServiceClient.GetModuleByIdService(request, cancellationToken)).ConfigureAwait(false); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError($"{nameof(GetModuleByIdService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Updates a full module by identifier. | ||||
|         /// </summary> | ||||
|         [HttpPut("Update")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [Permission("ModuleManagement.Write")] | ||||
|         public async Task<IActionResult> UpdateModuleService(UpdateModuleRequest newModule, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 logger.LogInformation($"{nameof(UpdateModuleService)} - Request received - Payload: {JsonSerializer.Serialize(newModule)}"); | ||||
|  | ||||
|                 if (newModule == null) return BadRequest("Invalid module object"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(newModule.Name)) return BadRequest("Invalid module name"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(newModule.Description)) return BadRequest("Invalid module description"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(newModule.Route)) return BadRequest("Invalid module route"); | ||||
|  | ||||
|                 return await Handle(() => cerberosServiceClient.UpdateModuleService(newModule, cancellationToken)).ConfigureAwait(false); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError($"{nameof(UpdateModuleService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(newModule)}"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <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)] | ||||
|         [Permission("ModuleManagement.Write")] | ||||
|         public async Task<IActionResult> ChangeModuleStatusService([FromBody] ChangeModuleStatusRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 logger.LogInformation($"{nameof(ChangeModuleStatusService)} - Request received - Payload: {JsonSerializer.Serialize(request)}"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(request.Id)) { return BadRequest("Invalid module identifier"); } | ||||
|  | ||||
|                 return await Handle(() => cerberosServiceClient.ChangeModuleStatusService(request, cancellationToken)).ConfigureAwait(false); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError($"{nameof(ChangeModuleStatusService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|  | ||||
|     } | ||||
| } | ||||
							
								
								
									
										216
									
								
								Core.Cerberos.BFF.Api/Controllers/PermissionController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										216
									
								
								Core.Cerberos.BFF.Api/Controllers/PermissionController.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,216 @@ | ||||
| using Asp.Versioning; | ||||
| using Core.Cerberos.Adapters; | ||||
| using Core.Cerberos.Adapters.Attributes; | ||||
| using Core.Cerberos.Adapters.Common.Constants; | ||||
| using Core.Cerberos.External.Clients.Cerberos.Requests.Permissions; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using LSA.Dashboard.External.Clients.Dashboard; | ||||
| using Microsoft.AspNetCore.Authorization; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
| using Microsoft.Graph; | ||||
| using System.Text.Json; | ||||
|  | ||||
| namespace Core.Cerberos.BFF.Api.Controllers | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Handles all requests for permission authentication. | ||||
|     /// </summary> | ||||
|     [ApiVersion("1.0")] | ||||
|     [Route("api/v{version:apiVersion}/[controller]")] | ||||
|     [Consumes("application/json")] | ||||
|     [Produces("application/json")] | ||||
|     [ApiController] | ||||
|     [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|     public class PermissionController(ICerberosServiceClient cerberosServiceClient, ILogger<PermissionController> logger) : BaseController(logger) | ||||
|     { | ||||
|         /// <summary> | ||||
|         /// Gets all the permissions. | ||||
|         /// </summary> | ||||
|         [HttpGet("GetAll")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [Permission("PermissionManagement.Read, RoleManagement.Read")] | ||||
|         public async Task<IActionResult> GetAllPermissionsService(CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 logger.LogInformation($"{nameof(GetAllPermissionsService)} - Request received - Payload: "); | ||||
|  | ||||
|                 return await Handle(() => cerberosServiceClient.GetAllPermissionsService(new GetAllPermissionsRequest { }, cancellationToken)).ConfigureAwait(false); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError($"{nameof(GetAllPermissionsService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <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="500">Internal server error if an unexpected error occurs.</response> | ||||
|         [HttpPost("GetAllByList")] | ||||
|         [ProducesResponseType(typeof(IEnumerable<PermissionAdapter>), StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [Permission("PermissionManagement.Read")] | ||||
|         public async Task<IActionResult> GetAllPermissionsByListAsync([FromBody] GetAllPermissionsByListRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 logger.LogInformation($"{nameof(GetAllPermissionsByListAsync)} - Request received - Payload: {request}"); | ||||
|  | ||||
|                 if (request == null || request.Permissions == null || !request.Permissions.Any()) | ||||
|                 { | ||||
|                     return BadRequest("Permission identifiers are required."); | ||||
|                 } | ||||
|  | ||||
|                 return await Handle(() => cerberosServiceClient.GetAllPermissionsByListService(request, cancellationToken)).ConfigureAwait(false); | ||||
|  | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError(ex, $"{nameof(GetAllPermissionsByListAsync)} - An error occurred - {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload: {request}"); | ||||
|                 return StatusCode(StatusCodes.Status500InternalServerError, "Internal server error"); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Creates a new permission. | ||||
|         /// </summary> | ||||
|         [HttpPost("Create")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [Permission("PermissionManagement.Write")] | ||||
|         public async Task<IActionResult> CreatePermissionService(CreatePermissionRequest newPermission, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 logger.LogInformation($"{nameof(CreatePermissionService)} - Request received - Payload: {JsonSerializer.Serialize(newPermission)}"); | ||||
|  | ||||
|                 if (newPermission == null) return BadRequest("Invalid permission object"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(newPermission.Name)) return BadRequest("Invalid permission name"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(newPermission.Description)) return BadRequest("Invalid permission description"); | ||||
|  | ||||
|                 return await Handle(() => cerberosServiceClient.CreatePermissionService(newPermission, cancellationToken)).ConfigureAwait(false); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError($"{nameof(CreatePermissionService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(newPermission)}"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets the permission by identifier. | ||||
|         /// </summary> | ||||
|         [HttpPost("GetById")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [Permission("PermissionManagement.Read")] | ||||
|         public async Task<IActionResult> GetPermissionByIdService(GetPermissionRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 logger.LogInformation($"{nameof(GetPermissionByIdService)} - Request received - Payload: {JsonSerializer.Serialize(request)}"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(request.Id)) return BadRequest("Invalid permission identifier"); | ||||
|  | ||||
|                 return await Handle(() => cerberosServiceClient.GetPermissionByIdService(request, cancellationToken)).ConfigureAwait(false); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError($"{nameof(GetPermissionByIdService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Updates a full permission by identifier. | ||||
|         /// </summary> | ||||
|         [HttpPut("Update")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [Permission("PermissionManagement.Write")] | ||||
|         public async Task<IActionResult> UpdatePermissionService(UpdatePermissionRequest newPermission, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 logger.LogInformation($"{nameof(UpdatePermissionService)} - Request received - Payload: {JsonSerializer.Serialize(newPermission)}"); | ||||
|  | ||||
|                 if (newPermission == null) return BadRequest("Invalid permission object"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(newPermission.Name)) return BadRequest("Invalid permission name"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(newPermission.Description)) return BadRequest("Invalid permission description"); | ||||
|  | ||||
|                 return await Handle(() => cerberosServiceClient.UpdatePermissionService(newPermission, cancellationToken)).ConfigureAwait(false); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError($"{nameof(UpdatePermissionService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(newPermission)}"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <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)] | ||||
|         [Permission("PermissionManagement.Write")] | ||||
|         public async Task<IActionResult> ChangePermissionStatusService([FromBody] ChangePermissionStatusRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 logger.LogInformation($"{nameof(ChangePermissionStatusService)} - Request received - Payload: {JsonSerializer.Serialize(request)}"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(request.Id)) { return BadRequest("Invalid permission identifier"); } | ||||
|  | ||||
|                 return await Handle(() => cerberosServiceClient.ChangePermissionStatusService(request, cancellationToken)).ConfigureAwait(false); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError($"{nameof(ChangePermissionStatusService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|  | ||||
|     } | ||||
| } | ||||
							
								
								
									
										247
									
								
								Core.Cerberos.BFF.Api/Controllers/RoleController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										247
									
								
								Core.Cerberos.BFF.Api/Controllers/RoleController.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,247 @@ | ||||
| using Asp.Versioning; | ||||
| using Core.Cerberos.Adapters.Attributes; | ||||
| using Core.Cerberos.Adapters.Common.Constants; | ||||
| using Core.Cerberos.Application.UseCases.Roles.Input; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using LSA.Dashboard.External.Clients.Dashboard; | ||||
| using Microsoft.AspNetCore.Authorization; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
| using System.Text.Json; | ||||
|  | ||||
| namespace Core.Cerberos.BFF.Api.Controllers | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Handles all requests for role authentication. | ||||
|     /// </summary> | ||||
|     [ApiVersion("1.0")] | ||||
|     [Route("api/v{version:apiVersion}/[controller]")] | ||||
|     [Consumes("application/json")] | ||||
|     [Produces("application/json")] | ||||
|     [ApiController] | ||||
|     [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|     public class RoleController(ICerberosServiceClient cerberosServiceClient, ILogger<RoleController> logger) : BaseController(logger) | ||||
|     { | ||||
|         /// <summary> | ||||
|         /// Gets all the roles. | ||||
|         /// </summary> | ||||
|         [HttpGet("GetAll")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [Permission("RoleManagement.Read")] | ||||
|         public async Task<IActionResult> GetAllRolesService(CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 logger.LogInformation($"{nameof(GetAllRolesService)} - Request received - Payload: "); | ||||
|  | ||||
|                 return await Handle(() => cerberosServiceClient.GetAllRolesService(new GetAllRolesRequest { }, cancellationToken)).ConfigureAwait(false); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError($"{nameof(GetAllRolesService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Creates a new role. | ||||
|         /// </summary> | ||||
|         [HttpPost("Create")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [Permission("RoleManagement.Write")] | ||||
|         public async Task<IActionResult> CreateRoleService(CreateRoleRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 logger.LogInformation($"{nameof(CreateRoleService)} - Request received - Payload: {JsonSerializer.Serialize(request)}"); | ||||
|  | ||||
|                 if (request == null) return BadRequest("Invalid role object"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(request.Name)) return BadRequest("Invalid role name"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(request.Description)) return BadRequest("Invalid role description"); | ||||
|  | ||||
|                 if (request.Applications?.Length <= 0) return BadRequest("Role must have at least one application"); | ||||
|  | ||||
|                 if (request.Modules?.Length <= 0) return BadRequest("Role must have at least one module"); | ||||
|  | ||||
|                 if (request.Permissions?.Length <= 0) return BadRequest("Role must have at least one permission"); | ||||
|  | ||||
|                 return await Handle(() => cerberosServiceClient.CreateRoleService(request, cancellationToken)).ConfigureAwait(false); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError($"{nameof(CreateRoleService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets the role by identifier. | ||||
|         /// </summary> | ||||
|         [HttpPost("GetById")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [Permission("RoleManagement.Read")] | ||||
|         public async Task<IActionResult> GetRoleByIdService(GetRoleRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 logger.LogInformation($"{nameof(GetRoleByIdService)} - Request received - Payload: {JsonSerializer.Serialize(request)}"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(request.Id)) return BadRequest("Invalid role identifier"); | ||||
|  | ||||
|                 return await Handle(() => cerberosServiceClient.GetRoleByIdService(request, cancellationToken)).ConfigureAwait(false); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError($"{nameof(GetRoleByIdService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Updates a full role by identifier. | ||||
|         /// </summary> | ||||
|         [HttpPut("Update")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [Permission("RoleManagement.Write")] | ||||
|         public async Task<IActionResult> UpdateRoleService(UpdateRoleRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 logger.LogInformation($"{nameof(UpdateRoleService)} - Request received - Payload: {JsonSerializer.Serialize(request)}"); | ||||
|  | ||||
|                 if (request == null) return BadRequest("Invalid role object"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(request.Name)) return BadRequest("Invalid role name"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(request.Id)) return BadRequest("Invalid role identifier"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(request.Description)) return BadRequest("Invalid role description"); | ||||
|  | ||||
|                 if (request.Applications?.Length <= 0) return BadRequest("Role must have at least one application"); | ||||
|  | ||||
|                 if (request.Modules?.Length <= 0) return BadRequest("Role must have at least one module"); | ||||
|  | ||||
|                 if (request.Permissions?.Length <= 0) return BadRequest("Role must have at least one permission"); | ||||
|  | ||||
|  | ||||
|                 return await Handle(() => cerberosServiceClient.UpdateRoleService(request, cancellationToken)).ConfigureAwait(false); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError($"{nameof(UpdateRoleService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <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)] | ||||
|         [Permission("RoleManagement.Write")] | ||||
|         public async Task<IActionResult> ChangeRoleStatusService([FromBody] ChangeRoleStatusRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 logger.LogInformation($"{nameof(ChangeRoleStatusService)} - Request received - Payload: {JsonSerializer.Serialize(request)}"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(request.Id)) { return BadRequest("Invalid role identifier"); } | ||||
|  | ||||
|                 return await Handle(() => cerberosServiceClient.ChangeRoleStatusService(request, cancellationToken)).ConfigureAwait(false); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError($"{nameof(ChangeRoleStatusService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <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)] | ||||
|         [Permission("RoleManagement.Write")] | ||||
|         public async Task<IActionResult> AddApplicationToRoleService([FromBody] AddApplicationToRoleRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 logger.LogInformation($"{nameof(AddApplicationToRoleService)} - Request received - Payload: {JsonSerializer.Serialize(request)}"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(request.RoleId)) { return BadRequest("Invalid role identifier"); } | ||||
|  | ||||
|                 return await Handle(() => cerberosServiceClient.AddApplicationToRoleService(request, cancellationToken)).ConfigureAwait(false); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError($"{nameof(AddApplicationToRoleService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <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)] | ||||
|         [Permission("RoleManagement.Write")] | ||||
|         public async Task<IActionResult> RemoveApplicationFromRoleService([FromBody] RemoveApplicationFromRoleRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 logger.LogInformation($"{nameof(RemoveApplicationFromRoleService)} - Request received - Payload: {JsonSerializer.Serialize(request)}"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(request.RoleId)) { return BadRequest("Invalid role identifier"); } | ||||
|  | ||||
|                 return await Handle(() => cerberosServiceClient.RemoveApplicationFromRoleService(request, cancellationToken)).ConfigureAwait(false); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError($"{nameof(RemoveApplicationFromRoleService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										431
									
								
								Core.Cerberos.BFF.Api/Controllers/UserController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										431
									
								
								Core.Cerberos.BFF.Api/Controllers/UserController.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,431 @@ | ||||
| using Asp.Versioning; | ||||
| using Core.Cerberos.Adapters.Attributes; | ||||
| using Core.Cerberos.Adapters.Common.Constants; | ||||
| using Core.Cerberos.Application.UseCases.Users.Input; | ||||
| using Core.Cerberos.External.Clients.Cerberos.Requests.Users; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using LSA.Dashboard.External.Clients.Dashboard; | ||||
| using Microsoft.AspNetCore.Authorization; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
| using System.Text.Json; | ||||
|  | ||||
| namespace Core.Cerberos.BFF.Api.Controllers | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Handles all requests for user authentication. | ||||
|     /// </summary> | ||||
|     [ApiVersion("1.0")] | ||||
|     [Route("api/v{version:apiVersion}/[controller]")] | ||||
|     [Consumes("application/json")] | ||||
|     [Produces("application/json")] | ||||
|     [ApiController] | ||||
|     public class UserController(ICerberosServiceClient cerberosServiceClient, ILogger<UserController> logger) : BaseController(logger) | ||||
|     { | ||||
|         /// <summary> | ||||
|         /// Gets all the users. | ||||
|         /// </summary> | ||||
|         [HttpGet("GetAll")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [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> GetAllUsersService(CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 logger.LogInformation($"{nameof(GetAllUsersService)} - Request received - Payload: "); | ||||
|  | ||||
|                 return await Handle(() => cerberosServiceClient.GetAllUsersService(new GetAllUsersRequest { }, cancellationToken)).ConfigureAwait(false); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError($"{nameof(GetAllUsersService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Creates a new user. | ||||
|         /// </summary> | ||||
|         [HttpPost("Create")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [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> CreateUserService(CreateUserRequest newUser, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 logger.LogInformation($"{nameof(CreateUserService)} - Request received - Payload: {JsonSerializer.Serialize(newUser)}"); | ||||
|  | ||||
|                 if (newUser == null) return BadRequest("Invalid user object"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(newUser.Email)) return BadRequest("Invalid user email"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(newUser.Name)) return BadRequest("Invalid user name"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(newUser.LastName)) return BadRequest("Invalid user lastname"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(newUser.RoleId)) return BadRequest("Invalid role id"); | ||||
|  | ||||
|                 if (!newUser.Companies.Any()) return BadRequest("The user must contain at least one company"); | ||||
|  | ||||
|                 return await Handle(() => cerberosServiceClient.CreateUserService(newUser, cancellationToken)).ConfigureAwait(false); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError($"{nameof(CreateUserService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(newUser)}"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets the user by identifier. | ||||
|         /// </summary> | ||||
|         [HttpPost("GetById")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [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> GetUserByIdService(GetUserRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 logger.LogInformation($"{nameof(GetUserByIdService)} - Request received - Payload: {JsonSerializer.Serialize(request)}"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(request.Id)) return BadRequest("Invalid user identifier"); | ||||
|  | ||||
|                 return await Handle(() => cerberosServiceClient.GetUserByIdService(request, cancellationToken)).ConfigureAwait(false); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError($"{nameof(GetUserByIdService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets the user by email. | ||||
|         /// </summary> | ||||
|         [HttpPost("GetByEmail")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [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> GetUserByEmailService(GetUserByEmailRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 logger.LogInformation($"{nameof(GetUserByEmailService)} - Request received - Payload: {JsonSerializer.Serialize(request)}"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(request.Email)) return BadRequest("Invalid user email"); | ||||
|  | ||||
|                 return await Handle(() => cerberosServiceClient.GetUserByEmailService(request, cancellationToken)).ConfigureAwait(false); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError($"{nameof(GetUserByIdService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Updates a full user by identifier. | ||||
|         /// </summary> | ||||
|         [HttpPut("Update")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [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> UpdateUserService(UpdateUserRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 logger.LogInformation($"{nameof(UpdateUserService)} - Request received - Payload: {JsonSerializer.Serialize(request)}"); | ||||
|  | ||||
|                 if (request == null) return BadRequest("Invalid user object"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(request.Email)) return BadRequest("Invalid user email"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(request.Name)) return BadRequest("Invalid user name"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(request.LastName)) return BadRequest("Invalid user lastname"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(request.RoleId)) return BadRequest("Invalid role id"); | ||||
|  | ||||
|                 if (!request.Companies.Any()) return BadRequest("The user must contain at least one company"); | ||||
|  | ||||
|                 return await Handle(() => cerberosServiceClient.UpdateUserService(request, cancellationToken)).ConfigureAwait(false); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError($"{nameof(UpdateUserService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Logs in the user. | ||||
|         /// </summary> | ||||
|         [HttpPatch("LoginUser")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [Authorize(AuthenticationSchemes = $"{Schemes.AzureScheme}, {Schemes.HeathScheme}")] | ||||
|         public async Task<IActionResult> LoginUserService([FromBody] LoginUserRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 logger.LogInformation($"{nameof(LoginUserService)} - Request received - Payload: {JsonSerializer.Serialize(request)}"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(request.Email)) return BadRequest("Invalid user email"); | ||||
|  | ||||
|                 return await Handle(() => cerberosServiceClient.LoginUserService(request, cancellationToken)).ConfigureAwait(false); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError($"{nameof(LoginUserService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Logs out the user. | ||||
|         /// </summary> | ||||
|         [HttpPatch("LogoutUser")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [Authorize(AuthenticationSchemes = $"{Schemes.AzureScheme}, {Schemes.HeathScheme}")] | ||||
|         public async Task<IActionResult> LogoutUserService([FromBody] LogoutUserRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 logger.LogInformation($"{nameof(LogoutUserService)} - Request received - Payload: {JsonSerializer.Serialize(request)}"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(request.Email)) return BadRequest("Invalid user email"); | ||||
|  | ||||
|                 return await Handle(() => cerberosServiceClient.LogoutUserService(request, cancellationToken)).ConfigureAwait(false); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError($"{nameof(LogoutUserService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <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> ChangeUserStatusService([FromBody] ChangeUserStatusRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 logger.LogInformation($"{nameof(ChangeUserStatusService)} - Request received - Payload: {JsonSerializer.Serialize(request)}"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(request.Id)) { return BadRequest("Invalid user identifier"); } | ||||
|  | ||||
|                 return await Handle(() => cerberosServiceClient.ChangeUserStatusService(request, cancellationToken)).ConfigureAwait(false); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError($"{nameof(ChangeUserStatusService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <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> AddCompanyToUserService([FromBody] AddCompanyToUserRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 logger.LogInformation($"{nameof(AddCompanyToUserService)} - Request received - Payload: {JsonSerializer.Serialize(request)}"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(request.UserId)) { return BadRequest("Invalid user identifier"); } | ||||
|                 if (string.IsNullOrEmpty(request.CompanyId)) { return BadRequest("Invalid company identifier"); } | ||||
|  | ||||
|                 return await Handle(() => cerberosServiceClient.AddCompanyToUserService(request, cancellationToken)).ConfigureAwait(false); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError($"{nameof(AddCompanyToUserService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <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> RemoveCompanyFromUserService([FromBody] RemoveCompanyFromUserRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 logger.LogInformation($"{nameof(RemoveCompanyFromUserService)} - Request received - Payload: {JsonSerializer.Serialize(request)}"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(request.UserId)) { return BadRequest("Invalid user identifier"); } | ||||
|                 if (string.IsNullOrEmpty(request.CompanyId)) { return BadRequest("Invalid company identifier"); } | ||||
|  | ||||
|                 return await Handle(() => cerberosServiceClient.RemoveCompanyFromUserService(request, cancellationToken)).ConfigureAwait(false); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError($"{nameof(RemoveCompanyFromUserService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Adds a project to the user's list of companies. | ||||
|         /// </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> AddProjectToUserService([FromBody] AddProjectToUserRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 logger.LogInformation($"{nameof(AddProjectToUserService)} - Request received - Payload: {JsonSerializer.Serialize(request)}"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(request.UserId)) { return BadRequest("Invalid user identifier"); } | ||||
|                 if (string.IsNullOrEmpty(request.ProjectId)) { return BadRequest("Invalid project identifier"); } | ||||
|  | ||||
|                 return await Handle(() => cerberosServiceClient.AddProjectToUserService(request, cancellationToken)).ConfigureAwait(false); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError($"{nameof(AddProjectToUserService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Removes a project from the user's list of companies. | ||||
|         /// </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> RemoveProjectFromUserService([FromBody] RemoveProjectFromUserRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 logger.LogInformation($"{nameof(RemoveProjectFromUserService)} - Request received - Payload: {JsonSerializer.Serialize(request)}"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(request.UserId)) { return BadRequest("Invalid user identifier"); } | ||||
|                 if (string.IsNullOrEmpty(request.ProjectId)) { return BadRequest("Invalid project identifier"); } | ||||
|  | ||||
|                 return await Handle(() => cerberosServiceClient.RemoveProjectFromUserService(request, cancellationToken)).ConfigureAwait(false); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError($"{nameof(RemoveProjectFromUserService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets the user by email. | ||||
|         /// </summary> | ||||
|         [HttpPost("ValidateExistence")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [AllowAnonymous] | ||||
|         public async Task<IActionResult> ValidateUserExistenceService(ValidateUserExistenceRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 logger.LogInformation($"{nameof(ValidateUserExistenceService)} - Request received - Payload: {JsonSerializer.Serialize(request)}"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(request.Email)) return BadRequest("Invalid user email"); | ||||
|  | ||||
|                 return await Handle(() => cerberosServiceClient.ValidateUserExistenceService(request, cancellationToken)).ConfigureAwait(false); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError($"{nameof(GetUserByIdService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Sergio Matias Urquin
					Sergio Matias Urquin