Compare commits
	
		
			50 Commits
		
	
	
		
			feature/im
			...
			a7aad12742
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| a7aad12742 | |||
| 8c3f8f6402 | |||
| 739e9e9c85 | |||
| 927dedb357 | |||
| 8b2fa45fda | |||
| 9634b3f385 | |||
| f342ccdaff | |||
| 7769bf9e67 | |||
|   | 7e0fbc3b31 | ||
| 1c2272c6f3 | |||
| 2bab87fe8d | |||
| cd613cb5b8 | |||
| 39b415065a | |||
|   | 75962160af | ||
| 0f67d57bed | |||
| b3dec4a601 | |||
| 63173eac5a | |||
| d36e24cfbf | |||
| a2a2b6ef8d | |||
| 32131d032b | |||
| 35a0a01221 | |||
| 24a5fd28fb | |||
| 827e5ec270 | |||
| fc8d385a13 | |||
| e456913233 | |||
| 0eadd6e217 | |||
| 7c92a7e791 | |||
| 570e74a199 | |||
| 9590a03cee | |||
|   | 82166f5042 | ||
|   | a14cec8fb1 | ||
| 5922a53b93 | |||
| 13774093b4 | |||
| 7cd08411b9 | |||
| 1d52ee424d | |||
| 4a26ecc83a | |||
| c85897fd1a | |||
| 3511043209 | |||
|   | 99964d14b8 | ||
| 1ae0b600ae | |||
|   | 6cb0aea1a0 | ||
|   | 8207048c25 | ||
|   | f5b5f7d0f0 | ||
| ffc1afa8c9 | |||
|   | 1c38008e97 | ||
| c18c85959c | |||
|   | c3e1cfbf8d | ||
| 41da6d76f8 | |||
|   | a36fd0e480 | ||
|   | 24efe5612c | 
							
								
								
									
										17
									
								
								.dockerignore
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								.dockerignore
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,17 @@ | |||||||
|  | **/bin/ | ||||||
|  | **/obj/ | ||||||
|  | **/.vs/ | ||||||
|  | **/.idea/ | ||||||
|  | **/.vscode/ | ||||||
|  | **/*.user | ||||||
|  | **/*.suo | ||||||
|  | **/*.swp | ||||||
|  | **/*.csproj.user | ||||||
|  | **/*.log | ||||||
|  | **/Properties/launchSettings.json | ||||||
|  | **/appsettings.Local.json | ||||||
|  | **/appsettings.*.Development.json | ||||||
|  | .git/ | ||||||
|  | .gitignore | ||||||
|  | Dockerfile | ||||||
|  | docker-compose*.yml | ||||||
							
								
								
									
										6
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -350,6 +350,6 @@ ASALocalRun/ | |||||||
| # Local History for Visual Studio | # Local History for Visual Studio | ||||||
| .localhistory/ | .localhistory/ | ||||||
|  |  | ||||||
| /Core.Cerberos.DAL.API/CerberosDALSettings.development.json | /Core.Thalos.DAL.API/ThalosDALSettings.development.json | ||||||
| /Core.Cerberos.DAL.API/cerberosprivkey.pem | /Core.Thalos.DAL.API/thalosprivkey.pem | ||||||
| /Core.Cerberos.DAL.API/cerberospubkey.pem | /Core.Thalos.DAL.API/thalospubkey.pem | ||||||
| @@ -1,220 +0,0 @@ | |||||||
| // *********************************************************************** |  | ||||||
| // <copyright file="ModuleController.cs"> |  | ||||||
| //     AgileWebs |  | ||||||
| // </copyright> |  | ||||||
| // *********************************************************************** |  | ||||||
|  |  | ||||||
| using Asp.Versioning; |  | ||||||
| using Core.Cerberos.Adapters; |  | ||||||
| using Core.Cerberos.Adapters.Attributes; |  | ||||||
| using Core.Cerberos.Adapters.Common.Constants; |  | ||||||
| using Core.Cerberos.Adapters.Common.Enums; |  | ||||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; |  | ||||||
| using Core.Cerberos.Provider.Contracts; |  | ||||||
| using Microsoft.AspNetCore.Authorization; |  | ||||||
| using Microsoft.AspNetCore.Mvc; |  | ||||||
|  |  | ||||||
| namespace LSA.Core.Kerberos.API.Controllers |  | ||||||
| { |  | ||||||
|     /// <summary> |  | ||||||
|     /// Handles all requests for module authentication. |  | ||||||
|     /// </summary> |  | ||||||
|     [ApiVersion(MimeTypes.ApplicationVersion)] |  | ||||||
|     [Route("api/v{api-version:apiVersion}/[controller]")] |  | ||||||
|     [Produces(MimeTypes.ApplicationJson)] |  | ||||||
|     [Consumes(MimeTypes.ApplicationJson)] |  | ||||||
|     [ApiController] |  | ||||||
|     public class ModuleController(IModuleService service, ILogger<ModuleController> logger) : ControllerBase |  | ||||||
|     { |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets all the modules. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <returns>The <see cref="IEnumerable{ModuleAdapter}"/> found entities.</returns> |  | ||||||
|         /// <response code="200">The roles found.</response> |  | ||||||
|         /// <response code="404">The roles not found error.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpGet] |  | ||||||
|         [Consumes(MimeTypes.ApplicationJson)] |  | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |  | ||||||
|         [ProducesResponseType(typeof(IEnumerable<ModuleAdapter>), StatusCodes.Status200OK)] |  | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |  | ||||||
|         [Permission("ModuleManagement.Read, RoleManagement.Read")] |  | ||||||
|         public async Task<IActionResult> GetAllModulesAsync() |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var result = await service.GetAllModulesService(); |  | ||||||
|  |  | ||||||
|                 return Ok(result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in GetAllModulesAsync"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets all the modules by module identifiers. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="modules">The list of module identifiers.</param> |  | ||||||
|         /// <returns>The <see cref="IEnumerable{ModuleAdapter}"/> found entities.</returns> |  | ||||||
|         /// <response code="200">The modules found.</response> |  | ||||||
|         /// <response code="404">The modules not found error.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpPost] |  | ||||||
|         [Route(Routes.GetModuleList)] |  | ||||||
|         [Consumes(MimeTypes.ApplicationJson)] |  | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |  | ||||||
|         [ProducesResponseType(typeof(IEnumerable<ModuleAdapter>), StatusCodes.Status200OK)] |  | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |  | ||||||
|         [Permission("ModuleManagement.Read")] |  | ||||||
|         public async Task<IActionResult> GetAllModulesByList([FromBody] string[] modules) |  | ||||||
|         { |  | ||||||
|             if (modules == null || !modules.Any()) |  | ||||||
|             { |  | ||||||
|                 return BadRequest("Module identifiers are required."); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var result = await service.GetAllModulesByListService(modules); |  | ||||||
|  |  | ||||||
|                 if (result == null || !result.Any()) |  | ||||||
|                 { |  | ||||||
|                     return NotFound("No modules found for the given identifiers."); |  | ||||||
|                 } |  | ||||||
|  |  | ||||||
|                 return Ok(result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in GetAllModulesByList"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets the module by identifier. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="id">The module identifier.</param> |  | ||||||
|         /// <returns>The <see cref="ModuleAdapter"/> found entity.</returns> |  | ||||||
|         /// <response code="200">The module found.</response> |  | ||||||
|         /// <response code="404">The module not found error.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpGet] |  | ||||||
|         [Route(Routes.Id)] |  | ||||||
|         [Consumes(MimeTypes.ApplicationJson)] |  | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |  | ||||||
|         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)] |  | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |  | ||||||
|         [Permission("ModuleManagement.Read")] |  | ||||||
|         public async Task<IActionResult> GetModuleByIdAsync([FromRoute] string id) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var result = await service.GetModuleByIdService(id); |  | ||||||
|  |  | ||||||
|                 if (result is null) return NotFound($"module with id: '{id}' not found"); |  | ||||||
|  |  | ||||||
|                 return Ok(result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in GetModuleByIdAsync"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Creates a new module. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="newModule">The module to be added.</param> |  | ||||||
|         /// <returns>The <see cref="ModuleAdapter"/> created entity.</returns> |  | ||||||
|         /// <response code="201">The module created.</response> |  | ||||||
|         /// <response code="422">The module could not be created.</response> |  | ||||||
|         /// <response code="500">The service internal e|ror.</response> |  | ||||||
|         [HttpPost] |  | ||||||
|         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status201Created)] |  | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |  | ||||||
|         [Permission("ModuleManagement.Write")] |  | ||||||
|         public async Task<IActionResult> CreateModuleAsync([FromBody] ModuleRequest newModule) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var result = await service.CreateModuleService(newModule).ConfigureAwait(false); |  | ||||||
|                 return Created("CreatedWithIdService", result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in CreateModuleAsync"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Updates a full module by identifier. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="entity">The module to update.</param> |  | ||||||
|         /// <param name="id">The module identifier.</param> |  | ||||||
|         /// <returns>The <see cref="ModuleAdapter"/> updated entity.</returns> |  | ||||||
|         /// <response code="200">The module updated.</response> |  | ||||||
|         /// <response code="404">The module not found.</response> |  | ||||||
|         /// <response code="422">The module could not be updated.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpPut] |  | ||||||
|         [Route(Routes.Id)] |  | ||||||
|         [Consumes(MimeTypes.ApplicationJson)] |  | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |  | ||||||
|         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)] |  | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |  | ||||||
|         [Permission("ModuleManagement.Write")] |  | ||||||
|         public async Task<IActionResult> UpdateModuleAsync(ModuleAdapter entity, string id) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var result = await service.UpdateModuleService(entity, id); |  | ||||||
|  |  | ||||||
|                 return Ok(result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in UpdateModuleAsync"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Changes the status of the module. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="id">The module identifier.</param> |  | ||||||
|         /// <param name="newStatus">The new status of the module.</param> |  | ||||||
|         /// <returns>The <see cref="ModuleAdapter"/> updated entity.</returns> |  | ||||||
|         /// <response code="200">The module updates.</response> |  | ||||||
|         /// <response code="404">The module not found.</response> |  | ||||||
|         /// <response code="422">The module could not be deleted.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpPatch] |  | ||||||
|         [Route(Routes.ChangeStatus)] |  | ||||||
|         [Consumes(MimeTypes.ApplicationJson)] |  | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |  | ||||||
|         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)] |  | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |  | ||||||
|         [Permission("ModuleManagement.Write")] |  | ||||||
|         public async Task<IActionResult> ChangeModuleStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var result = await service.ChangeModuleStatusService(id, newStatus); |  | ||||||
|  |  | ||||||
|                 return Ok(result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in ChangeModuleStatus"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,231 +0,0 @@ | |||||||
| // *********************************************************************** |  | ||||||
| // <copyright file="RoleController.cs"> |  | ||||||
| //     AgileWebs |  | ||||||
| // </copyright> |  | ||||||
| // *********************************************************************** |  | ||||||
| using Asp.Versioning; |  | ||||||
| using Core.Cerberos.Adapters; |  | ||||||
| using Core.Cerberos.Adapters.Attributes; |  | ||||||
| using Core.Cerberos.Adapters.Common.Constants; |  | ||||||
| using Core.Cerberos.Adapters.Common.Enums; |  | ||||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; |  | ||||||
| using Core.Cerberos.Provider.Contracts; |  | ||||||
| using Microsoft.AspNetCore.Authorization; |  | ||||||
| using Microsoft.AspNetCore.Mvc; |  | ||||||
|  |  | ||||||
| namespace LSA.Core.Kerberos.API.Controllers |  | ||||||
| { |  | ||||||
|     /// <summary> |  | ||||||
|     /// Handles all requests for role authentication. |  | ||||||
|     /// </summary> |  | ||||||
|     [ApiVersion(MimeTypes.ApplicationVersion)] |  | ||||||
|     [Route("api/v{api-version:apiVersion}/[controller]")] |  | ||||||
|     [Produces(MimeTypes.ApplicationJson)] |  | ||||||
|     [Consumes(MimeTypes.ApplicationJson)] |  | ||||||
|     [ApiController] |  | ||||||
|     public class RoleController(IRoleService service, ILogger<RoleController> logger) : ControllerBase |  | ||||||
|     { |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets all the roles. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <returns>The rol found entities.</returns> |  | ||||||
|         /// <response code="200">The roles found.</response> |  | ||||||
|         /// <response code="404">The roles not found error.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpGet] |  | ||||||
|         [ProducesResponseType(typeof(IEnumerable<RoleAdapter>), StatusCodes.Status200OK)] |  | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |  | ||||||
|         [Permission("RoleManagement.Read")] |  | ||||||
|         public async Task<IActionResult> GetAllRolesAsync() |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var result = await service.GetAllRolesService(); |  | ||||||
|  |  | ||||||
|                 return Ok(result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in GetAllRolesAsync"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets the role by identifier. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="id">The role identifier.</param> |  | ||||||
|         /// <returns>The <see cref="RoleAdapter"/> found entity.</returns> |  | ||||||
|         /// <response code="200">The role found.</response> |  | ||||||
|         /// <response code="404">The role not found error.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpGet] |  | ||||||
|         [Route(Routes.Id)] |  | ||||||
|         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] |  | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |  | ||||||
|         [Permission("RoleManagement.Read")] |  | ||||||
|         public async Task<IActionResult> GetRoleByIdAsync([FromRoute] string id) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var result = await service.GetRoleByIdService(id); |  | ||||||
|  |  | ||||||
|                 if (result is null) return NotFound($"role with id: '{id}' not found"); |  | ||||||
|  |  | ||||||
|                 return Ok(result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in GetRoleByIdAsync"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Creates a new role. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="newRole">The role to be added.</param> |  | ||||||
|         /// <returns>The <see cref="RoleAdapter"/> created entity.</returns> |  | ||||||
|         /// <response code="201">The role created.</response> |  | ||||||
|         /// <response code="422">The role could not be created.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpPost] |  | ||||||
|         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status201Created)] |  | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |  | ||||||
|         [Permission("RoleManagement.Write")] |  | ||||||
|         public async Task<IActionResult> CreateRoleAsync([FromBody] RoleRequest newRole) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var result = await service.CreateRoleService(newRole).ConfigureAwait(false); |  | ||||||
|  |  | ||||||
|                 return Created("CreatedWithIdService", result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in CreateRoleAsync"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Updates a full role by identifier. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="entity">The role to update.</param> |  | ||||||
|         /// <param name="id">The role identifier.</param> |  | ||||||
|         /// <returns>The <see cref="RoleAdapter"/> updated entity.</returns> |  | ||||||
|         /// <response code="200">The role updated.</response> |  | ||||||
|         /// <response code="404">The role not found.</response> |  | ||||||
|         /// <response code="422">The role could not be updated.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpPut] |  | ||||||
|         [Route(Routes.Id)] |  | ||||||
|         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] |  | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |  | ||||||
|         [Permission("RoleManagement.Write")] |  | ||||||
|         public async Task<IActionResult> UpdateRoleAsync([FromBody] RoleAdapter entity, [FromRoute] string id) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var result = await service.UpdateRoleService(entity, id); |  | ||||||
|  |  | ||||||
|                 return Ok(result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in UpdateRoleAsync"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Changes the status of the role. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="id">The role identifier.</param> |  | ||||||
|         /// <param name="newStatus">The new status of the role.</param> |  | ||||||
|         /// <returns>The <see cref="RoleAdapter"/> updated entity.</returns> |  | ||||||
|         /// <response code="200">The role updates.</response> |  | ||||||
|         /// <response code="404">The role not found.</response> |  | ||||||
|         /// <response code="422">The role could not be deleted.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpPatch] |  | ||||||
|         [Route(Routes.ChangeStatus)] |  | ||||||
|         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] |  | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |  | ||||||
|         [Permission("RoleManagement.Write")] |  | ||||||
|         public async Task<IActionResult> ChangeRoleStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var result = await service.ChangeRoleStatusService(id, newStatus); |  | ||||||
|  |  | ||||||
|                 return Ok(result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in ChangeRoleStatus"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Adds an application to the role's list of applications. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="roleId">The identifier of the role to which the application will be added.</param> |  | ||||||
|         /// <param name="application">The application enum value to add.</param> |  | ||||||
|         /// <returns>A <see cref="Task{RoleAdapter}"/> representing the asynchronous operation, with the updated role object.</returns> |  | ||||||
|         /// <response code="200">The role updates.</response> |  | ||||||
|         /// <response code="404">The role not found.</response> |  | ||||||
|         /// <response code="422">The role could not be deleted.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpPost(Routes.AddApplication)] |  | ||||||
|         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] |  | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |  | ||||||
|         [Permission("RoleManagement.Write")] |  | ||||||
|         public async Task<IActionResult> AddApplicationToRoleAsync([FromRoute] string roleId, |  | ||||||
|                                                                    [FromRoute] ApplicationsEnum application) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var updatedRole = await service.AddApplicationToRoleService(roleId, application); |  | ||||||
|  |  | ||||||
|                 return Ok(updatedRole); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in AddApplicationToRoleAsync"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Removes an application from the role's list of applications. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="roleId">The identifier of the role from which the application will be removed.</param> |  | ||||||
|         /// <param name="application">The application enum value to remove.</param> |  | ||||||
|         /// <returns>A <see cref="Task{RoleAdapter}"/> representing the asynchronous operation, with the updated role object.</returns> |  | ||||||
|         /// <response code="200">The role updates.</response> |  | ||||||
|         /// <response code="404">The role not found.</response> |  | ||||||
|         /// <response code="422">The role could not be deleted.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpDelete(Routes.RemoveApplication)] |  | ||||||
|         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] |  | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |  | ||||||
|         [Permission("RoleManagement.Write")] |  | ||||||
|         public async Task<IActionResult> RemoveApplicationFromRoleAsync([FromRoute] string roleId, |  | ||||||
|                                                                         [FromRoute] ApplicationsEnum application) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var updatedRole = await service.RemoveApplicationFromRoleService(roleId, application); |  | ||||||
|                 return Ok(updatedRole); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in RemoveApplicationFromRoleAsync"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,442 +0,0 @@ | |||||||
| // *********************************************************************** |  | ||||||
| // <copyright file="UserController.cs"> |  | ||||||
| //     AgileWebs |  | ||||||
| // </copyright> |  | ||||||
| // *********************************************************************** |  | ||||||
| using Asp.Versioning; |  | ||||||
| using Core.Blueprint.Storage.Adapters; |  | ||||||
| using Core.Cerberos.Adapters; |  | ||||||
| using Core.Cerberos.Adapters.Attributes; |  | ||||||
| using Core.Cerberos.Adapters.Common.Constants; |  | ||||||
| using Core.Cerberos.Adapters.Common.Enums; |  | ||||||
| using Core.Cerberos.Provider.Contracts; |  | ||||||
| using Microsoft.AspNetCore.Authorization; |  | ||||||
| using Microsoft.AspNetCore.Mvc; |  | ||||||
| using Microsoft.Graph; |  | ||||||
| using UserRequest = Core.Cerberos.Domain.Contexts.Onboarding.Request.UserRequest; |  | ||||||
|  |  | ||||||
| namespace LSA.Core.Kerberos.API.Controllers |  | ||||||
| { |  | ||||||
|     /// <summary> |  | ||||||
|     /// Handles all requests for user authentication. |  | ||||||
|     /// </summary> |  | ||||||
|     [ApiVersion("1.0")] |  | ||||||
|     [Route("api/v{api-version:apiVersion}/[controller]")] |  | ||||||
|     [Produces(MimeTypes.ApplicationJson)] |  | ||||||
|     [Consumes(MimeTypes.ApplicationJson)] |  | ||||||
|     [ApiController] |  | ||||||
|     public class UserController(IUserService service, ILogger<UserController> logger) : ControllerBase |  | ||||||
|     { |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets all the users. |  | ||||||
|         /// </summary>   |  | ||||||
|         /// <returns>The <see cref="IEnumerable{UserAdapter}"/> found entity.</returns> |  | ||||||
|         /// <response code="200">The users found.</response> |  | ||||||
|         /// <response code="404">The users not found error.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpGet] |  | ||||||
|         [ProducesResponseType(typeof(IEnumerable<UserAdapter>), StatusCodes.Status200OK)] |  | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |  | ||||||
|         [Permission("UserManagement.Read")] |  | ||||||
|         public async Task<IActionResult> GetAllUsersService() |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var result = await service.GetAllUsersService(); |  | ||||||
|  |  | ||||||
|                 return Ok(result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in GetAllUsersService"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets the user by identifier. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="id">The user identifier.</param> |  | ||||||
|         /// <returns>The <see cref="UserAdapter"/> found entity.</returns> |  | ||||||
|         /// <response code="200">The user found.</response> |  | ||||||
|         /// <response code="404">The user not found error.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpGet] |  | ||||||
|         [Route(Routes.Id)] |  | ||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] |  | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |  | ||||||
|         [Permission("UserManagement.Read")] |  | ||||||
|         public async Task<IActionResult> GetUserByIdService([FromRoute] string id) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var result = await service.GetUserByIdService(id); |  | ||||||
|  |  | ||||||
|                 if (result is null) return NotFound($"user with id: '{id}' not found"); |  | ||||||
|  |  | ||||||
|                 return Ok(result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in GetUserByIdService"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets the user by email. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="email">The user's email.</param> |  | ||||||
|         /// <returns>The <see cref="UserAdapter"/> found entity.</returns> |  | ||||||
|         /// <response code="200">The user found.</response> |  | ||||||
|         /// <response code="404">The user not found error.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpGet] |  | ||||||
|         [Route(Routes.Email)] |  | ||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] |  | ||||||
|         [Authorize(AuthenticationSchemes = $"{Schemes.HeathScheme}, {Schemes.AzureScheme}")] |  | ||||||
|         public async Task<IActionResult> GetUserByEmail([FromRoute] string email) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var result = await service.GetUserByEmailService(email); |  | ||||||
|  |  | ||||||
|                 if (result is null) return NotFound($"user with email: '{email}' not found"); |  | ||||||
|  |  | ||||||
|                 return Ok(result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in GetUserByIdEmail"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Validates if a user exists on the database. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="email">The user's email.</param> |  | ||||||
|         /// <returns>The <see cref="UserExistenceAdapter"/> found entity.</returns> |  | ||||||
|         /// <response code="200">The user found.</response> |  | ||||||
|         /// <response code="404">The user not found error.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpGet] |  | ||||||
|         [Route("{email}/ValidateExistence")] |  | ||||||
|         [ProducesResponseType(typeof(UserExistenceAdapter), StatusCodes.Status200OK)] |  | ||||||
|         [AllowAnonymous] |  | ||||||
|         public async Task<IActionResult> ValidateUserExistence([FromRoute] string email) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var result = await service.ValidateUserExistenceService(email); |  | ||||||
|  |  | ||||||
|                 var existence = new UserExistenceAdapter |  | ||||||
|                 { |  | ||||||
|                     Existence = (result is not null) ? true : false |  | ||||||
|                 }; |  | ||||||
|  |  | ||||||
|                 return Ok(existence); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in ValidateUserExistance"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Creates a new user. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="newUser">The user to be added.</param> |  | ||||||
|         /// <param name="sendInvitation">Sends an invitation in case of third party access.</param> |  | ||||||
|         /// <returns>The <see cref="UserAdapter"/> created entity.</returns> |  | ||||||
|         /// <response code="201">The user created.</response> |  | ||||||
|         /// <response code="422">The user could not be created.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpPost(Routes.Register)] |  | ||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status201Created)] |  | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |  | ||||||
|         [Permission("UserManagement.Write")] |  | ||||||
|         public async Task<IActionResult> CreateUserAsync([FromBody] UserRequest newUser, [FromRoute] bool sendInvitation) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var user = await service.GetUserByEmailService(newUser.Email).ConfigureAwait(false); |  | ||||||
|  |  | ||||||
|                 if (user is not null) |  | ||||||
|                     return UnprocessableEntity("There is a user with the same email registered in the database"); |  | ||||||
|  |  | ||||||
|                 var result = await service.CreateUserService(newUser).ConfigureAwait(false); |  | ||||||
|  |  | ||||||
|                 return Created("CreatedWithIdService", result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in CreateUserAsync"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Updates a full user by identifier. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="entity">The user to update.</param> |  | ||||||
|         /// <param name="id">The user identifier.</param> |  | ||||||
|         /// <returns>The <see cref="UserAdapter"/> updated entity.</returns> |  | ||||||
|         /// <response code="200">The user updated.</response> |  | ||||||
|         /// <response code="404">The user not found.</response> |  | ||||||
|         /// <response code="422">The user could not be updated.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpPut] |  | ||||||
|         [Route(Routes.Id)] |  | ||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] |  | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |  | ||||||
|         [Permission("UserManagement.Write")] |  | ||||||
|         public async Task<IActionResult> UpdateUserAsync([FromBody] UserAdapter entity, [FromRoute] string id) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var result = await service.UpdateUserService(entity, id); |  | ||||||
|  |  | ||||||
|                 return Ok(result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in UpdateUserAsync"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Logs in the user. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="email">The User's email.</param> |  | ||||||
|         /// <returns>A <see cref="UserAdapter"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         /// <response code="200">The User found.</response> |  | ||||||
|         /// <response code="404">The User not found.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpPatch(Routes.LogIn)] |  | ||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] |  | ||||||
|         [Authorize(AuthenticationSchemes = $"{Schemes.HeathScheme}, {Schemes.AzureScheme}")] |  | ||||||
|         public async Task<IActionResult> LoginUserAsync([FromRoute] string email) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var result = await service.LogInUserService(email).ConfigureAwait(false); |  | ||||||
|  |  | ||||||
|                 if (result is null) |  | ||||||
|                     return new NotFoundObjectResult($"The user with email: '{email}' was not found"); |  | ||||||
|  |  | ||||||
|                 return Ok(result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in LogInUserService"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Logs out the user. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="email">The User's email.</param> |  | ||||||
|         /// <returns>A <see cref="UserAdapter"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         /// <response code="200">The User updated.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpPatch(Routes.LogOut)] |  | ||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] |  | ||||||
|         [Authorize(AuthenticationSchemes = $"{Schemes.HeathScheme}, {Schemes.AzureScheme}")] |  | ||||||
|         public async Task<IActionResult> LogOutUserSessionAsync([FromRoute] string email) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var result = await service.LogOutUserSessionService(email).ConfigureAwait(false); |  | ||||||
|  |  | ||||||
|                 return Ok(result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in LogOutUserSessionService"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Changes the status of the user. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="id">The user identifier.</param> |  | ||||||
|         /// <param name="newStatus">The new status of the user.</param> |  | ||||||
|         /// <returns>The <see cref="UserAdapter"/> updated entity.</returns> |  | ||||||
|         /// <response code="200">The user updates.</response> |  | ||||||
|         /// <response code="404">The user not found.</response> |  | ||||||
|         /// <response code="422">The user could not be deleted.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpPatch] |  | ||||||
|         [Route(Routes.ChangeStatus)] |  | ||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] |  | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |  | ||||||
|         [Permission("UserManagement.Write")] |  | ||||||
|         public async Task<IActionResult> ChangeUserStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var result = await service.ChangeUserStatusService(id, newStatus); |  | ||||||
|  |  | ||||||
|                 return Ok(result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in ChangeUserStatus"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Adds a company to the user's list of companies. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="userId">The user identifier.</param> |  | ||||||
|         /// <param name="companyId">The company identifier to add.</param> |  | ||||||
|         /// <returns>The updated <see cref="UserAdapter"/> entity.</returns> |  | ||||||
|         /// <response code="200">The user with the updated companies.</response> |  | ||||||
|         /// <response code="404">The user or company not found.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpPost] |  | ||||||
|         [Route(Routes.AddCompany)] |  | ||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] |  | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |  | ||||||
|         [Permission("UserManagement.Write")] |  | ||||||
|         public async Task<IActionResult> AddCompanyToUserAsync([FromRoute] string userId, [FromRoute] string companyId) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var result = await service.AddCompanyToUserService(userId, companyId); |  | ||||||
|  |  | ||||||
|                 return Ok(result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in AddCompanyToUserAsync"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Removes a company from the user's list of companies. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="userId">The user identifier.</param> |  | ||||||
|         /// <param name="companyId">The company identifier to remove.</param> |  | ||||||
|         /// <returns>The updated <see cref="UserAdapter"/> entity.</returns> |  | ||||||
|         /// <response code="200">The user with the updated companies.</response> |  | ||||||
|         /// <response code="404">The user or company not found.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpDelete] |  | ||||||
|         [Route(Routes.RemoveCompany)] |  | ||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] |  | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |  | ||||||
|         [Permission("UserManagement.Write")] |  | ||||||
|         public async Task<IActionResult> RemoveCompanyFromUserAsync([FromRoute] string userId, [FromRoute] string companyId) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var result = await service.RemoveCompanyFromUserService(userId, companyId); |  | ||||||
|  |  | ||||||
|                 return Ok(result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in RemoveCompanyFromUserAsync"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Adds a project to the user's list of projects. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="userId">The user identifier.</param> |  | ||||||
|         /// <param name="projectId">The project identifier to add.</param> |  | ||||||
|         /// <returns>The updated <see cref="UserAdapter"/> entity.</returns> |  | ||||||
|         /// <response code="200">The user with the updated projects.</response> |  | ||||||
|         /// <response code="404">The user or project not found.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpPost] |  | ||||||
|         [Route(Routes.AddProject)] |  | ||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] |  | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |  | ||||||
|         [Permission("UserManagement.Write")] |  | ||||||
|         public async Task<IActionResult> AddProjectToUserAsync([FromRoute] string userId, [FromRoute] string projectId) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var result = await service.AddProjectToUserService(userId, projectId); |  | ||||||
|  |  | ||||||
|                 return Ok(result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in AddProjectToUserAsync"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Removes a project from the user's list of projects. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="userId">The user identifier.</param> |  | ||||||
|         /// <param name="projectId">The project identifier to remove.</param> |  | ||||||
|         /// <returns>The updated <see cref="UserAdapter"/> entity.</returns> |  | ||||||
|         /// <response code="200">The user with the updated projects.</response> |  | ||||||
|         /// <response code="404">The user or project not found.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpDelete] |  | ||||||
|         [Route(Routes.RemoveProject)] |  | ||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] |  | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |  | ||||||
|         [Permission("UserManagement.Write")] |  | ||||||
|         public async Task<IActionResult> RemoveProjectFromUserAsync([FromRoute] string userId, [FromRoute] string projectId) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var result = await service.RemoveProjectFromUserService(userId, projectId); |  | ||||||
|  |  | ||||||
|                 return Ok(result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in RemoveProjectFromUserAsync"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets a token for the user, including roles, permissions, and modules. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="email">The user's email.</param> |  | ||||||
|         /// <returns>The token adapter with user details, role, permissions, and modules.</returns> |  | ||||||
|         /// <response code="200">The token adapter with user details.</response> |  | ||||||
|         /// <response code="404">The user not found.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpGet] |  | ||||||
|         [Route("{email}/GetTokenAdapter")] |  | ||||||
|         [ProducesResponseType(typeof(TokenAdapter), StatusCodes.Status200OK)] |  | ||||||
|         [Authorize(AuthenticationSchemes = $"{Schemes.HeathScheme}, {Schemes.AzureScheme}")] |  | ||||||
|         public async Task<IActionResult> GetTokenAdapter([FromRoute] string email) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var tokenAdapter = await service.GetTokenAdapter(email); |  | ||||||
|  |  | ||||||
|                 if (tokenAdapter == null) return NotFound($"User with email: {email} not found"); |  | ||||||
|  |  | ||||||
|                 return Ok(tokenAdapter); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in GetTokenAdapter"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,6 +0,0 @@ | |||||||
| @Core.Cerberos.DAL.API_HostAddress = http://localhost:5211 |  | ||||||
|  |  | ||||||
| GET {{Core.Cerberos.DAL.API_HostAddress}}/weatherforecast/ |  | ||||||
| Accept: application/json |  | ||||||
|  |  | ||||||
| ### |  | ||||||
| @@ -1,90 +0,0 @@ | |||||||
| using Core.Blueprint.Logging.Configuration; |  | ||||||
| using Core.Cerberos.Adapters.Extensions; |  | ||||||
| using Core.Cerberos.Adapters.Helpers; |  | ||||||
| using Core.Cerberos.Provider; |  | ||||||
| using Microsoft.AspNetCore.RateLimiting; |  | ||||||
| using Microsoft.AspNetCore.ResponseCompression; |  | ||||||
| using System.IO.Compression; |  | ||||||
| using System.Reflection; |  | ||||||
| using System.Threading.RateLimiting; |  | ||||||
|  |  | ||||||
| var builder = WebApplication.CreateBuilder(args); |  | ||||||
|  |  | ||||||
| var authSettings = AuthHelper.GetAuthSettings(builder, "cerberos_dal"); |  | ||||||
|  |  | ||||||
| builder.Services.ConfigureAuthentication(builder.Configuration, authSettings); |  | ||||||
|  |  | ||||||
| builder.Configuration.AddUserSecrets(Assembly.GetExecutingAssembly()).AddEnvironmentVariables(); |  | ||||||
|  |  | ||||||
| // Add services to the container. |  | ||||||
|  |  | ||||||
| builder.Services.AddControllers(); |  | ||||||
| // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle |  | ||||||
| builder.Services.AddEndpointsApiExplorer(); |  | ||||||
|  |  | ||||||
| builder.Services.AddLogs(builder); |  | ||||||
|  |  | ||||||
| builder.Services.AddCors(options => |  | ||||||
| { |  | ||||||
|     options.AddPolicy("AllowAll", policyBuilder => |  | ||||||
|         policyBuilder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod()); |  | ||||||
| }); |  | ||||||
| builder.Services.AddMvc().AddJsonOptions(options => |  | ||||||
| { |  | ||||||
|     options.JsonSerializerOptions.WriteIndented = true; |  | ||||||
|     options.JsonSerializerOptions.MaxDepth = 20; |  | ||||||
|     options.JsonSerializerOptions.NumberHandling = System.Text.Json.Serialization.JsonNumberHandling.AllowNamedFloatingPointLiterals; |  | ||||||
| }); |  | ||||||
| builder.Services.Configure<BrotliCompressionProviderOptions>(options => |  | ||||||
| { |  | ||||||
|     options.Level = CompressionLevel.Fastest; |  | ||||||
| }); |  | ||||||
| builder.Services.Configure<GzipCompressionProviderOptions>(options => |  | ||||||
| { |  | ||||||
|     options.Level = CompressionLevel.SmallestSize; |  | ||||||
| }); |  | ||||||
| builder.Services.AddResponseCompression(options => |  | ||||||
| { |  | ||||||
|     options.EnableForHttps = true; |  | ||||||
|     options.Providers.Add<BrotliCompressionProvider>(); |  | ||||||
|     options.Providers.Add<GzipCompressionProvider>(); |  | ||||||
| }); |  | ||||||
|  |  | ||||||
| builder.Services.AddRateLimiter(_ => _ |  | ||||||
|     .AddFixedWindowLimiter("fixed", options => |  | ||||||
|     { |  | ||||||
|         options.PermitLimit = 5; |  | ||||||
|         options.Window = TimeSpan.FromSeconds(10); |  | ||||||
|         options.QueueProcessingOrder = QueueProcessingOrder.OldestFirst; |  | ||||||
|         options.QueueLimit = 2; |  | ||||||
|     }) |  | ||||||
|     .AddSlidingWindowLimiter("sliding", options => |  | ||||||
|     { |  | ||||||
|         options.PermitLimit = 5; |  | ||||||
|         options.Window = TimeSpan.FromSeconds(10); |  | ||||||
|         options.SegmentsPerWindow = 5; |  | ||||||
|         options.QueueProcessingOrder = QueueProcessingOrder.OldestFirst; |  | ||||||
|         options.QueueLimit = 2; |  | ||||||
|     })); |  | ||||||
|  |  | ||||||
| builder.Services.AddResponseCaching(); |  | ||||||
| builder.Services.AddControllers(); |  | ||||||
| builder.Services.AddEndpointsApiExplorer(); |  | ||||||
| builder.Services.AddSwagger(builder.Configuration, "Core.Cerberos.DAL.API.xml", authSettings); |  | ||||||
| builder.Services.AddVersioning(builder.Configuration); |  | ||||||
| builder.Services.AddLogging(); |  | ||||||
| builder.Services.AddProblemDetails(); |  | ||||||
|  |  | ||||||
|  |  | ||||||
| builder.Services.AddDALLayer(builder.Configuration); |  | ||||||
|  |  | ||||||
| var app = builder.Build(); |  | ||||||
|  |  | ||||||
| app.UseSwaggerUI(builder.Configuration, authSettings); |  | ||||||
| app.ConfigureSwagger(builder.Configuration); |  | ||||||
| app.UseLogging(builder.Configuration); |  | ||||||
| app.UseHttpsRedirection(); |  | ||||||
| app.UseAuthorization(); |  | ||||||
| app.MapControllers(); |  | ||||||
|  |  | ||||||
| app.Run(); |  | ||||||
| @@ -1,12 +0,0 @@ | |||||||
| { |  | ||||||
|   "Logging": { |  | ||||||
|     "LogLevel": { |  | ||||||
|       "Default": "Information", |  | ||||||
|       "Microsoft.AspNetCore": "Warning" |  | ||||||
|     } |  | ||||||
|   }, |  | ||||||
|   "AllowedHosts": "*", |  | ||||||
|   "Endpoints": { |  | ||||||
|     "AppConfigurationURI": "https://sandbox-hci-usc-appcg.azconfig.io" |  | ||||||
|   } |  | ||||||
| } |  | ||||||
| @@ -1,42 +0,0 @@ | |||||||
| // *********************************************************************** |  | ||||||
| // <copyright file="ModuleMapper.cs"> |  | ||||||
| //    HEATH |  | ||||||
| // </copyright> |  | ||||||
| // *********************************************************************** |  | ||||||
| using Core.Cerberos.Adapters; |  | ||||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; |  | ||||||
| using Microsoft.AspNetCore.Http; |  | ||||||
| using MongoDB.Bson; |  | ||||||
| using System.Security.Claims; |  | ||||||
| namespace Core.Cerberos.Domain.Contexts.Onboarding.Mappers |  | ||||||
| { |  | ||||||
|     /// <summary> |  | ||||||
|     /// Handles mappings between |  | ||||||
|     /// <see cref="ModuleRequest"/>, |  | ||||||
|     /// and <see cref="ModuleAdapter"/> |  | ||||||
|     /// </summary> |  | ||||||
|     public static class ModuleMapper |  | ||||||
|     { |  | ||||||
|         /// <summary> |  | ||||||
|         /// Maps the permissionRequest to ModuleAdapter. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="newModule">The Module to be mapped.</param> |  | ||||||
|         /// <returns>A <see cref="ModuleAdapter"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public static ModuleAdapter ToAdapter(this ModuleRequest newModule, IHttpContextAccessor httpContextAccessor) |  | ||||||
|         { |  | ||||||
|             return new ModuleAdapter |  | ||||||
|             { |  | ||||||
|                 Id = ObjectId.GenerateNewId().ToString(), |  | ||||||
|                 Name = newModule.Name, |  | ||||||
|                 Description = newModule.Description, |  | ||||||
|                 Icon = newModule.Icon, |  | ||||||
|                 Route = newModule.Route, |  | ||||||
|                 Order = newModule.Order, |  | ||||||
|                 Application = newModule.Application, |  | ||||||
|                 CreatedAt = DateTime.UtcNow, |  | ||||||
|                 CreatedBy = httpContextAccessor.HttpContext?.User?.FindFirst(ClaimTypes.Email)?.Value ?? string.Empty, |  | ||||||
|             }; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,39 +0,0 @@ | |||||||
| // *********************************************************************** |  | ||||||
| // <copyright file="PermissionMapper.cs"> |  | ||||||
| //    HEATH |  | ||||||
| // </copyright> |  | ||||||
| // *********************************************************************** |  | ||||||
| using Core.Cerberos.Adapters; |  | ||||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; |  | ||||||
| using Microsoft.AspNetCore.Http; |  | ||||||
| using MongoDB.Bson; |  | ||||||
| using System.Security.Claims; |  | ||||||
| namespace Core.Cerberos.Domain.Contexts.Onboarding.Mappers |  | ||||||
| { |  | ||||||
|     /// <summary> |  | ||||||
|     /// Handles mappings between |  | ||||||
|     /// <see cref="PermissionRequest"/>, |  | ||||||
|     /// and <see cref="PermissionAdapter"/> |  | ||||||
|     /// </summary> |  | ||||||
|     public static class PermissionMapper |  | ||||||
|     { |  | ||||||
|         /// <summary> |  | ||||||
|         /// Maps the permissionRequest to PermissionAdapter. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="newPermission">The Permission to be mapped.</param> |  | ||||||
|         /// <returns>A <see cref="PermissionAdapter"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public static PermissionAdapter ToAdapter(this PermissionRequest newPermission, IHttpContextAccessor httpContextAccessor) |  | ||||||
|         { |  | ||||||
|             return new PermissionAdapter |  | ||||||
|             { |  | ||||||
|                 Id = ObjectId.GenerateNewId().ToString(), |  | ||||||
|                 Name = newPermission.Name, |  | ||||||
|                 Description = newPermission.Description, |  | ||||||
|                 CreatedAt = DateTime.UtcNow, |  | ||||||
|                 CreatedBy = httpContextAccessor.HttpContext?.User?.FindFirst(ClaimTypes.Email)?.Value ?? string.Empty, |  | ||||||
|                 AccessLevel = newPermission.AccessLevel |  | ||||||
|             }; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,42 +0,0 @@ | |||||||
| // *********************************************************************** |  | ||||||
| // <copyright file="RoleMapper.cs"> |  | ||||||
| //    HEATH |  | ||||||
| // </copyright> |  | ||||||
| // *********************************************************************** |  | ||||||
|  |  | ||||||
| using Core.Cerberos.Adapters; |  | ||||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; |  | ||||||
| using Microsoft.AspNetCore.Http; |  | ||||||
| using MongoDB.Bson; |  | ||||||
| using System.Security.Claims; |  | ||||||
| namespace Core.Cerberos.Domain.Contexts.Onboarding.Mappers |  | ||||||
| { |  | ||||||
|     /// <summary> |  | ||||||
|     /// Handles mappings between |  | ||||||
|     /// <see cref="RoleRequest"/>, |  | ||||||
|     /// and <see cref="RoleAdapter"/> |  | ||||||
|     /// </summary> |  | ||||||
|     public static class RoleMapper |  | ||||||
|     { |  | ||||||
|         /// <summary> |  | ||||||
|         /// Maps the RoleRequest to RoleAdapter. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="newRole">The Role to be mapped.</param> |  | ||||||
|         /// <returns>A <see cref="RoleAdapter"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public static RoleAdapter ToAdapter(this RoleRequest newRole, IHttpContextAccessor httpContextAccessor) |  | ||||||
|         { |  | ||||||
|             return new RoleAdapter |  | ||||||
|             { |  | ||||||
|                 Id = ObjectId.GenerateNewId().ToString(), |  | ||||||
|                 Name = newRole.Name, |  | ||||||
|                 Description = newRole.Description, |  | ||||||
|                 Applications = newRole.Applications, |  | ||||||
|                 Modules = newRole.Modules, |  | ||||||
|                 Permissions = newRole.Permissions, |  | ||||||
|                 CreatedAt = DateTime.UtcNow, |  | ||||||
|                 CreatedBy = httpContextAccessor.HttpContext?.User?.FindFirst(ClaimTypes.Email)?.Value ?? string.Empty |  | ||||||
|             }; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,46 +0,0 @@ | |||||||
| // *********************************************************************** |  | ||||||
| // <copyright file="UserMapper.cs"> |  | ||||||
| //    HEATH |  | ||||||
| // </copyright> |  | ||||||
| // *********************************************************************** |  | ||||||
| using Core.Cerberos.Adapters; |  | ||||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; |  | ||||||
| using Microsoft.AspNetCore.Http; |  | ||||||
| using MongoDB.Bson; |  | ||||||
| using System.Security.Claims; |  | ||||||
|  |  | ||||||
| namespace Core.Cerberos.Domain.Contexts.Onboarding.Mappers |  | ||||||
| { |  | ||||||
|     /// <summary> |  | ||||||
|     /// Handles mappings between |  | ||||||
|     /// <see cref="UserRequest"/>, |  | ||||||
|     /// and <see cref="UserAdapter"/> |  | ||||||
|     /// </summary> |  | ||||||
|     public static class UserMapper |  | ||||||
|     { |  | ||||||
|         /// <summary> |  | ||||||
|         /// Maps the UserRequest to UserAdapter. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="newUser">The User to be mapped.</param> |  | ||||||
|         /// <returns>A <see cref="UserAdapter"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public static UserAdapter ToAdapter(this UserRequest newUser, IHttpContextAccessor httpContextAccessor) |  | ||||||
|         { |  | ||||||
|             return new UserAdapter |  | ||||||
|             { |  | ||||||
|                 Id = ObjectId.GenerateNewId().ToString(), |  | ||||||
|                 Guid = Guid.NewGuid().ToString(), |  | ||||||
|                 Email = newUser.Email, |  | ||||||
|                 Name = newUser.Name, |  | ||||||
|                 MiddleName = newUser.MiddleName, |  | ||||||
|                 LastName = newUser.LastName, |  | ||||||
|                 DisplayName = $"{newUser.Name} {newUser.MiddleName} {newUser.LastName}", |  | ||||||
|                 RoleId = newUser.RoleId, |  | ||||||
|                 Companies = newUser.Companies, |  | ||||||
|                 Projects = newUser.Projects, |  | ||||||
|                 CreatedAt = DateTime.UtcNow, |  | ||||||
|                 CreatedBy = httpContextAccessor.HttpContext?.User?.FindFirst(ClaimTypes.Email)?.Value ?? string.Empty |  | ||||||
|             }; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,30 +0,0 @@ | |||||||
| using Core.Cerberos.Infraestructure.Caching.Configs; |  | ||||||
|  |  | ||||||
| namespace LSA.Core.Dapper.Service.Caching |  | ||||||
| { |  | ||||||
|     public static class CacheHelper |  | ||||||
|     { |  | ||||||
|         /// <summary> |  | ||||||
|         /// Determines the cache duration based on specific duration, settings, or a default value. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="specificCacheDuration">Specific cache duration in minutes, if provided.</param> |  | ||||||
|         /// <param name="cacheSettings">General cache settings containing default duration values.</param> |  | ||||||
|         /// <returns>The cache duration as a TimeSpan.</returns> |  | ||||||
|         public static TimeSpan GetCacheDuration(CacheSettings cacheSettings, int? specificCacheDuration = 0) |  | ||||||
|         { |  | ||||||
|             var defaultCacheDuration = TimeSpan.FromMinutes(.5); |  | ||||||
|  |  | ||||||
|             if (specificCacheDuration.HasValue && specificCacheDuration.Value > 0) |  | ||||||
|             { |  | ||||||
|                 return TimeSpan.FromMinutes(specificCacheDuration.Value); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             if (cacheSettings.DefaultCacheDurationInMinutes > 0) |  | ||||||
|             { |  | ||||||
|                 return TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             return defaultCacheDuration; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,47 +0,0 @@ | |||||||
| using System.Reflection; |  | ||||||
| using System.Text; |  | ||||||
| using System.Text.RegularExpressions; |  | ||||||
|  |  | ||||||
| namespace LSA.Core.Dapper.Service.Caching |  | ||||||
| { |  | ||||||
|     public static class CacheKeyHelper |  | ||||||
|     { |  | ||||||
|         public static string GenerateCacheKey(object instance, string methodName, params object[] parameters) |  | ||||||
|         { |  | ||||||
|             var className = instance.GetType().Name; |  | ||||||
|             var keyBuilder = new StringBuilder($"{className}.{methodName}"); |  | ||||||
|  |  | ||||||
|             foreach (var param in parameters) |  | ||||||
|             { |  | ||||||
|                 string normalizedParam = NormalizeParameter(param); |  | ||||||
|                 keyBuilder.Append($".{normalizedParam}"); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             return keyBuilder.ToString(); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         private static string NormalizeParameter(object param) |  | ||||||
|         { |  | ||||||
|             if (param == null) |  | ||||||
|             { |  | ||||||
|                 return "null"; |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             string paramString; |  | ||||||
|  |  | ||||||
|             if (param is DateTime dateTime) |  | ||||||
|             { |  | ||||||
|                 paramString = dateTime.ToString("yyyyMMdd"); |  | ||||||
|             } |  | ||||||
|             else |  | ||||||
|             { |  | ||||||
|                 paramString = param.ToString(); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             // Replace special characters with an underscore |  | ||||||
|             string normalizedParam = Regex.Replace(paramString, @"[^a-zA-Z0-9]", "_"); |  | ||||||
|  |  | ||||||
|             return normalizedParam; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,133 +0,0 @@ | |||||||
| using Azure.Identity; |  | ||||||
| using Core.Cerberos.Infraestructure.Caching.Contracts; |  | ||||||
| using Microsoft.Extensions.Logging; |  | ||||||
| using StackExchange.Redis; |  | ||||||
| using System.Text.Json; |  | ||||||
|  |  | ||||||
| namespace LSA.Core.Dapper.Service.Caching |  | ||||||
| { |  | ||||||
|     public class CacheService : ICacheService |  | ||||||
|     { |  | ||||||
|         private IDatabase _cacheDatabase = null!; |  | ||||||
|         private readonly ILogger<CacheService> _logger; |  | ||||||
|  |  | ||||||
|  |  | ||||||
|         public CacheService(string connectionString, ILogger<CacheService> logger) |  | ||||||
|         { |  | ||||||
|             _logger = logger; |  | ||||||
|             Task.Run(async () => |  | ||||||
|             { |  | ||||||
|                 _cacheDatabase = await GetRedisDatabase(connectionString); |  | ||||||
|             }).Wait(); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         private async Task<IDatabase> GetRedisDatabase(string connectionString) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var configurationOptions = await ConfigurationOptions.Parse($"{connectionString}") |  | ||||||
|                     .ConfigureForAzureWithTokenCredentialAsync(new DefaultAzureCredential()); |  | ||||||
|  |  | ||||||
|                 configurationOptions.AbortOnConnectFail = false; |  | ||||||
|                 var connectionMultiplexer = await ConnectionMultiplexer.ConnectAsync(configurationOptions); |  | ||||||
|  |  | ||||||
|                 _logger.LogInformation("Successfully connected to Redis."); |  | ||||||
|  |  | ||||||
|                 return connectionMultiplexer.GetDatabase(); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 _logger.LogError(ex, "Error establishing Redis connection."); |  | ||||||
|                 throw; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|  |  | ||||||
|         public async Task<T> GetAsync<T>(string key) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var value = await _cacheDatabase.StringGetAsync(key); |  | ||||||
|                 if (value.IsNullOrEmpty) |  | ||||||
|                 { |  | ||||||
|                     _logger.LogInformation($"Cache miss for key: {key}"); |  | ||||||
|                     return default; |  | ||||||
|                 } |  | ||||||
|  |  | ||||||
|                 _logger.LogInformation($"Cache hit for key: {key}"); |  | ||||||
|                 return JsonSerializer.Deserialize<T>(value); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 _logger.LogError(ex, $"Error getting cache item with key {key}"); |  | ||||||
|                 throw; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         public async Task SetAsync<T>(string key, T value, TimeSpan? expiry = null) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var json = JsonSerializer.Serialize(value); |  | ||||||
|                 await _cacheDatabase.StringSetAsync(key, json, expiry); |  | ||||||
|                 _logger.LogInformation($"Cache item set with key: {key}"); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 _logger.LogError(ex, $"Error setting cache item with key {key}"); |  | ||||||
|                 throw; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         public async Task RemoveAsync(string key) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 await _cacheDatabase.KeyDeleteAsync(key); |  | ||||||
|                 _logger.LogInformation($"Cache item removed with key: {key}"); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 _logger.LogError(ex, $"Error removing cache item with key {key}"); |  | ||||||
|                 throw; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         public async Task<bool> ExistsAsync(string key) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var exists = await _cacheDatabase.KeyExistsAsync(key); |  | ||||||
|                 _logger.LogInformation($"Cache item exists check for key: {key} - {exists}"); |  | ||||||
|                 return exists; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 _logger.LogError(ex, $"Error checking existence of cache item with key {key}"); |  | ||||||
|                 throw; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         public async Task RefreshAsync(string key, TimeSpan? expiry = null) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var value = await _cacheDatabase.StringGetAsync(key); |  | ||||||
|                 if (!value.IsNullOrEmpty) |  | ||||||
|                 { |  | ||||||
|                     await _cacheDatabase.StringSetAsync(key, value, expiry); |  | ||||||
|                     _logger.LogInformation($"Cache item refreshed with key: {key}"); |  | ||||||
|                 } |  | ||||||
|                 else |  | ||||||
|                 { |  | ||||||
|                     _logger.LogWarning($"Cache item with key: {key} does not exist, cannot refresh"); |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 _logger.LogError(ex, $"Error refreshing cache item with key {key}"); |  | ||||||
|                 throw; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,7 +0,0 @@ | |||||||
| namespace Core.Cerberos.Infraestructure.Caching.Configs |  | ||||||
| { |  | ||||||
|     public class CacheSettings |  | ||||||
|     { |  | ||||||
|         public int DefaultCacheDurationInMinutes { get; set; } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,11 +0,0 @@ | |||||||
| namespace Core.Cerberos.Infraestructure.Caching.Contracts |  | ||||||
| { |  | ||||||
|     public interface ICacheService |  | ||||||
|     { |  | ||||||
|         Task<T> GetAsync<T>(string key); |  | ||||||
|         Task SetAsync<T>(string key, T value, TimeSpan? expiry = null); |  | ||||||
|         Task RemoveAsync(string key); |  | ||||||
|         Task<bool> ExistsAsync(string key); |  | ||||||
|         Task RefreshAsync(string key, TimeSpan? expiry = null); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,33 +0,0 @@ | |||||||
| using Microsoft.Extensions.Configuration; |  | ||||||
|  |  | ||||||
| namespace Core.Cerberos.Infraestructure.Contexts.Mongo |  | ||||||
| { |  | ||||||
|     public class ConnectionStringProvider(IConfiguration configuration) : IConnectionStringProvider |  | ||||||
|     { |  | ||||||
|         public string ConnectionString { get; set; } = string.Empty; |  | ||||||
|         public string Databasename { get; set; } = string.Empty; |  | ||||||
|         public string Audience { get; set; } = string.Empty; |  | ||||||
|  |  | ||||||
|         public string GetConnectionString() |  | ||||||
|         { |  | ||||||
|             return configuration?.GetConnectionString("DefaultConnection")?.ToString() ?? string.Empty; |  | ||||||
|         } |  | ||||||
|         public string GetDatabasename() |  | ||||||
|         { |  | ||||||
|             return configuration.GetSection("MongoDb:DatabaseName").Value ?? string.Empty; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         public string GetAudience() |  | ||||||
|         { |  | ||||||
|             return configuration.GetSection("MongoDb:Audience").Value ?? string.Empty; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|     public interface IConnectionStringProvider |  | ||||||
|     { |  | ||||||
|         string GetConnectionString(); |  | ||||||
|         string GetDatabasename(); |  | ||||||
|         string ConnectionString { get; set; } |  | ||||||
|         string Databasename { get; set; } |  | ||||||
|         string Audience { get; set; } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,14 +0,0 @@ | |||||||
| namespace Core.Cerberos.Infraestructure.Contexts.Mongo; |  | ||||||
|  |  | ||||||
| public interface IMongoConnSettings |  | ||||||
| { |  | ||||||
|     string ConnectionString { get; set; } |  | ||||||
|     string Databasename { get; set; } |  | ||||||
|     string Audience { get; set; } |  | ||||||
| } |  | ||||||
| public class MongoConnSettings : IMongoConnSettings |  | ||||||
| { |  | ||||||
|     public string ConnectionString { get; set; } |  | ||||||
|     public string Databasename { get; set; } |  | ||||||
|     public string Audience { get; set; } |  | ||||||
| } |  | ||||||
| @@ -1,15 +0,0 @@ | |||||||
| namespace Core.Cerberos.Infraestructure.PerformanceCacheService |  | ||||||
| { |  | ||||||
|     [AttributeUsage(AttributeTargets.Method, Inherited = true, AllowMultiple = false)] |  | ||||||
|     public class CacheAttribute : Attribute |  | ||||||
|     { |  | ||||||
|         public int CacheDurationInMinutes { get; set; } |  | ||||||
|         public bool EnableCaching { get; set; } |  | ||||||
|  |  | ||||||
|         public CacheAttribute(int cacheDurationInMinutes, bool enableCaching = true) |  | ||||||
|         { |  | ||||||
|             CacheDurationInMinutes = cacheDurationInMinutes; |  | ||||||
|             EnableCaching = enableCaching; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,64 +0,0 @@ | |||||||
| // *********************************************************************** |  | ||||||
| // <copyright file="IModuleService.cs"> |  | ||||||
| //     AgileWebs |  | ||||||
| // </copyright> |  | ||||||
| // *********************************************************************** |  | ||||||
| using Core.Cerberos.Adapters; |  | ||||||
| using Core.Cerberos.Adapters.Common.Enums; |  | ||||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; |  | ||||||
|  |  | ||||||
| namespace Core.Cerberos.Provider.Contracts |  | ||||||
| { |  | ||||||
|     public interface IModuleService |  | ||||||
|     { |  | ||||||
|         /// <summary> |  | ||||||
|         /// Creates a new Module. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="entity">The Module to be created.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         Task<ModuleAdapter> CreateModuleService(ModuleRequest newModule); |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets an Module by identifier. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="id">The Module identifier.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         Task<ModuleAdapter> GetModuleByIdService(string id); |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets all the roles. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <returns>A <see cref="{Task{IEnumerbale{ModuleAdapter}}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         Task<IEnumerable<ModuleAdapter>> GetAllModulesService(); |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets all the permissions by permissions identifier list. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="permissions">The list of permissions identifiers.</param> |  | ||||||
|         /// <returns>A <see cref="Task{IEnumerable{ModuleAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         Task<IEnumerable<ModuleAdapter>> GetAllModulesByListService(string[] permissions); |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Changes the status of the permission. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="id">The permission identifier.</param> |  | ||||||
|         /// <param name="newStatus">The new status of the permission.</param> |  | ||||||
|         /// <returns>The <see cref="ModuleAdapter"/> updated entity.</returns> |  | ||||||
|         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         Task<ModuleAdapter> ChangeModuleStatusService(string id, StatusEnum newStatus); |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Updates a Module by id. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="entity">The Module to be updated.</param> |  | ||||||
|         /// <param name="id">The Module identifier.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         Task<ModuleAdapter> UpdateModuleService(ModuleAdapter entity, string id); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,64 +0,0 @@ | |||||||
| // *********************************************************************** |  | ||||||
| // <copyright file="IPermissionService.cs"> |  | ||||||
| //     AgileWebs |  | ||||||
| // </copyright> |  | ||||||
| // *********************************************************************** |  | ||||||
| using Core.Cerberos.Adapters; |  | ||||||
| using Core.Cerberos.Adapters.Common.Enums; |  | ||||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; |  | ||||||
|  |  | ||||||
| namespace Core.Cerberos.Provider.Contracts |  | ||||||
| { |  | ||||||
|     public interface IPermissionService |  | ||||||
|     { |  | ||||||
|         /// <summary> |  | ||||||
|         /// Creates a new Permission. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="entity">The Permission to be created.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         Task<PermissionAdapter> CreatePermissionService(PermissionRequest newPermission); |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets an Permission by identifier. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="id">The Permission identifier.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         Task<PermissionAdapter> GetPermissionByIdService(string id); |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets all the roles. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <returns>A <see cref="{Task{IEnumerbale{PermissionAdapter}}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         Task<IEnumerable<PermissionAdapter>> GetAllPermissionsService(); |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets all the permissions by permissions identifier list. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="permissions">The list of permissions identifiers.</param> |  | ||||||
|         /// <returns>A <see cref="Task{IEnumerable{PermissionAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         Task<IEnumerable<PermissionAdapter>> GetAllPermissionsByListService(string[] permissions); |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Changes the status of the permission. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="id">The permission identifier.</param> |  | ||||||
|         /// <param name="newStatus">The new status of the permission.</param> |  | ||||||
|         /// <returns>The <see cref="PermissionAdapter"/> updated entity.</returns> |  | ||||||
|         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         Task<PermissionAdapter> ChangePermissionStatusService(string id, StatusEnum newStatus); |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Updates a Permission by id. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="entity">The Permission to be updated.</param> |  | ||||||
|         /// <param name="id">The Permission identifier.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         Task<PermissionAdapter> UpdatePermissionService(PermissionAdapter entity, string id); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,72 +0,0 @@ | |||||||
| // *********************************************************************** |  | ||||||
| // <copyright file="IRoleService.cs"> |  | ||||||
| //     AgileWebs |  | ||||||
| // </copyright> |  | ||||||
| // *********************************************************************** |  | ||||||
| using Core.Cerberos.Adapters; |  | ||||||
| using Core.Cerberos.Adapters.Common.Enums; |  | ||||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; |  | ||||||
|  |  | ||||||
| namespace Core.Cerberos.Provider.Contracts |  | ||||||
| { |  | ||||||
|     public interface IRoleService |  | ||||||
|     { |  | ||||||
|         /// <summary> |  | ||||||
|         /// Creates a new Role. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="entity">The Role to be created.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         Task<RoleAdapter> CreateRoleService(RoleRequest newRole); |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets an Role by identifier. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="id">The Role identifier.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         Task<RoleAdapter> GetRoleByIdService(string id); |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets all the roles. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <returns>A <see cref="{Task{IEnumerbale{RoleAdapter}}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         Task<IEnumerable<RoleAdapter>> GetAllRolesService(); |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Changes the status of the role. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="id">The role identifier.</param> |  | ||||||
|         /// <param name="newStatus">The new status of the role.</param> |  | ||||||
|         /// <returns>The <see cref="RoleAdapter"/> updated entity.</returns> |  | ||||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         Task<RoleAdapter> ChangeRoleStatusService(string id, StatusEnum newStatus); |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Updates a Role by id. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="entity">The Role to be updated.</param> |  | ||||||
|         /// <param name="id">The Role identifier.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         Task<RoleAdapter> UpdateRoleService(RoleAdapter entity, string id); |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Adds an application to the role's list of applications. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="roleId">The identifier of the role to which the application will be added.</param> |  | ||||||
|         /// <param name="application">The application enum value to add.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing the asynchronous operation, with the updated role object.</returns> |  | ||||||
|         Task<RoleAdapter> AddApplicationToRoleService(string roleId, ApplicationsEnum application); |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Removes an application from the role's list of applications. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="roleId">The identifier of the role from which the application will be removed.</param> |  | ||||||
|         /// <param name="application">The application enum value to remove.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing the asynchronous operation, with the updated role object.</returns> |  | ||||||
|         Task<RoleAdapter> RemoveApplicationFromRoleService(string roleId, ApplicationsEnum application); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,129 +0,0 @@ | |||||||
| // *********************************************************************** |  | ||||||
| // <copyright file="IUserService.cs"> |  | ||||||
| //     AgileWebs |  | ||||||
| // </copyright> |  | ||||||
| // *********************************************************************** |  | ||||||
| using Core.Blueprint.Storage.Adapters; |  | ||||||
| using Core.Cerberos.Adapters; |  | ||||||
| using Core.Cerberos.Adapters.Common.Enums; |  | ||||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; |  | ||||||
|  |  | ||||||
| namespace Core.Cerberos.Provider.Contracts |  | ||||||
| { |  | ||||||
|     public interface IUserService |  | ||||||
|     { |  | ||||||
|         /// <summary> |  | ||||||
|         /// Creates a new User. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="entity">The User to be created.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         Task<UserAdapter> CreateUserService(UserRequest newUser); |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets an User by identifier. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="id">The User identifier.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         Task<UserAdapter> GetUserByIdService(string id); |  | ||||||
|  |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets all the users. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <returns>A <see cref="{Task{IEnumerable{UserAdapter}}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         Task<IEnumerable<UserAdapter>> GetAllUsersService(); |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets an User by email. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="email">The User email.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         Task<UserAdapter> GetUserByEmailService(string? email); |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Validates if a users exists by email. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="eamil">The User email.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         Task<UserAdapter> ValidateUserExistenceService(string? email); |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Changes the status of the user. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="id">The user identifier.</param> |  | ||||||
|         /// <param name="newStatus">The new status of the user.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         Task<UserAdapter> ChangeUserStatusService(string id, StatusEnum newStatus); |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Updates a User by id. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="entity">The User to be updated.</param> |  | ||||||
|         /// <param name="id">The User identifier.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         Task<UserAdapter> UpdateUserService(UserAdapter entity, string id); |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Logs in the user. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="email">The User's email.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         Task<UserAdapter?> LogInUserService(string email); |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Logs out the user's session. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="email">The User's email.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         Task<UserAdapter> LogOutUserSessionService(string email); |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Adds a company to the user's list of companies. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="userId">The identifier of the user to whom the company will be added.</param> |  | ||||||
|         /// <param name="companyId">The identifier of the company to add.</param> |  | ||||||
|         /// <returns>A <see cref="Task{UserAdapter}"/> representing the asynchronous operation, with the updated user object.</returns> |  | ||||||
|         Task<UserAdapter> AddCompanyToUserService(string userId, string companyId); |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Removes a company from the user's list of companies. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="userId">The identifier of the user from whom the company will be removed.</param> |  | ||||||
|         /// <param name="companyId">The identifier of the company to remove.</param> |  | ||||||
|         /// <returns>A <see cref="Task{UserAdapter}"/> representing the asynchronous operation, with the updated user object.</returns> |  | ||||||
|         Task<UserAdapter> RemoveCompanyFromUserService(string userId, string companyId); |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Adds a project to the user's list of projects. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="userId">The identifier of the user to whom the project will be added.</param> |  | ||||||
|         /// <param name="projectId">The identifier of the project to add.</param> |  | ||||||
|         /// <returns>A <see cref="Task{UserAdapter}"/> representing the asynchronous operation, with the updated user object.</returns> |  | ||||||
|         Task<UserAdapter> AddProjectToUserService(string userId, string projectId); |  | ||||||
|  |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Removes a project from the user's list of projects. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="userId">The identifier of the user from whom the project will be removed.</param> |  | ||||||
|         /// <param name="projectId">The identifier of the project to remove.</param> |  | ||||||
|         /// <returns>A <see cref="Task{UserAdapter}"/> representing the asynchronous operation, with the updated user object.</returns> |  | ||||||
|         Task<UserAdapter> RemoveProjectFromUserService(string userId, string projectId); |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets the token adapter for a user. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="email">The user's email.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{TokenAdapter}}"/> representing the asynchronous execution of the service.</returns> |  | ||||||
|         Task<TokenAdapter?> GetTokenAdapter(string email); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,24 +0,0 @@ | |||||||
| <Project Sdk="Microsoft.NET.Sdk"> |  | ||||||
|  |  | ||||||
|   <PropertyGroup> |  | ||||||
|     <TargetFramework>net8.0</TargetFramework> |  | ||||||
|     <ImplicitUsings>enable</ImplicitUsings> |  | ||||||
|     <Nullable>enable</Nullable> |  | ||||||
|   </PropertyGroup> |  | ||||||
|  |  | ||||||
|   <ItemGroup> |  | ||||||
|     <Compile Remove="Providers\Onboarding\UserService - Copy.cs" /> |  | ||||||
|   </ItemGroup> |  | ||||||
|  |  | ||||||
|   <ItemGroup> |  | ||||||
|     <PackageReference Include="Core.Blueprint.Storage" Version="0.3.0-alpha0049" /> |  | ||||||
|     <PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" /> |  | ||||||
|     <PackageReference Include="MongoDB.Driver" Version="3.0.0" /> |  | ||||||
|   </ItemGroup> |  | ||||||
|  |  | ||||||
|   <ItemGroup> |  | ||||||
|     <ProjectReference Include="..\Core.Cerberos.Domain\Core.Cerberos.Domain.csproj" /> |  | ||||||
|     <ProjectReference Include="..\Core.Cerberos.Infraestructure\Core.Cerberos.Infrastructure.csproj" /> |  | ||||||
|   </ItemGroup> |  | ||||||
|  |  | ||||||
| </Project> |  | ||||||
| @@ -1,16 +0,0 @@ | |||||||
| using MongoDB.Driver; |  | ||||||
|  |  | ||||||
| namespace Core.Cerberos.Provider.Providers |  | ||||||
| { |  | ||||||
|     public class BaseProvider |  | ||||||
|     { |  | ||||||
|         private readonly IMongoDatabase _database; |  | ||||||
|  |  | ||||||
|         public BaseProvider(IMongoDatabase database) |  | ||||||
|         { |  | ||||||
|             _database = database ?? throw new ArgumentNullException(nameof(database)); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         protected IMongoDatabase Database => _database; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,99 +0,0 @@ | |||||||
| using Azure.Core; |  | ||||||
| using Azure.Identity; |  | ||||||
| using Core.Cerberos.Adapters.Common.Constants; |  | ||||||
| using MongoDB.Driver.Authentication.Oidc; |  | ||||||
|  |  | ||||||
| namespace Core.Cerberos.Provider.Providers |  | ||||||
| { |  | ||||||
|     public class HeathOidcCallback : IOidcCallback |  | ||||||
|     { |  | ||||||
|         private readonly string _audience; |  | ||||||
|         private readonly string _environment; |  | ||||||
|         public HeathOidcCallback(string audience) |  | ||||||
|         { |  | ||||||
|             _audience = audience; |  | ||||||
|             _environment = Environment.GetEnvironmentVariable(EnvironmentVariables.Stage) ?? string.Empty; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         public OidcAccessToken GetOidcAccessToken(OidcCallbackParameters parameters, CancellationToken cancellationToken) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 AccessToken token; |  | ||||||
|  |  | ||||||
|                 TokenRequestContext tokenRequestContext = |  | ||||||
|                     new TokenRequestContext( |  | ||||||
|                         new[] { _audience } |  | ||||||
|                     ); |  | ||||||
|  |  | ||||||
|                 if (_environment == "Local") |  | ||||||
|                 { |  | ||||||
|                     token = |  | ||||||
|                     new ChainedTokenCredential( |  | ||||||
|                         new ManagedIdentityCredential(), |  | ||||||
|                         new VisualStudioCredential(), |  | ||||||
|                         new VisualStudioCodeCredential(), |  | ||||||
|                         new SharedTokenCacheCredential() |  | ||||||
|                     ) |  | ||||||
|                     .GetToken( |  | ||||||
|                         tokenRequestContext |  | ||||||
|                     ); |  | ||||||
|                 } |  | ||||||
|                 else |  | ||||||
|                 { |  | ||||||
|                     token = |  | ||||||
|                     new ManagedIdentityCredential() |  | ||||||
|                     .GetToken( |  | ||||||
|                         tokenRequestContext |  | ||||||
|                     ); |  | ||||||
|                 } |  | ||||||
|  |  | ||||||
|                 return new(token.Token, expiresIn: null); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|  |  | ||||||
|                 throw new Exception($"An error ocurred while trying to get the OIDC token to connect to the database, ERROR: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         public async Task<OidcAccessToken> GetOidcAccessTokenAsync(OidcCallbackParameters parameters, CancellationToken cancellationToken) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 TokenRequestContext tokenRequestContext = |  | ||||||
|                     new TokenRequestContext( |  | ||||||
|                         new[] { _audience } |  | ||||||
|                     ); |  | ||||||
|  |  | ||||||
|                 AccessToken token; |  | ||||||
|  |  | ||||||
|                 if (_environment == "Local") |  | ||||||
|                 { |  | ||||||
|                     token = await new ChainedTokenCredential( |  | ||||||
|                         new ManagedIdentityCredential(), |  | ||||||
|                         new VisualStudioCredential(), |  | ||||||
|                         new VisualStudioCodeCredential(), |  | ||||||
|                         new SharedTokenCacheCredential() |  | ||||||
|                     ) |  | ||||||
|                     .GetTokenAsync( |  | ||||||
|                         tokenRequestContext, cancellationToken |  | ||||||
|                     ).ConfigureAwait(false); |  | ||||||
|                 } |  | ||||||
|                 else |  | ||||||
|                 { |  | ||||||
|                     token = await new ManagedIdentityCredential() |  | ||||||
|                     .GetTokenAsync( |  | ||||||
|                         tokenRequestContext, cancellationToken |  | ||||||
|                     ).ConfigureAwait(false); |  | ||||||
|                 } |  | ||||||
|  |  | ||||||
|                 return new(token.Token, expiresIn: null); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 throw new Exception($"An error ocurred while trying to get the OIDC token to connect to the database, ERROR: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,256 +0,0 @@ | |||||||
| // *********************************************************************** |  | ||||||
| // <copyright file="ModuleService.cs"> |  | ||||||
| //     AgileWebs |  | ||||||
| // </copyright> |  | ||||||
| // *********************************************************************** |  | ||||||
| using Core.Cerberos.Adapters; |  | ||||||
| using Core.Cerberos.Adapters.Common.Constants; |  | ||||||
| using Core.Cerberos.Adapters.Common.Enums; |  | ||||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Mappers; |  | ||||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; |  | ||||||
| using Core.Cerberos.Infraestructure.Caching.Configs; |  | ||||||
| using Core.Cerberos.Infraestructure.Caching.Contracts; |  | ||||||
| using Core.Cerberos.Provider.Contracts; |  | ||||||
| using LSA.Core.Dapper.Service.Caching; |  | ||||||
| using Microsoft.AspNetCore.Http; |  | ||||||
| using Microsoft.Extensions.Logging; |  | ||||||
| using Microsoft.Extensions.Options; |  | ||||||
| using MongoDB.Bson; |  | ||||||
| using MongoDB.Driver; |  | ||||||
|  |  | ||||||
| namespace Core.Cerberos.Provider.Providers.Onboarding |  | ||||||
| { |  | ||||||
|     /// <summary> |  | ||||||
|     /// Handles all services and business rules related to <see cref="ModuleAdapter"/>. |  | ||||||
|     /// </summary> |  | ||||||
|     public class ModuleService(ILogger<ModuleService> logger, IHttpContextAccessor httpContextAccessor, ICacheService cacheService, |  | ||||||
|         IOptions<CacheSettings> cacheSettings, IMongoDatabase database) : IModuleService |  | ||||||
|     { |  | ||||||
|         private readonly CacheSettings _cacheSettings = cacheSettings.Value; |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Creates a new Module. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="entity">The Module to be created.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<ModuleAdapter> CreateModuleService(ModuleRequest newModule) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var entity = newModule.ToAdapter(httpContextAccessor); |  | ||||||
|                 entity.Order = (entity.Order is not null) ? entity.Order : await GetLastOrderModule(newModule); |  | ||||||
|                 await database.GetCollection<ModuleAdapter>(CollectionNames.Module).InsertOneAsync(entity); |  | ||||||
|                 entity.Id = (entity as dynamic ?? "").Id.ToString(); |  | ||||||
|  |  | ||||||
|                 return entity; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"CreateModuleService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets an Module by identifier. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="id">The Module identifier.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns>0 |  | ||||||
|         public async Task<ModuleAdapter> GetModuleByIdService(string id) |  | ||||||
|         { |  | ||||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetModuleByIdService", id); |  | ||||||
|             var cachedData = await cacheService.GetAsync<ModuleAdapter>(cacheKey); |  | ||||||
|  |  | ||||||
|             if (cachedData is not null) { return cachedData; } |  | ||||||
|  |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<ModuleAdapter>.Filter.And( |  | ||||||
|                     Builders<ModuleAdapter>.Filter.Eq("_id", ObjectId.Parse(id)), |  | ||||||
|                     Builders<ModuleAdapter>.Filter.Eq("status", StatusEnum.Active.ToString()) |  | ||||||
|                 ); |  | ||||||
|  |  | ||||||
|                 var module = await database.GetCollection<ModuleAdapter>(CollectionNames.Module) |  | ||||||
|                                     .Find(filter) |  | ||||||
|                                     .FirstOrDefaultAsync(); |  | ||||||
|  |  | ||||||
|                 var cacheDuration = CacheHelper.GetCacheDuration(_cacheSettings); |  | ||||||
|  |  | ||||||
|                 await cacheService.SetAsync(cacheKey, module, cacheDuration); |  | ||||||
|  |  | ||||||
|                 return module; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"GetModuleByIdService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets all the modules. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <returns>A <see cref="{Task{IEnumerbale{ModuleAdapter}}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<IEnumerable<ModuleAdapter>> GetAllModulesService() |  | ||||||
|         { |  | ||||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllModulesService"); |  | ||||||
|             var cachedData = await cacheService.GetAsync<IEnumerable<ModuleAdapter>>(cacheKey) ?? []; |  | ||||||
|  |  | ||||||
|             if (cachedData.Any()) return cachedData; |  | ||||||
|  |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<ModuleAdapter>.Filter.Eq("status", StatusEnum.Active.ToString()); |  | ||||||
|  |  | ||||||
|                 var roles = await database.GetCollection<ModuleAdapter>(CollectionNames.Module) |  | ||||||
|                                     .Find(filter) |  | ||||||
|                                     .SortBy(m => m.Application) |  | ||||||
|                                     .ThenBy(m => m.Order) |  | ||||||
|                                     .ToListAsync(); |  | ||||||
|  |  | ||||||
|                 var cacheDuration = CacheHelper.GetCacheDuration(_cacheSettings); |  | ||||||
|  |  | ||||||
|                 await cacheService.SetAsync(cacheKey, roles, cacheDuration); |  | ||||||
|  |  | ||||||
|                 return roles; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"GetAllModulesService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets all the modules by modules identifier list. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="modules">The list of modules identifiers.</param> |  | ||||||
|         /// <returns>A <see cref="Task{IEnumerable{ModuleAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<IEnumerable<ModuleAdapter>> GetAllModulesByListService(string[] modules) |  | ||||||
|         { |  | ||||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllModulesByListService", modules); |  | ||||||
|  |  | ||||||
|             var cachedData = await cacheService.GetAsync<IEnumerable<ModuleAdapter>>(cacheKey); |  | ||||||
|  |  | ||||||
|             if (cachedData != null && cachedData.Any()) return cachedData; |  | ||||||
|  |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var objectIds = modules.Select(id => ObjectId.Parse(id)).ToArray(); |  | ||||||
|  |  | ||||||
|                 var filter = Builders<ModuleAdapter>.Filter.In("_id", objectIds) |  | ||||||
|                                 & Builders<ModuleAdapter>.Filter.Eq("status", StatusEnum.Active.ToString()); |  | ||||||
|  |  | ||||||
|                 var roles = await database.GetCollection<ModuleAdapter>(CollectionNames.Module) |  | ||||||
|                                           .Find(filter) |  | ||||||
|                                           .SortBy(m => m.Application) |  | ||||||
|                                           .ThenBy(m => m.Order) |  | ||||||
|                                           .ToListAsync(); |  | ||||||
|  |  | ||||||
|                 var cacheDuration = CacheHelper.GetCacheDuration(_cacheSettings); |  | ||||||
|  |  | ||||||
|                 await cacheService.SetAsync(cacheKey, roles, cacheDuration); |  | ||||||
|  |  | ||||||
|                 return roles; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"GetAllModulesByListService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Changes the status of the module. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="id">The module identifier.</param> |  | ||||||
|         /// <param name="newStatus">The new status of the module.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<ModuleAdapter> ChangeModuleStatusService(string id, StatusEnum newStatus) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<ModuleAdapter>.Filter |  | ||||||
|                     .Eq("_id", ObjectId.Parse(id)); |  | ||||||
|  |  | ||||||
|                 var update = Builders<ModuleAdapter>.Update |  | ||||||
|                             .Set(v => v.Status, newStatus) |  | ||||||
|                             .Set(v => v.UpdatedBy, Helper.GetEmail(httpContextAccessor)) |  | ||||||
|                             .Set(v => v.UpdatedAt, DateTime.UtcNow); |  | ||||||
|  |  | ||||||
|                 await database.GetCollection<ModuleAdapter>(CollectionNames.Module).UpdateOneAsync(filter, update); |  | ||||||
|  |  | ||||||
|                 var updatedModule = await database.GetCollection<ModuleAdapter>(CollectionNames.Module) |  | ||||||
|                                     .Find(filter) |  | ||||||
|                                     .FirstOrDefaultAsync(); |  | ||||||
|  |  | ||||||
|                 return updatedModule; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"ChangeModuleStatusService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Updates a Module by id. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="entity">The Module to be updated.</param> |  | ||||||
|         /// <param name="id">The Module identifier.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<ModuleAdapter> UpdateModuleService(ModuleAdapter entity, string id) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<ModuleAdapter>.Filter |  | ||||||
|                     .Eq("_id", ObjectId.Parse(id)); |  | ||||||
|  |  | ||||||
|                 var update = Builders<ModuleAdapter>.Update |  | ||||||
|                             .Set(v => v.Name, entity.Name) |  | ||||||
|                             .Set(v => v.Description, entity.Description) |  | ||||||
|                             .Set(v => v.Icon, entity.Icon) |  | ||||||
|                             .Set(v => v.Route, entity.Route) |  | ||||||
|                             .Set(v => v.Order, entity.Order) |  | ||||||
|                             .Set(v => v.Application, entity.Application) |  | ||||||
|                             .Set(v => v.Status, entity.Status) |  | ||||||
|                             .Set(v => v.UpdatedBy, Helper.GetEmail(httpContextAccessor)) |  | ||||||
|                             .Set(v => v.UpdatedAt, DateTime.UtcNow); |  | ||||||
|  |  | ||||||
|                 await database.GetCollection<ModuleAdapter>(CollectionNames.Module).UpdateOneAsync(filter, update); |  | ||||||
|  |  | ||||||
|                 var updatedModule = await database.GetCollection<ModuleAdapter>(CollectionNames.Module) |  | ||||||
|                                             .Find(filter) |  | ||||||
|                                             .FirstOrDefaultAsync(); |  | ||||||
|  |  | ||||||
|                 return updatedModule; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"UpdateModuleService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         private async Task<int?> GetLastOrderModule(ModuleRequest newModule) |  | ||||||
|         { |  | ||||||
|             var filter = Builders<ModuleAdapter>.Filter.And( |  | ||||||
|                 Builders<ModuleAdapter>.Filter.Eq("status", StatusEnum.Active.ToString()), |  | ||||||
|                 Builders<ModuleAdapter>.Filter.Eq("application", newModule.Application.ToString())); |  | ||||||
|  |  | ||||||
|             var maxOrderModule = await database.GetCollection<ModuleAdapter>(CollectionNames.Module) |  | ||||||
|                                                .Find(filter) |  | ||||||
|                                                .SortByDescending(m => m.Order) |  | ||||||
|                                                .FirstOrDefaultAsync(); |  | ||||||
|  |  | ||||||
|             return (maxOrderModule is not null && maxOrderModule.Order is not null) ? maxOrderModule.Order : 0; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,234 +0,0 @@ | |||||||
| // *********************************************************************** |  | ||||||
| // <copyright file="PermissionService.cs"> |  | ||||||
| //     AgileWebs |  | ||||||
| // </copyright> |  | ||||||
| // *********************************************************************** |  | ||||||
| using Core.Cerberos.Adapters; |  | ||||||
| using Core.Cerberos.Adapters.Common.Constants; |  | ||||||
| using Core.Cerberos.Adapters.Common.Enums; |  | ||||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Mappers; |  | ||||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; |  | ||||||
| using Core.Cerberos.Infraestructure.Caching.Configs; |  | ||||||
| using Core.Cerberos.Infraestructure.Caching.Contracts; |  | ||||||
| using Core.Cerberos.Provider.Contracts; |  | ||||||
| using LSA.Core.Dapper.Service.Caching; |  | ||||||
| using Microsoft.AspNetCore.Http; |  | ||||||
| using Microsoft.Extensions.Logging; |  | ||||||
| using Microsoft.Extensions.Options; |  | ||||||
| using MongoDB.Bson; |  | ||||||
| using MongoDB.Driver; |  | ||||||
|  |  | ||||||
| namespace Core.Cerberos.Provider.Providers.Onboarding |  | ||||||
| { |  | ||||||
|     /// <summary> |  | ||||||
|     /// Handles all services and business rules related to <see cref="PermissionAdapter"/>. |  | ||||||
|     /// </summary> |  | ||||||
|     public class PermissionService(ILogger<PermissionService> logger, IHttpContextAccessor httpContextAccessor, ICacheService cacheService, |  | ||||||
|         IOptions<CacheSettings> cacheSettings, IMongoDatabase database) : IPermissionService |  | ||||||
|     { |  | ||||||
|         private readonly CacheSettings _cacheSettings = cacheSettings.Value; |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Creates a new Permission. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="entity">The Permission to be created.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<PermissionAdapter> CreatePermissionService(PermissionRequest newPermission) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var entity = newPermission.ToAdapter(httpContextAccessor); |  | ||||||
|                 await database.GetCollection<PermissionAdapter>(CollectionNames.Permission).InsertOneAsync(entity); |  | ||||||
|                 entity.Id = (entity as dynamic ?? "").Id.ToString(); |  | ||||||
|  |  | ||||||
|                 return entity; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"CreatePermissionService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets an Permission by identifier. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="id">The Permission identifier.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns>0 |  | ||||||
|         public async Task<PermissionAdapter> GetPermissionByIdService(string id) |  | ||||||
|         { |  | ||||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetPermissionByIdService", id); |  | ||||||
|             var cachedData = await cacheService.GetAsync<PermissionAdapter>(cacheKey); |  | ||||||
|  |  | ||||||
|             if (cachedData is not null) { return cachedData; } |  | ||||||
|  |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<PermissionAdapter>.Filter.And( |  | ||||||
|                     Builders<PermissionAdapter>.Filter.Eq("_id", ObjectId.Parse(id)), |  | ||||||
|                     Builders<PermissionAdapter>.Filter.Eq("status", StatusEnum.Active.ToString()) |  | ||||||
|                 ); |  | ||||||
|  |  | ||||||
|                 var permission = await database.GetCollection<PermissionAdapter>(CollectionNames.Permission) |  | ||||||
|                                     .Find(filter) |  | ||||||
|                                     .FirstOrDefaultAsync(); |  | ||||||
|  |  | ||||||
|                 var cacheDuration = CacheHelper.GetCacheDuration(_cacheSettings); |  | ||||||
|  |  | ||||||
|                 await cacheService.SetAsync(cacheKey, permission, cacheDuration); |  | ||||||
|  |  | ||||||
|                 return permission; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"GetPermissionByIdService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets all the permissions. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <returns>A <see cref="{Task{IEnumerbale{PermissionAdapter}}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<IEnumerable<PermissionAdapter>> GetAllPermissionsService() |  | ||||||
|         { |  | ||||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllPermissionsService"); |  | ||||||
|             var cachedData = await cacheService.GetAsync<IEnumerable<PermissionAdapter>>(cacheKey) ?? []; |  | ||||||
|  |  | ||||||
|             if (cachedData.Any()) return cachedData; |  | ||||||
|  |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<PermissionAdapter>.Filter.Eq("status", StatusEnum.Active.ToString()); |  | ||||||
|  |  | ||||||
|                 var roles = await database.GetCollection<PermissionAdapter>(CollectionNames.Permission) |  | ||||||
|                                     .Find(filter) |  | ||||||
|                                     .ToListAsync(); |  | ||||||
|  |  | ||||||
|                 var cacheDuration = CacheHelper.GetCacheDuration(_cacheSettings); |  | ||||||
|  |  | ||||||
|                 await cacheService.SetAsync(cacheKey, roles, cacheDuration); |  | ||||||
|  |  | ||||||
|                 return roles; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"GetAllPermissionsService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets all the permissions by permissions identifier list. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="permissions">The list of permissions identifiers.</param> |  | ||||||
|         /// <returns>A <see cref="Task{IEnumerable{PermissionAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<IEnumerable<PermissionAdapter>> GetAllPermissionsByListService(string[] permissions) |  | ||||||
|         { |  | ||||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllPermissionsByListService", permissions); |  | ||||||
|  |  | ||||||
|             var cachedData = await cacheService.GetAsync<IEnumerable<PermissionAdapter>>(cacheKey); |  | ||||||
|  |  | ||||||
|             if (cachedData != null && cachedData.Any()) return cachedData; |  | ||||||
|  |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var objectIds = permissions.Select(id => ObjectId.Parse(id)).ToArray(); |  | ||||||
|  |  | ||||||
|                 var filter = Builders<PermissionAdapter>.Filter.In("_id", objectIds) |  | ||||||
|                                 & Builders<PermissionAdapter>.Filter.Eq("status", StatusEnum.Active.ToString()); |  | ||||||
|  |  | ||||||
|                 var roles = await database.GetCollection<PermissionAdapter>(CollectionNames.Permission) |  | ||||||
|                                           .Find(filter) |  | ||||||
|                                           .ToListAsync(); |  | ||||||
|  |  | ||||||
|                 var cacheDuration = CacheHelper.GetCacheDuration(_cacheSettings); |  | ||||||
|  |  | ||||||
|                 await cacheService.SetAsync(cacheKey, roles, cacheDuration); |  | ||||||
|  |  | ||||||
|                 return roles; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"GetAllPermissionsByListService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Changes the status of the permission. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="id">The permission identifier.</param> |  | ||||||
|         /// <param name="newStatus">The new status of the permission.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<PermissionAdapter> ChangePermissionStatusService(string id, StatusEnum newStatus) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<PermissionAdapter>.Filter |  | ||||||
|                     .Eq("_id", ObjectId.Parse(id)); |  | ||||||
|  |  | ||||||
|                 var update = Builders<PermissionAdapter>.Update |  | ||||||
|                             .Set(v => v.Status, newStatus) |  | ||||||
|                             .Set(v => v.UpdatedBy, Helper.GetEmail(httpContextAccessor)) |  | ||||||
|                             .Set(v => v.UpdatedAt, DateTime.UtcNow); |  | ||||||
|  |  | ||||||
|                 await database.GetCollection<PermissionAdapter>(CollectionNames.Permission).UpdateOneAsync(filter, update); |  | ||||||
|  |  | ||||||
|                 var updatedPermission = await database.GetCollection<PermissionAdapter>(CollectionNames.Permission) |  | ||||||
|                                     .Find(filter) |  | ||||||
|                                     .FirstOrDefaultAsync(); |  | ||||||
|  |  | ||||||
|                 return updatedPermission; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"ChangePermissionStatusService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Updates a Permission by id. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="entity">The Permission to be updated.</param> |  | ||||||
|         /// <param name="id">The Permission identifier.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<PermissionAdapter> UpdatePermissionService(PermissionAdapter entity, string id) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<PermissionAdapter>.Filter |  | ||||||
|                     .Eq("_id", ObjectId.Parse(id)); |  | ||||||
|  |  | ||||||
|                 var update = Builders<PermissionAdapter>.Update |  | ||||||
|                             .Set(v => v.Name, entity.Name) |  | ||||||
|                             .Set(v => v.Description, entity.Description) |  | ||||||
|                             .Set(v => v.AccessLevel, entity.AccessLevel) |  | ||||||
|                             .Set(v => v.Status, entity.Status) |  | ||||||
|                             .Set(v => v.UpdatedBy, Helper.GetEmail(httpContextAccessor)) |  | ||||||
|                             .Set(v => v.UpdatedAt, DateTime.UtcNow); |  | ||||||
|  |  | ||||||
|                 await database.GetCollection<PermissionAdapter>(CollectionNames.Permission).UpdateOneAsync(filter, update); |  | ||||||
|  |  | ||||||
|                 var updatedPermission = await database.GetCollection<PermissionAdapter>(CollectionNames.Permission) |  | ||||||
|                                             .Find(filter) |  | ||||||
|                                             .FirstOrDefaultAsync(); |  | ||||||
|  |  | ||||||
|                 return updatedPermission; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"UpdatePermissionService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,251 +0,0 @@ | |||||||
| // *********************************************************************** |  | ||||||
| // <copyright file="RoleService.cs"> |  | ||||||
| //     AgileWebs |  | ||||||
| // </copyright> |  | ||||||
| // *********************************************************************** |  | ||||||
| using Core.Cerberos.Adapters; |  | ||||||
| using Core.Cerberos.Adapters.Common.Constants; |  | ||||||
| using Core.Cerberos.Adapters.Common.Enums; |  | ||||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Mappers; |  | ||||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; |  | ||||||
| using Core.Cerberos.Infraestructure.Caching.Configs; |  | ||||||
| using Core.Cerberos.Infraestructure.Caching.Contracts; |  | ||||||
| using Core.Cerberos.Provider.Contracts; |  | ||||||
| using LSA.Core.Dapper.Service.Caching; |  | ||||||
| using Microsoft.AspNetCore.Http; |  | ||||||
| using Microsoft.Extensions.Logging; |  | ||||||
| using Microsoft.Extensions.Options; |  | ||||||
| using MongoDB.Bson; |  | ||||||
| using MongoDB.Driver; |  | ||||||
|  |  | ||||||
| namespace Core.Cerberos.Provider.Providers.Onboarding |  | ||||||
| { |  | ||||||
|     /// <summary> |  | ||||||
|     /// Handles all services and business rules related to <see cref="RoleAdapter"/>. |  | ||||||
|     /// </summary> |  | ||||||
|     public class RoleService(ILogger<RoleService> logger, IHttpContextAccessor httpContextAccessor, ICacheService cacheService, |  | ||||||
|         IOptions<CacheSettings> cacheSettings, IMongoDatabase database) : IRoleService |  | ||||||
|     { |  | ||||||
|         private readonly CacheSettings _cacheSettings = cacheSettings.Value; |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Creates a new Role. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="entity">The Role to be created.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<RoleAdapter> CreateRoleService(RoleRequest newRole) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var entity = newRole.ToAdapter(httpContextAccessor); |  | ||||||
|                 await database.GetCollection<RoleAdapter>(CollectionNames.Role).InsertOneAsync(entity); |  | ||||||
|                 entity.Id = (entity as dynamic ?? "").Id.ToString(); |  | ||||||
|  |  | ||||||
|                 return entity; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"CreateRoleService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets an Role by identifier. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="id">The Role identifier.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<RoleAdapter> GetRoleByIdService(string id) |  | ||||||
|         { |  | ||||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetRoleByIdService", id); |  | ||||||
|             var cachedData = await cacheService.GetAsync<RoleAdapter>(cacheKey); |  | ||||||
|  |  | ||||||
|             if (cachedData is not null) { return cachedData; } |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<RoleAdapter>.Filter.And( |  | ||||||
|                         Builders<RoleAdapter>.Filter.Eq("_id", ObjectId.Parse(id)), |  | ||||||
|                         Builders<RoleAdapter>.Filter.Eq("status", StatusEnum.Active.ToString()) |  | ||||||
|                     ); |  | ||||||
|  |  | ||||||
|                 var role = await database.GetCollection<RoleAdapter>(CollectionNames.Role) |  | ||||||
|                 .Find(filter) |  | ||||||
|                             .FirstOrDefaultAsync(); |  | ||||||
|  |  | ||||||
|                 var cacheDuration = CacheHelper.GetCacheDuration(_cacheSettings); |  | ||||||
|  |  | ||||||
|                 await cacheService.SetAsync(cacheKey, role, cacheDuration); |  | ||||||
|  |  | ||||||
|                 return role; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"GetRoleByIdService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets all the roles. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <returns>A <see cref="{Task{IEnumerbale{RoleAdapter}}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<IEnumerable<RoleAdapter>> GetAllRolesService() |  | ||||||
|         { |  | ||||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllRolesService"); |  | ||||||
|             var cachedData = await cacheService.GetAsync<IEnumerable<RoleAdapter>>(cacheKey) ?? []; |  | ||||||
|  |  | ||||||
|             if (cachedData.Any()) return cachedData; |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<RoleAdapter>.Filter.Eq("status", StatusEnum.Active.ToString()); |  | ||||||
|  |  | ||||||
|                 var roles = await database.GetCollection<RoleAdapter>(CollectionNames.Role) |  | ||||||
|                                 .Find(filter) |  | ||||||
|                                 .ToListAsync(); |  | ||||||
|  |  | ||||||
|                 var cacheDuration = CacheHelper.GetCacheDuration(_cacheSettings); |  | ||||||
|  |  | ||||||
|                 await cacheService.SetAsync(cacheKey, roles, cacheDuration); |  | ||||||
|  |  | ||||||
|                 return roles; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"GetAllRolesService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Changes the status of the role. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="id">The role identifier.</param> |  | ||||||
|         /// <param name="newStatus">The new status of the role.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<RoleAdapter> ChangeRoleStatusService(string id, StatusEnum newStatus) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<RoleAdapter>.Filter |  | ||||||
|                     .Eq("_id", ObjectId.Parse(id)); |  | ||||||
|  |  | ||||||
|                 var update = Builders<RoleAdapter>.Update |  | ||||||
|                             .Set(v => v.Status, newStatus) |  | ||||||
|                             .Set(v => v.UpdatedBy, Helper.GetEmail(httpContextAccessor)) |  | ||||||
|                             .Set(v => v.UpdatedAt, DateTime.UtcNow); |  | ||||||
|  |  | ||||||
|                 await database.GetCollection<RoleAdapter>(CollectionNames.Role).UpdateOneAsync(filter, update); |  | ||||||
|  |  | ||||||
|                 var updatedRole = await database.GetCollection<RoleAdapter>(CollectionNames.Role) |  | ||||||
|                                     .Find(filter) |  | ||||||
|                                     .FirstOrDefaultAsync(); |  | ||||||
|  |  | ||||||
|                 return updatedRole; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"ChangeRoleStatusService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Updates a Role by id. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="entity">The Role to be updated.</param> |  | ||||||
|         /// <param name="id">The Role identifier.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<RoleAdapter> UpdateRoleService(RoleAdapter entity, string id) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<RoleAdapter>.Filter |  | ||||||
|                     .Eq("_id", ObjectId.Parse(id)); |  | ||||||
|  |  | ||||||
|                 var update = Builders<RoleAdapter>.Update |  | ||||||
|                             .Set(v => v.Name, entity.Name) |  | ||||||
|                             .Set(v => v.Description, entity.Description) |  | ||||||
|                             .Set(v => v.Applications, entity.Applications) |  | ||||||
|                             .Set(v => v.Modules, entity.Modules) |  | ||||||
|                             .Set(v => v.Permissions, entity.Permissions) |  | ||||||
|                             .Set(v => v.Status, entity.Status) |  | ||||||
|                             .Set(v => v.UpdatedBy, Helper.GetEmail(httpContextAccessor)) |  | ||||||
|                             .Set(v => v.UpdatedAt, DateTime.UtcNow); |  | ||||||
|  |  | ||||||
|                 await database.GetCollection<RoleAdapter>(CollectionNames.Role).UpdateOneAsync(filter, update); |  | ||||||
|  |  | ||||||
|                 var updatedRole = await database.GetCollection<RoleAdapter>(CollectionNames.Role) |  | ||||||
|                                     .Find(filter) |  | ||||||
|                                     .FirstOrDefaultAsync(); |  | ||||||
|  |  | ||||||
|                 return updatedRole; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"UpdateRoleService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Adds an application to the role's list of applications. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="roleId">The identifier of the role to which the application will be added.</param> |  | ||||||
|         /// <param name="application">The application enum value to add.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing the asynchronous operation, with the updated role object.</returns> |  | ||||||
|         public async Task<RoleAdapter> AddApplicationToRoleService(string roleId, ApplicationsEnum application) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<RoleAdapter>.Filter.Eq("_id", ObjectId.Parse(roleId)); |  | ||||||
|                 var update = Builders<RoleAdapter>.Update.AddToSet(r => r.Applications, application); |  | ||||||
|  |  | ||||||
|                 await database.GetCollection<RoleAdapter>(CollectionNames.Role).UpdateOneAsync(filter, update); |  | ||||||
|  |  | ||||||
|                 var updatedRole = await database.GetCollection<RoleAdapter>(CollectionNames.Role) |  | ||||||
|                                     .Find(filter) |  | ||||||
|                                     .FirstOrDefaultAsync(); |  | ||||||
|                 return updatedRole; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"AddApplicationToRoleService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Removes an application from the role's list of applications. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="roleId">The identifier of the role from which the application will be removed.</param> |  | ||||||
|         /// <param name="application">The application enum value to remove.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing the asynchronous operation, with the updated role object.</returns> |  | ||||||
|         public async Task<RoleAdapter> RemoveApplicationFromRoleService(string roleId, ApplicationsEnum application) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<RoleAdapter>.Filter.Eq("_id", ObjectId.Parse(roleId)); |  | ||||||
|                 var update = Builders<RoleAdapter>.Update.Pull(r => r.Applications, application); |  | ||||||
|  |  | ||||||
|                 await database.GetCollection<RoleAdapter>(CollectionNames.Role).UpdateOneAsync(filter, update); |  | ||||||
|  |  | ||||||
|                 var updatedRole = await database.GetCollection<RoleAdapter>(CollectionNames.Role) |  | ||||||
|                                     .Find(filter) |  | ||||||
|                                     .FirstOrDefaultAsync(); |  | ||||||
|                 return updatedRole; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"RemoveApplicationFromRoleService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,627 +0,0 @@ | |||||||
| // *********************************************************************** |  | ||||||
| // <copyright file="UserService.cs"> |  | ||||||
| //     AgileWebs |  | ||||||
| // </copyright> |  | ||||||
| // *********************************************************************** |  | ||||||
|  |  | ||||||
| using Core.Cerberos.Adapters; |  | ||||||
| using Core.Cerberos.Adapters.Common.Constants; |  | ||||||
| using Core.Cerberos.Adapters.Common.Enums; |  | ||||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Mappers; |  | ||||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; |  | ||||||
| using Core.Cerberos.Infraestructure.Caching.Configs; |  | ||||||
| using Core.Cerberos.Infraestructure.Caching.Contracts; |  | ||||||
| using Core.Cerberos.Provider.Contracts; |  | ||||||
| using LSA.Core.Dapper.Service.Caching; |  | ||||||
| using Microsoft.AspNetCore.Http; |  | ||||||
| using Microsoft.Extensions.Logging; |  | ||||||
| using Microsoft.Extensions.Options; |  | ||||||
| using MongoDB.Bson; |  | ||||||
| using MongoDB.Bson.Serialization; |  | ||||||
| using MongoDB.Driver; |  | ||||||
| using System.Text.RegularExpressions; |  | ||||||
| using Core.Blueprint.Storage.Contracts; |  | ||||||
| using Core.Blueprint.Storage.Adapters; |  | ||||||
|  |  | ||||||
| namespace Core.Cerberos.Provider.Providers.Onboarding |  | ||||||
| { |  | ||||||
|     /// <summary> |  | ||||||
|     /// Handles all services and business rules related to <see cref="UserAdapter"/>. |  | ||||||
|     /// </summary> |  | ||||||
|     public class UserService(ILogger<UserService> logger, IHttpContextAccessor httpContextAccessor, ICacheService cacheService, |  | ||||||
|         IOptions<CacheSettings> cacheSettings, IMongoDatabase database, IBlobStorageProvider blobStorageProvider) : IUserService |  | ||||||
|     { |  | ||||||
|         private readonly CacheSettings _cacheSettings = cacheSettings.Value; |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Creates a new User. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="newUser">The User to be created.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<UserAdapter> CreateUserService(UserRequest newUser) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var entity = newUser.ToAdapter(httpContextAccessor); |  | ||||||
|                 await database.GetCollection<UserAdapter>(CollectionNames.User).InsertOneAsync(entity); |  | ||||||
|                 entity.Id = (entity as dynamic ?? "").Id.ToString(); |  | ||||||
|  |  | ||||||
|                 return entity; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"CreateUserService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets an User by identifier. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="id">The User identifier.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<UserAdapter> GetUserByIdService(string id) |  | ||||||
|         { |  | ||||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetUserByIdService", id); |  | ||||||
|             var cachedData = await cacheService.GetAsync<UserAdapter>(cacheKey); |  | ||||||
|  |  | ||||||
|             if (cachedData is not null) return cachedData; |  | ||||||
|  |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<UserAdapter>.Filter.And( |  | ||||||
|                     Builders<UserAdapter>.Filter.Eq("_id", ObjectId.Parse(id)), |  | ||||||
|                     Builders<UserAdapter>.Filter.Eq("status", StatusEnum.Active.ToString()) |  | ||||||
|                 ); |  | ||||||
|  |  | ||||||
|                 var user = await database.GetCollection<UserAdapter>(CollectionNames.User) |  | ||||||
|                             .Find(filter) |  | ||||||
|                             .FirstOrDefaultAsync(); |  | ||||||
|  |  | ||||||
|                 var cacheDuration = CacheHelper.GetCacheDuration(_cacheSettings); |  | ||||||
|  |  | ||||||
|                 await cacheService.SetAsync(cacheKey, user, cacheDuration); |  | ||||||
|  |  | ||||||
|                 return user; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"GetUserByIdService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets all the users. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <returns>A <see cref="{Task{IEnumerable{UserAdapter}}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<IEnumerable<UserAdapter>> GetAllUsersService() |  | ||||||
|         { |  | ||||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllUsersService"); |  | ||||||
|             var cachedData = await cacheService.GetAsync<IEnumerable<UserAdapter>>(cacheKey) ?? []; |  | ||||||
|  |  | ||||||
|             if (cachedData.Any()) return cachedData; |  | ||||||
|  |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<UserAdapter>.Filter.Eq("status", StatusEnum.Active.ToString()); |  | ||||||
|  |  | ||||||
|                 var users = await database.GetCollection<UserAdapter>(CollectionNames.User) |  | ||||||
|                             .Find(filter) |  | ||||||
|                             .ToListAsync(); |  | ||||||
|  |  | ||||||
|                 var cacheDuration = CacheHelper.GetCacheDuration(_cacheSettings); |  | ||||||
|                 await cacheService.SetAsync(cacheKey, users, cacheDuration); |  | ||||||
|  |  | ||||||
|                 return users; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"GetAllUsersService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets an User by email. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="email">The User email.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<UserAdapter> GetUserByEmailService(string? email) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<UserAdapter>.Filter.And( |  | ||||||
|                     Builders<UserAdapter>.Filter.Regex("email", new BsonRegularExpression($"^{Regex.Escape(email ?? "")}$", "i")), |  | ||||||
|                     Builders<UserAdapter>.Filter.Eq("status", StatusEnum.Active.ToString()) |  | ||||||
|                 ); |  | ||||||
|  |  | ||||||
|                 var user = await database.GetCollection<UserAdapter>(CollectionNames.User) |  | ||||||
|                             .Find(filter) |  | ||||||
|                             .FirstOrDefaultAsync(); |  | ||||||
|  |  | ||||||
|                 return user; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"GetUserByEmailService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Validates if a users exists by email.. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="email">The User email.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<UserAdapter> ValidateUserExistenceService(string? email) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<UserAdapter>.Filter.And( |  | ||||||
|                     Builders<UserAdapter>.Filter.Regex("email", new BsonRegularExpression($"^{Regex.Escape(email ?? "")}$", "i")), |  | ||||||
|                     Builders<UserAdapter>.Filter.Eq("status", StatusEnum.Active.ToString()) |  | ||||||
|                 ); |  | ||||||
|  |  | ||||||
|                 var user = await database.GetCollection<UserAdapter>(CollectionNames.User) |  | ||||||
|                             .Find(filter) |  | ||||||
|                             .FirstOrDefaultAsync(); |  | ||||||
|  |  | ||||||
|                 return user; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"ValidateUserExistenceService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Deletes an User by id. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="id">The User identifier.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<UserAdapter> DeleteUserService(string id) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<UserAdapter>.Filter |  | ||||||
|                     .Eq("_id", ObjectId.Parse(id)); |  | ||||||
|  |  | ||||||
|                 var update = Builders<UserAdapter>.Update |  | ||||||
|                             .Set(v => v.Status, StatusEnum.Inactive); |  | ||||||
|  |  | ||||||
|                 await database.GetCollection<UserAdapter>(CollectionNames.User).UpdateOneAsync(filter, update); |  | ||||||
|  |  | ||||||
|                 var deletedUser = await database.GetCollection<UserAdapter>(CollectionNames.User).Find(filter).FirstAsync(); |  | ||||||
|  |  | ||||||
|                 return deletedUser; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"DeleteUserService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Changes the status of the user. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="id">The user identifier.</param> |  | ||||||
|         /// <param name="newStatus">The new status of the user.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<UserAdapter> ChangeUserStatusService(string id, StatusEnum newStatus) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<UserAdapter>.Filter |  | ||||||
|                     .Eq("_id", ObjectId.Parse(id)); |  | ||||||
|  |  | ||||||
|                 var update = Builders<UserAdapter>.Update |  | ||||||
|                             .Set(v => v.Status, newStatus) |  | ||||||
|                             .Set(v => v.UpdatedBy, Helper.GetEmail(httpContextAccessor)) |  | ||||||
|                             .Set(v => v.UpdatedAt, DateTime.UtcNow); |  | ||||||
|  |  | ||||||
|                 await database.GetCollection<UserAdapter>(CollectionNames.User).UpdateOneAsync(filter, update); |  | ||||||
|  |  | ||||||
|                 var updatedUser = await database.GetCollection<UserAdapter>(CollectionNames.User) |  | ||||||
|                                     .Find(filter) |  | ||||||
|                                     .FirstOrDefaultAsync(); |  | ||||||
|  |  | ||||||
|                 return updatedUser; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"ChangeUserStatusService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Updates a User by id. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="entity">The User to be updated.</param> |  | ||||||
|         /// <param name="id">The User identifier.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<UserAdapter> UpdateUserService(UserAdapter entity, string id) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<UserAdapter>.Filter |  | ||||||
|                     .Eq("_id", ObjectId.Parse(id)); |  | ||||||
|  |  | ||||||
|                 var update = Builders<UserAdapter>.Update |  | ||||||
|                             .Set(v => v.Email, entity.Email) |  | ||||||
|                             .Set(v => v.Name, entity.Name) |  | ||||||
|                             .Set(v => v.MiddleName, entity.MiddleName) |  | ||||||
|                             .Set(v => v.LastName, entity.LastName) |  | ||||||
|                             .Set(v => v.DisplayName, $"{entity.Name} {entity.MiddleName} {entity.LastName}") |  | ||||||
|                             .Set(v => v.RoleId, entity.RoleId) |  | ||||||
|                             .Set(v => v.Companies, entity.Companies) |  | ||||||
|                             .Set(v => v.Projects, entity.Projects) |  | ||||||
|                             .Set(v => v.Status, entity.Status) |  | ||||||
|                             .Set(v => v.UpdatedBy, Helper.GetEmail(httpContextAccessor)) |  | ||||||
|                             .Set(v => v.UpdatedAt, DateTime.UtcNow); |  | ||||||
|  |  | ||||||
|                 await database.GetCollection<UserAdapter>(CollectionNames.User).UpdateOneAsync(filter, update); |  | ||||||
|  |  | ||||||
|                 var updatedUser = await GetUserByIdService(id); |  | ||||||
|  |  | ||||||
|                 return updatedUser; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"UpdateUserService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Logs in the user. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="id">The User identifier.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<UserAdapter?> LogInUserService(string email) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<UserAdapter>.Filter |  | ||||||
|                     .Regex("email", new BsonRegularExpression($"^{Regex.Escape(email ?? "")}$", "i")); |  | ||||||
|  |  | ||||||
|                 var update = Builders<UserAdapter>.Update |  | ||||||
|                             .Set(v => v.LastLogIn, DateTime.UtcNow); |  | ||||||
|  |  | ||||||
|                 await database.GetCollection<UserAdapter>(CollectionNames.User).UpdateOneAsync(filter, update); |  | ||||||
|  |  | ||||||
|                 var user = await database.GetCollection<UserAdapter>(CollectionNames.User) |  | ||||||
|                                     .Find(filter) |  | ||||||
|                                     .FirstAsync(); |  | ||||||
|  |  | ||||||
|                 return user; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"LogInUserService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Logs out the user's session. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="email">The User email.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<UserAdapter> LogOutUserSessionService(string email) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<UserAdapter>.Filter |  | ||||||
|                     .Regex("email", new BsonRegularExpression($"^{Regex.Escape(email ?? "")}$", "i")); |  | ||||||
|  |  | ||||||
|  |  | ||||||
|                 var update = Builders<UserAdapter>.Update |  | ||||||
|                             .Set(v => v.LastLogOut, DateTime.UtcNow); |  | ||||||
|  |  | ||||||
|                 await database.GetCollection<UserAdapter>(CollectionNames.User).UpdateOneAsync(filter, update); |  | ||||||
|  |  | ||||||
|                 var user = await database.GetCollection<UserAdapter>(CollectionNames.User) |  | ||||||
|                                     .Find(filter) |  | ||||||
|                                     .FirstAsync(); |  | ||||||
|  |  | ||||||
|                 return user; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"LogOutUserSessionService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Adds a company to the user's list of companies. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="userId">The identifier of the user to whom the company will be added.</param> |  | ||||||
|         /// <param name="companyId">The identifier of the company to add.</param> |  | ||||||
|         /// <returns>A <see cref="Task{UserAdapter}"/> representing the asynchronous operation, with the updated user object.</returns> |  | ||||||
|         public async Task<UserAdapter> AddCompanyToUserService(string userId, string companyId) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<UserAdapter>.Filter.Eq("_id", ObjectId.Parse(userId)); |  | ||||||
|                 var update = Builders<UserAdapter>.Update.AddToSet(v => v.Companies, companyId); |  | ||||||
|  |  | ||||||
|                 await database.GetCollection<UserAdapter>(CollectionNames.User).UpdateOneAsync(filter, update); |  | ||||||
|  |  | ||||||
|                 var updatedUser = await database.GetCollection<UserAdapter>(CollectionNames.User) |  | ||||||
|                                     .Find(filter) |  | ||||||
|                                     .FirstOrDefaultAsync(); |  | ||||||
|                 return updatedUser; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"AddCompanyToUserService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Removes a company from the user's list of companies. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="userId">The identifier of the user from whom the company will be removed.</param> |  | ||||||
|         /// <param name="companyId">The identifier of the company to remove.</param> |  | ||||||
|         /// <returns>A <see cref="Task{UserAdapter}"/> representing the asynchronous operation, with the updated user object.</returns> |  | ||||||
|         public async Task<UserAdapter> RemoveCompanyFromUserService(string userId, string companyId) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<UserAdapter>.Filter.Eq("_id", ObjectId.Parse(userId)); |  | ||||||
|                 var update = Builders<UserAdapter>.Update.Pull(v => v.Companies, companyId); |  | ||||||
|  |  | ||||||
|                 await database.GetCollection<UserAdapter>(CollectionNames.User).UpdateOneAsync(filter, update); |  | ||||||
|  |  | ||||||
|                 var updatedUser = await database.GetCollection<UserAdapter>(CollectionNames.User) |  | ||||||
|                                     .Find(filter) |  | ||||||
|                                     .FirstOrDefaultAsync(); |  | ||||||
|                 return updatedUser; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"RemoveCompanyFromUserService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Adds a project to the user's list of projects. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="userId">The identifier of the user to whom the project will be added.</param> |  | ||||||
|         /// <param name="projectId">The identifier of the project to add.</param> |  | ||||||
|         /// <returns>A <see cref="Task{UserAdapter}"/> representing the asynchronous operation, with the updated user object.</returns> |  | ||||||
|         public async Task<UserAdapter> AddProjectToUserService(string userId, string projectId) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<UserAdapter>.Filter.Eq("_id", ObjectId.Parse(userId)); |  | ||||||
|                 var update = Builders<UserAdapter>.Update.AddToSet(v => v.Projects, projectId); |  | ||||||
|  |  | ||||||
|                 await database.GetCollection<UserAdapter>(CollectionNames.User).UpdateOneAsync(filter, update); |  | ||||||
|  |  | ||||||
|                 var updatedUser = await database.GetCollection<UserAdapter>(CollectionNames.User) |  | ||||||
|                                      .Find(filter) |  | ||||||
|                                      .FirstOrDefaultAsync(); |  | ||||||
|                 return updatedUser; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"AddProjectToUserService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Removes a project from the user's list of projects. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="userId">The identifier of the user from whom the project will be removed.</param> |  | ||||||
|         /// <param name="projectId">The identifier of the project to remove.</param> |  | ||||||
|         /// <returns>A <see cref="Task{UserAdapter}"/> representing the asynchronous operation, with the updated user object.</returns> |  | ||||||
|         public async Task<UserAdapter> RemoveProjectFromUserService(string userId, string projectId) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<UserAdapter>.Filter.Eq("_id", ObjectId.Parse(userId)); |  | ||||||
|                 var update = Builders<UserAdapter>.Update.Pull(v => v.Projects, projectId); |  | ||||||
|  |  | ||||||
|                 await database.GetCollection<UserAdapter>(CollectionNames.User).UpdateOneAsync(filter, update); |  | ||||||
|  |  | ||||||
|                 var updatedUser = await database.GetCollection<UserAdapter>(CollectionNames.User) |  | ||||||
|                                     .Find(filter) |  | ||||||
|                                     .FirstOrDefaultAsync(); |  | ||||||
|                 return updatedUser; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"RemoveProjectFromUserService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets the token adapter for a user. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="email">The user's email.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{TokenAdapter}}"/> representing the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<TokenAdapter?> GetTokenAdapter(string email) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var pipeline = new[] |  | ||||||
|                 { |  | ||||||
|                     new BsonDocument("$match", new BsonDocument |  | ||||||
|                     { |  | ||||||
|                         { "email", new BsonDocument |  | ||||||
|                             { |  | ||||||
|                                 { "$regex", $"^{Regex.Escape(email)}$" }, |  | ||||||
|                                 { "$options", "i" } |  | ||||||
|                             } |  | ||||||
|                         }, |  | ||||||
|                         { "status", StatusEnum.Active.ToString() } |  | ||||||
|                     }), |  | ||||||
|  |  | ||||||
|                     new BsonDocument("$lookup", new BsonDocument |  | ||||||
|                     { |  | ||||||
|                         { "from", "Roles" }, |  | ||||||
|                         { "localField", "roleId" }, |  | ||||||
|                         { "foreignField", "_id" }, |  | ||||||
|                         { "as", "role" } |  | ||||||
|                     }), |  | ||||||
|  |  | ||||||
|                     new BsonDocument("$unwind", "$role"), |  | ||||||
|                     new BsonDocument("$match", new BsonDocument("role.status", StatusEnum.Active.ToString())), |  | ||||||
|  |  | ||||||
|                     new BsonDocument("$addFields", new BsonDocument |  | ||||||
|                     { |  | ||||||
|                         { "role.permissions", new BsonDocument("$map", new BsonDocument |  | ||||||
|                             { |  | ||||||
|                                 { "input", "$role.permissions" }, |  | ||||||
|                                 { "as", "perm" }, |  | ||||||
|                                 { "in", new BsonDocument("$toObjectId", "$$perm") } |  | ||||||
|                             }) |  | ||||||
|                         }, |  | ||||||
|                         { "role.modules", new BsonDocument("$map", new BsonDocument |  | ||||||
|                             { |  | ||||||
|                                 { "input", "$role.modules" }, |  | ||||||
|                                 { "as", "mod" }, |  | ||||||
|                                 { "in", new BsonDocument("$toObjectId", "$$mod") } |  | ||||||
|                             }) |  | ||||||
|                         } |  | ||||||
|                     }), |  | ||||||
|  |  | ||||||
|                     new BsonDocument("$lookup", new BsonDocument |  | ||||||
|                     { |  | ||||||
|                         { "from", "Permissions" }, |  | ||||||
|                         { "localField", "role.permissions" }, |  | ||||||
|                         { "foreignField", "_id" }, |  | ||||||
|                         { "as", "permissions" } |  | ||||||
|                     }), |  | ||||||
|                     new BsonDocument("$lookup", new BsonDocument |  | ||||||
|                     { |  | ||||||
|                         { "from", "Modules" }, |  | ||||||
|                         { "localField", "role.modules" }, |  | ||||||
|                         { "foreignField", "_id" }, |  | ||||||
|                         { "as", "modules" } |  | ||||||
|                     }), |  | ||||||
|                     new BsonDocument("$project", new BsonDocument |  | ||||||
|                     { |  | ||||||
|                         { "_id", 1 }, |  | ||||||
|                         { "guid", 1 }, |  | ||||||
|                         { "email", 1 }, |  | ||||||
|                         { "name", 1 }, |  | ||||||
|                         { "middleName", 1 }, |  | ||||||
|                         { "lastName", 1 }, |  | ||||||
|                         { "displayName", 1 }, |  | ||||||
|                         { "roleId", 1 }, |  | ||||||
|                         { "companies", 1 }, |  | ||||||
|                         { "projects", 1 }, |  | ||||||
|                         { "lastLogIn", 1 }, |  | ||||||
|                         { "lastLogOut", 1 }, |  | ||||||
|                         { "createdBy", 1 }, |  | ||||||
|                         { "updatedBy", 1 }, |  | ||||||
|                         { "status", 1 }, |  | ||||||
|                         { "createdAt", 1 }, |  | ||||||
|                         { "updatedAt", 1 }, |  | ||||||
|                         { "role._id", 1 }, |  | ||||||
|                         { "role.name", 1 }, |  | ||||||
|                         { "role.description", 1 }, |  | ||||||
|                         { "role.applications", 1 }, |  | ||||||
|                         { "role.permissions", 1 }, |  | ||||||
|                         { "role.modules", 1 }, |  | ||||||
|                         { "role.status", 1 }, |  | ||||||
|                         { "role.createdAt", 1 }, |  | ||||||
|                         { "role.updatedAt", 1 }, |  | ||||||
|                         { "role.createdBy", 1 }, |  | ||||||
|                         { "role.updatedBy", 1 }, |  | ||||||
|                         { "permissions", 1 }, |  | ||||||
|                         { "modules", 1 } |  | ||||||
|                     }) |  | ||||||
|                 }; |  | ||||||
|  |  | ||||||
|  |  | ||||||
|                 var result = await database.GetCollection<BsonDocument>(CollectionNames.User) |  | ||||||
|                     .Aggregate<BsonDocument>(pipeline) |  | ||||||
|                     .FirstOrDefaultAsync(); |  | ||||||
|  |  | ||||||
|                 if (result is null) return null; |  | ||||||
|  |  | ||||||
|                 var tokenAdapter = new TokenAdapter |  | ||||||
|                 { |  | ||||||
|                     User = new UserAdapter |  | ||||||
|                     { |  | ||||||
|                         Id = result["_id"]?.ToString() ?? "", |  | ||||||
|                         Guid = result["guid"].AsString, |  | ||||||
|                         Email = result["email"].AsString, |  | ||||||
|                         Name = result["name"].AsString, |  | ||||||
|                         MiddleName = result["middleName"].AsString, |  | ||||||
|                         LastName = result["lastName"].AsString, |  | ||||||
|                         DisplayName = result["displayName"].AsString, |  | ||||||
|                         RoleId = result["roleId"]?.ToString() ?? "", |  | ||||||
|                         Companies = result["companies"].AsBsonArray |  | ||||||
|                             .Select(c => c.AsString) |  | ||||||
|                             .ToArray(), |  | ||||||
|                         Projects = result["projects"].AsBsonArray |  | ||||||
|                             .Select(c => c.AsString) |  | ||||||
|                             .ToArray(), |  | ||||||
|                         LastLogIn = result["lastLogIn"].ToUniversalTime(), |  | ||||||
|                         LastLogOut = result["lastLogOut"].ToUniversalTime(), |  | ||||||
|                         CreatedAt = result["createdAt"].ToUniversalTime(), |  | ||||||
|                         CreatedBy = result["createdBy"].AsString, |  | ||||||
|                         UpdatedAt = result["updatedAt"].ToUniversalTime(), |  | ||||||
|                         UpdatedBy = result["updatedBy"].AsString, |  | ||||||
|                         Status = (StatusEnum)Enum.Parse(typeof(StatusEnum), result["status"].AsString), |  | ||||||
|                     }, |  | ||||||
|                     Role = new RoleAdapter |  | ||||||
|                     { |  | ||||||
|                         Id = result["role"]["_id"]?.ToString() ?? "", |  | ||||||
|                         Name = result["role"]["name"].AsString, |  | ||||||
|                         Description = result["role"]["description"].AsString, |  | ||||||
|                         Applications = result["role"]["applications"].AsBsonArray |  | ||||||
|                             .Select(c => (ApplicationsEnum)c.AsInt32) |  | ||||||
|                             .ToArray(), |  | ||||||
|                         Modules = result["role"]["modules"].AsBsonArray |  | ||||||
|                             .Select(c => c.ToString() ?? "") |  | ||||||
|                             .ToArray(), |  | ||||||
|                         Permissions = result["role"]["permissions"].AsBsonArray |  | ||||||
|                             .Select(c => c.ToString() ?? "") |  | ||||||
|                             .ToArray(), |  | ||||||
|                         Status = (StatusEnum)Enum.Parse(typeof(StatusEnum), result["role"]["status"].AsString), |  | ||||||
|                         CreatedAt = result["role"]["createdAt"].ToUniversalTime(), |  | ||||||
|                         UpdatedAt = result["role"]["updatedAt"].ToUniversalTime(), |  | ||||||
|                         CreatedBy = result["role"]["createdBy"].AsString, |  | ||||||
|                         UpdatedBy = result["role"]["updatedBy"].AsString |  | ||||||
|                     }, |  | ||||||
|                     Permissions = result["permissions"].AsBsonArray |  | ||||||
|                         .Select(permission => BsonSerializer.Deserialize<PermissionAdapter>(permission.AsBsonDocument)) |  | ||||||
|                         .Where(permission => permission.Status == StatusEnum.Active) |  | ||||||
|                         .ToList() |  | ||||||
|                 }; |  | ||||||
|  |  | ||||||
|                 return tokenAdapter; |  | ||||||
|  |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"GetTokenAdapter: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,104 +0,0 @@ | |||||||
| using Core.Blueprint.Storage.Configuration; |  | ||||||
| using Core.Cerberos.Infraestructure.Caching.Contracts; |  | ||||||
| using Core.Cerberos.Infraestructure.Contexts.Mongo; |  | ||||||
| using Core.Cerberos.Provider.Contracts; |  | ||||||
| using Core.Cerberos.Provider.Providers; |  | ||||||
| using Core.Cerberos.Provider.Providers.Onboarding; |  | ||||||
| using LSA.Core.Dapper.Service.Caching; |  | ||||||
| using Microsoft.Extensions.Configuration; |  | ||||||
| using Microsoft.Extensions.DependencyInjection; |  | ||||||
| using Microsoft.Extensions.Logging; |  | ||||||
| using Microsoft.Extensions.Options; |  | ||||||
| using MongoDB.Driver; |  | ||||||
|  |  | ||||||
| namespace Core.Cerberos.Provider |  | ||||||
| { |  | ||||||
|     public static class ServiceCollectionExtensions |  | ||||||
|     { |  | ||||||
|         public static IServiceCollection AddDALLayer(this IServiceCollection services, IConfiguration configuration) |  | ||||||
|         { |  | ||||||
|             var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? string.Empty; |  | ||||||
|  |  | ||||||
|             var connectionString = configuration.GetSection("ConnectionStrings:MongoDB").Value ?? string.Empty; |  | ||||||
|             var databaseName = configuration.GetSection("MongoDB:DatabaseName").Value ?? string.Empty; |  | ||||||
|             var audience = (environment == "Local") |  | ||||||
|                 ? configuration.GetSection("MongoDB:LocalAudience").Value |  | ||||||
|                 : configuration.GetSection("MongoDB:Audience").Value; |  | ||||||
|  |  | ||||||
|             if (string.IsNullOrEmpty(connectionString) || string.IsNullOrEmpty(databaseName) || string.IsNullOrEmpty(audience)) |  | ||||||
|             { |  | ||||||
|                 throw new InvalidOperationException("Mongo connection is not configured correctly."); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             services.Configure<MongoConnSettings>(options => |  | ||||||
|             { |  | ||||||
|                 options.ConnectionString = connectionString; |  | ||||||
|                 options.Databasename = databaseName; |  | ||||||
|                 options.Audience = audience ?? string.Empty; |  | ||||||
|             }); |  | ||||||
|  |  | ||||||
|             services.AddSingleton<IMongoClient>(serviceProvider => |  | ||||||
|             { |  | ||||||
|                 var settings = serviceProvider.GetRequiredService<IOptions<MongoConnSettings>>().Value; |  | ||||||
|                 var mongoClientSettings = MongoClientSettings.FromConnectionString(settings.ConnectionString); |  | ||||||
|                 mongoClientSettings.Credential = MongoCredential.CreateOidcCredential(new HeathOidcCallback(settings.Audience)); |  | ||||||
|                 return new MongoClient(mongoClientSettings); |  | ||||||
|             }); |  | ||||||
|  |  | ||||||
|             services.AddSingleton<IMongoDatabase>(serviceProvider => |  | ||||||
|             { |  | ||||||
|                 var settings = serviceProvider.GetRequiredService<IOptions<MongoConnSettings>>().Value; |  | ||||||
|                 var client = serviceProvider.GetRequiredService<IMongoClient>(); |  | ||||||
|                 return client.GetDatabase(settings.Databasename); |  | ||||||
|             }); |  | ||||||
|  |  | ||||||
|             services.AddDALConfigurationLayer(); |  | ||||||
|             services.AddLogs(); |  | ||||||
|             services.AddRedisCacheService(configuration); |  | ||||||
|             services.AddBlobStorage(configuration); |  | ||||||
|  |  | ||||||
|             return services; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|  |  | ||||||
|         private static IServiceCollection AddDALConfigurationLayer(this IServiceCollection services) |  | ||||||
|         { |  | ||||||
|             services.AddHttpContextAccessor(); |  | ||||||
|  |  | ||||||
|             services.AddScoped<IUserService, UserService>(); |  | ||||||
|             services.AddScoped<IRoleService, RoleService>(); |  | ||||||
|             services.AddScoped<IPermissionService, PermissionService>(); |  | ||||||
|             services.AddScoped<IPermissionService, PermissionService>(); |  | ||||||
|             services.AddScoped<IModuleService, ModuleService>(); |  | ||||||
|             return services; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         private static IServiceCollection AddLogs(this IServiceCollection services) |  | ||||||
|         { |  | ||||||
|             services.AddLogging(); |  | ||||||
|             var serviceProvider = services.BuildServiceProvider(); |  | ||||||
|             //var logger = serviceProvider.GetService<ILogger<DashboardDALService>>(); //Add for Markup class later TODO |  | ||||||
|  |  | ||||||
|             //services.AddSingleton(typeof(ILogger), logger); |  | ||||||
|  |  | ||||||
|             return services; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         private static IServiceCollection AddRedisCacheService(this IServiceCollection services, IConfiguration configuration) |  | ||||||
|         { |  | ||||||
|             var source = configuration.GetSection("ConnectionStrings"); |  | ||||||
|  |  | ||||||
|             var redisConnectionString = source["Redis"]?.ToString(); |  | ||||||
|  |  | ||||||
|             if (string.IsNullOrEmpty(redisConnectionString)) |  | ||||||
|             { |  | ||||||
|                 throw new InvalidOperationException("Redis connection string is not configured."); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             services.AddSingleton<ICacheService>(provider => |  | ||||||
|                 new CacheService(redisConnectionString, provider.GetRequiredService<ILogger<CacheService>>())); |  | ||||||
|  |  | ||||||
|             return services; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -3,15 +3,13 @@ Microsoft Visual Studio Solution File, Format Version 12.00 | |||||||
| # Visual Studio Version 17 | # Visual Studio Version 17 | ||||||
| VisualStudioVersion = 17.10.35027.167 | VisualStudioVersion = 17.10.35027.167 | ||||||
| MinimumVisualStudioVersion = 10.0.40219.1 | MinimumVisualStudioVersion = 10.0.40219.1 | ||||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Cerberos.DAL.API", "Core.Cerberos.DAL.API\Core.Cerberos.DAL.API.csproj", "{F00B4683-03B3-487A-9608-4B30675AA278}" | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Thalos.DAL.API", "Core.Thalos.DAL.API\Core.Thalos.DAL.API.csproj", "{F00B4683-03B3-487A-9608-4B30675AA278}" | ||||||
| EndProject | EndProject | ||||||
| Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Application", "Application", "{2E7D918E-AB9F-44BF-A334-FD675C9B626E}" | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Application", "Application", "{2E7D918E-AB9F-44BF-A334-FD675C9B626E}" | ||||||
| EndProject | EndProject | ||||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Cerberos.Domain", "Core.Cerberos.Domain\Core.Cerberos.Domain.csproj", "{BE8E05D6-05B2-4317-B619-21853B7D21DB}" | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Thalos.Domain", "Core.Thalos.Domain\Core.Thalos.Domain.csproj", "{BE8E05D6-05B2-4317-B619-21853B7D21DB}" | ||||||
| EndProject | EndProject | ||||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Cerberos.Infrastructure", "Core.Cerberos.Infraestructure\Core.Cerberos.Infrastructure.csproj", "{43BD5F47-132F-4E78-83F1-A1FEED01A502}" | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Thalos.Provider", "Core.Thalos.Provider\Core.Thalos.Provider.csproj", "{8CAE8380-475F-46B8-AF90-C495AAC58606}" | ||||||
| EndProject |  | ||||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Cerberos.Provider", "Core.Cerberos.Provider\Core.Cerberos.Provider.csproj", "{8CAE8380-475F-46B8-AF90-C495AAC58606}" |  | ||||||
| EndProject | EndProject | ||||||
| Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Presentation", "Presentation", "{36839283-6407-476A-BB33-F0EE90383E2B}" | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Presentation", "Presentation", "{36839283-6407-476A-BB33-F0EE90383E2B}" | ||||||
| EndProject | EndProject | ||||||
| @@ -29,10 +27,6 @@ Global | |||||||
| 		{BE8E05D6-05B2-4317-B619-21853B7D21DB}.Debug|Any CPU.Build.0 = Debug|Any CPU | 		{BE8E05D6-05B2-4317-B619-21853B7D21DB}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||||
| 		{BE8E05D6-05B2-4317-B619-21853B7D21DB}.Release|Any CPU.ActiveCfg = Release|Any CPU | 		{BE8E05D6-05B2-4317-B619-21853B7D21DB}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||||
| 		{BE8E05D6-05B2-4317-B619-21853B7D21DB}.Release|Any CPU.Build.0 = Release|Any CPU | 		{BE8E05D6-05B2-4317-B619-21853B7D21DB}.Release|Any CPU.Build.0 = Release|Any CPU | ||||||
| 		{43BD5F47-132F-4E78-83F1-A1FEED01A502}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |  | ||||||
| 		{43BD5F47-132F-4E78-83F1-A1FEED01A502}.Debug|Any CPU.Build.0 = Debug|Any CPU |  | ||||||
| 		{43BD5F47-132F-4E78-83F1-A1FEED01A502}.Release|Any CPU.ActiveCfg = Release|Any CPU |  | ||||||
| 		{43BD5F47-132F-4E78-83F1-A1FEED01A502}.Release|Any CPU.Build.0 = Release|Any CPU |  | ||||||
| 		{8CAE8380-475F-46B8-AF90-C495AAC58606}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | 		{8CAE8380-475F-46B8-AF90-C495AAC58606}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||||||
| 		{8CAE8380-475F-46B8-AF90-C495AAC58606}.Debug|Any CPU.Build.0 = Debug|Any CPU | 		{8CAE8380-475F-46B8-AF90-C495AAC58606}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||||
| 		{8CAE8380-475F-46B8-AF90-C495AAC58606}.Release|Any CPU.ActiveCfg = Release|Any CPU | 		{8CAE8380-475F-46B8-AF90-C495AAC58606}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||||
| @@ -44,7 +38,6 @@ Global | |||||||
| 	GlobalSection(NestedProjects) = preSolution | 	GlobalSection(NestedProjects) = preSolution | ||||||
| 		{F00B4683-03B3-487A-9608-4B30675AA278} = {36839283-6407-476A-BB33-F0EE90383E2B} | 		{F00B4683-03B3-487A-9608-4B30675AA278} = {36839283-6407-476A-BB33-F0EE90383E2B} | ||||||
| 		{BE8E05D6-05B2-4317-B619-21853B7D21DB} = {2E7D918E-AB9F-44BF-A334-FD675C9B626E} | 		{BE8E05D6-05B2-4317-B619-21853B7D21DB} = {2E7D918E-AB9F-44BF-A334-FD675C9B626E} | ||||||
| 		{43BD5F47-132F-4E78-83F1-A1FEED01A502} = {2E7D918E-AB9F-44BF-A334-FD675C9B626E} |  | ||||||
| 		{8CAE8380-475F-46B8-AF90-C495AAC58606} = {2E7D918E-AB9F-44BF-A334-FD675C9B626E} | 		{8CAE8380-475F-46B8-AF90-C495AAC58606} = {2E7D918E-AB9F-44BF-A334-FD675C9B626E} | ||||||
| 	EndGlobalSection | 	EndGlobalSection | ||||||
| 	GlobalSection(ExtensibilityGlobals) = postSolution | 	GlobalSection(ExtensibilityGlobals) = postSolution | ||||||
							
								
								
									
										145
									
								
								Core.Thalos.DAL.API/Controllers/ModuleController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										145
									
								
								Core.Thalos.DAL.API/Controllers/ModuleController.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,145 @@ | |||||||
|  | // *********************************************************************** | ||||||
|  | // <copyright file="ModuleController.cs"> | ||||||
|  | //     AgileWebs | ||||||
|  | // </copyright> | ||||||
|  | // *********************************************************************** | ||||||
|  |  | ||||||
|  | using Asp.Versioning; | ||||||
|  | using Core.Thalos.BuildingBlocks; | ||||||
|  | using Core.Thalos.Provider.Contracts; | ||||||
|  | using Microsoft.AspNetCore.Authorization; | ||||||
|  | using Microsoft.AspNetCore.Mvc; | ||||||
|  | using ModuleRequest = Core.Thalos.Domain.Contexts.Onboarding.Request.ModuleRequest; | ||||||
|  | using StatusEnum = Core.Blueprint.Mongo.StatusEnum; | ||||||
|  |  | ||||||
|  | namespace LSA.Core.Thalos.API.Controllers | ||||||
|  | { | ||||||
|  |     /// <summary> | ||||||
|  |     /// Handles all requests for module management. | ||||||
|  |     /// </summary> | ||||||
|  |     [ApiVersion(MimeTypes.ApplicationVersion)] | ||||||
|  |     [Route("api/v{api-version:apiVersion}/[controller]")] | ||||||
|  |     [Produces(MimeTypes.ApplicationJson)] | ||||||
|  |     [Consumes(MimeTypes.ApplicationJson)] | ||||||
|  |     [ApiController] | ||||||
|  |     [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |     public class ModuleController(IModuleProvider service) : ControllerBase | ||||||
|  |     { | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets all modules. | ||||||
|  |         /// </summary> | ||||||
|  |         [HttpGet] | ||||||
|  |         [ProducesResponseType(typeof(IEnumerable<ModuleAdapter>), StatusCodes.Status200OK)] | ||||||
|  |         [Permission("ModuleManagement.Read, RoleManagement.Read")] | ||||||
|  |         public async Task<IActionResult> GetAllModulesAsync(CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.GetAllModules(cancellationToken); | ||||||
|  |             return Ok(result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets all the modules by module identifiers. | ||||||
|  |         /// </summary> | ||||||
|  |         [HttpPost] | ||||||
|  |         [Route(Routes.GetModuleList)] | ||||||
|  |         [ProducesResponseType(typeof(IEnumerable<ModuleAdapter>), StatusCodes.Status200OK)] | ||||||
|  |         [Permission("ModuleManagement.Read")] | ||||||
|  |         public async Task<IActionResult> GetAllModulesByList([FromBody] string[] modules, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             if (modules == null || !modules.Any()) | ||||||
|  |                 return BadRequest("Module identifiers are required."); | ||||||
|  |  | ||||||
|  |             var result = await service.GetAllModulesByList(modules, cancellationToken); | ||||||
|  |             return Ok(result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets the module by mongo identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         [HttpGet] | ||||||
|  |         [Route(Routes.Id)] | ||||||
|  |         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status404NotFound)] | ||||||
|  |         [Permission("ModuleManagement.Read")] | ||||||
|  |         public async Task<IActionResult> GetModuleByIdAsync([FromRoute] string _id, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.GetModuleById(_id, cancellationToken); | ||||||
|  |  | ||||||
|  |             if (result == null) | ||||||
|  |                 return NotFound("Module not found"); | ||||||
|  |  | ||||||
|  |             return Ok(result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Creates a new module. | ||||||
|  |         /// </summary> | ||||||
|  |         [HttpPost] | ||||||
|  |         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status201Created)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status422UnprocessableEntity)] | ||||||
|  |         [Permission("ModuleManagement.Write")] | ||||||
|  |         public async Task<IActionResult> CreateModuleAsync([FromBody] ModuleRequest newModule, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.CreateModule(newModule, cancellationToken); | ||||||
|  |             return Created("CreatedWithIdAsync", result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Updates a full module by mongo identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         [HttpPut] | ||||||
|  |         [Route(Routes.Id)] | ||||||
|  |         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status422UnprocessableEntity)] | ||||||
|  |         [Permission("ModuleManagement.Write")] | ||||||
|  |         public async Task<IActionResult> UpdateModuleAsync([FromRoute] string _id, [FromBody] ModuleAdapter entity, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             if (_id != entity._Id) | ||||||
|  |                 return BadRequest("Module ID mismatch"); | ||||||
|  |  | ||||||
|  |             var result = await service.UpdateModule(entity, cancellationToken); | ||||||
|  |             return Ok(result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Changes the status of the module. | ||||||
|  |         /// </summary> | ||||||
|  |         [HttpPatch] | ||||||
|  |         [Route(Routes.ChangeStatus)] | ||||||
|  |         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)] | ||||||
|  |         [Permission("ModuleManagement.Write")] | ||||||
|  |         public async Task<IActionResult> ChangeModuleStatus([FromRoute] string _id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.ChangeModuleStatus(_id, newStatus, cancellationToken); | ||||||
|  |  | ||||||
|  |             if (result == null) | ||||||
|  |                 return NotFound("Module not found"); | ||||||
|  |  | ||||||
|  |             return Ok(result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Deletes a module by mongo identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The module Mongo mongo identifier.</param> | ||||||
|  |         /// <param name="cancellationToken">Cancellation token for async operation.</param> | ||||||
|  |         /// <returns>The deleted <see cref="ModuleAdapter"/> if found.</returns> | ||||||
|  |         /// <response code="200">The module was successfully deleted.</response> | ||||||
|  |         /// <response code="404">The module was not found.</response> | ||||||
|  |         /// <response code="500">Internal server error.</response> | ||||||
|  |         [HttpDelete] | ||||||
|  |         [Route(Routes.Id)] | ||||||
|  |         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status404NotFound)] | ||||||
|  |         [Permission("ModuleManagement.Write")] | ||||||
|  |         public async Task<IActionResult> DeleteModuleAsync([FromRoute] string _id, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.DeleteModule(_id, cancellationToken); | ||||||
|  |             if (result == null) | ||||||
|  |                 return NotFound("Module not found"); | ||||||
|  |  | ||||||
|  |             return Ok(result); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -5,16 +5,14 @@ | |||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| 
 | 
 | ||||||
| using Asp.Versioning; | using Asp.Versioning; | ||||||
| using Core.Cerberos.Adapters; | using Core.Thalos.BuildingBlocks; | ||||||
| using Core.Cerberos.Adapters.Attributes; | using Core.Thalos.Provider.Contracts; | ||||||
| using Core.Cerberos.Adapters.Common.Constants; |  | ||||||
| using Core.Cerberos.Adapters.Common.Enums; |  | ||||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; |  | ||||||
| using Core.Cerberos.Provider.Contracts; |  | ||||||
| using Microsoft.AspNetCore.Authorization; | using Microsoft.AspNetCore.Authorization; | ||||||
| using Microsoft.AspNetCore.Mvc; | using Microsoft.AspNetCore.Mvc; | ||||||
|  | using PermissionRequest = Core.Thalos.Domain.Contexts.Onboarding.Request.PermissionRequest; | ||||||
|  | using StatusEnum = Core.Blueprint.Mongo.StatusEnum; | ||||||
| 
 | 
 | ||||||
| namespace LSA.Core.Kerberos.API.Controllers | namespace LSA.Core.Thalos.API.Controllers | ||||||
| { | { | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// Handles all requests for permission authentication. |     /// Handles all requests for permission authentication. | ||||||
| @@ -24,196 +22,173 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|     [Produces(MimeTypes.ApplicationJson)] |     [Produces(MimeTypes.ApplicationJson)] | ||||||
|     [Consumes(MimeTypes.ApplicationJson)] |     [Consumes(MimeTypes.ApplicationJson)] | ||||||
|     [ApiController] |     [ApiController] | ||||||
|     public class PermissionController(IPermissionService service, ILogger<PermissionController> logger) : ControllerBase |     [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |     public class PermissionController(IPermissionProvider service) : ControllerBase | ||||||
|     { |     { | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets all the permissions. |         /// Gets all permissions. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// <returns>The <see cref="IEnumerable{PermissionAdapter}"/> found entities.</returns> |         /// <returns>The <see cref="IEnumerable{PermissionAdapter}"/> found entities.</returns> | ||||||
|         /// <response code="200">The roles found.</response> |         /// <response code="200">The permissions found.</response> | ||||||
|         /// <response code="404">The roles not found error.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |         /// <response code="500">The service internal error.</response> | ||||||
|         [HttpGet] |         [HttpGet] | ||||||
|         [Consumes(MimeTypes.ApplicationJson)] |         [Consumes(MimeTypes.ApplicationJson)] | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |         [Produces(MimeTypes.ApplicationJson)] | ||||||
|         [ProducesResponseType(typeof(IEnumerable<PermissionAdapter>), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(IEnumerable<PermissionAdapter>), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |  | ||||||
|         [Permission("PermissionManagement.Read, RoleManagement.Read")] |         [Permission("PermissionManagement.Read, RoleManagement.Read")] | ||||||
|         public async Task<IActionResult> GetAllPermissionsAsync() |         public async Task<IActionResult> GetAllPermissionsAsync(CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             try |             var result = await service.GetAllPermissions(cancellationToken).ConfigureAwait(false); | ||||||
|             { |  | ||||||
|                 var result = await service.GetAllPermissionsService(); |  | ||||||
| 
 |  | ||||||
|             return Ok(result); |             return Ok(result); | ||||||
|         } |         } | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in GetAllPermissionsAsync"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets all the permissions by permission identifiers. |         /// Gets all the permissions by permission identifiers. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="permissions">The list of permission identifiers.</param> |         /// <param name="permissions">The list of permission identifiers.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// <returns>The <see cref="IEnumerable{PermissionAdapter}"/> found entities.</returns> |         /// <returns>The <see cref="IEnumerable{PermissionAdapter}"/> found entities.</returns> | ||||||
|         /// <response code="200">The permissions found.</response> |         /// <response code="200">The permissions found.</response> | ||||||
|         /// <response code="404">The permissions not found error.</response> |         /// <response code="400">Bad request if list is null or empty.</response> | ||||||
|         /// <response code="500">The service internal error.</response> |         /// <response code="500">The service internal error.</response> | ||||||
|         [HttpPost] |         [HttpPost] | ||||||
|         [Route(Routes.GetPermissionList)] |         [Route(Routes.GetPermissionList)] | ||||||
|         [Consumes(MimeTypes.ApplicationJson)] |         [Consumes(MimeTypes.ApplicationJson)] | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |         [Produces(MimeTypes.ApplicationJson)] | ||||||
|         [ProducesResponseType(typeof(IEnumerable<PermissionAdapter>), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(IEnumerable<PermissionAdapter>), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |  | ||||||
|         [Permission("PermissionManagement.Read")] |         [Permission("PermissionManagement.Read")] | ||||||
|         public async Task<IActionResult> GetAllPermissionsByList([FromBody] string[] permissions) |         public async Task<IActionResult> GetAllPermissionsByList([FromBody] string[] permissions, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             if (permissions == null || !permissions.Any()) |             if (permissions == null || !permissions.Any()) | ||||||
|             { |             { | ||||||
|                 return BadRequest("Permission identifiers are required."); |                 return BadRequest("Permissions identifiers are required."); | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var result = await service.GetAllPermissionsByListService(permissions); |  | ||||||
| 
 |  | ||||||
|                 if (result == null || !result.Any()) |  | ||||||
|                 { |  | ||||||
|                     return NotFound("No permissions found for the given identifiers."); |  | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|  |             var result = await service.GetAllPermissionsByList(permissions, cancellationToken).ConfigureAwait(false); | ||||||
|             return Ok(result); |             return Ok(result); | ||||||
|         } |         } | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in GetAllPermissionsByList"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets the permission by identifier. |         /// Gets the permission by mongo identifier. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="id">The permission identifier.</param> |         /// <param name="_id">The permission mongo identifier.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// <returns>The <see cref="PermissionAdapter"/> found entity.</returns> |         /// <returns>The <see cref="PermissionAdapter"/> found entity.</returns> | ||||||
|         /// <response code="200">The permission found.</response> |         /// <response code="200">The permission found.</response> | ||||||
|         /// <response code="404">The permission not found error.</response> |         /// <response code="404">The permission not found.</response> | ||||||
|         /// <response code="500">The service internal error.</response> |         /// <response code="500">The service internal error.</response> | ||||||
|         [HttpGet] |         [HttpGet] | ||||||
|         [Route(Routes.Id)] |         [Route(Routes.Id)] | ||||||
|         [Consumes(MimeTypes.ApplicationJson)] |         [Consumes(MimeTypes.ApplicationJson)] | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |         [Produces(MimeTypes.ApplicationJson)] | ||||||
|         [ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |  | ||||||
|         [Permission("PermissionManagement.Read")] |         [Permission("PermissionManagement.Read")] | ||||||
|         public async Task<IActionResult> GetPermissionByIdAsync([FromRoute] string id) |         public async Task<IActionResult> GetPermissionByIdAsync([FromRoute] string _id, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             try |             var result = await service.GetPermissionById(_id, cancellationToken).ConfigureAwait(false); | ||||||
|             { |  | ||||||
|                 var result = await service.GetPermissionByIdService(id); |  | ||||||
| 
 | 
 | ||||||
|                 if (result is null) return NotFound($"permission with id: '{id}' not found"); |             if (result == null) | ||||||
|  |             { | ||||||
|  |                 return NotFound("Permission not found"); | ||||||
|  |             } | ||||||
| 
 | 
 | ||||||
|             return Ok(result); |             return Ok(result); | ||||||
|         } |         } | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in GetPermissionByIdAsync"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Creates a new permission. |         /// Creates a new permission. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="newPermission">The permission to be added.</param> |         /// <param name="newPermission">The permission to be added.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// <returns>The <see cref="PermissionAdapter"/> created entity.</returns> |         /// <returns>The <see cref="PermissionAdapter"/> created entity.</returns> | ||||||
|         /// <response code="201">The permission created.</response> |         /// <response code="201">The permission created.</response> | ||||||
|         /// <response code="422">The permission could not be created.</response> |         /// <response code="422">The permission could not be created.</response> | ||||||
|         /// <response code="500">The service internal e|ror.</response> |         /// <response code="500">Internal server error.</response> | ||||||
|         [HttpPost] |         [HttpPost] | ||||||
|         [ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status201Created)] |         [ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status201Created)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |  | ||||||
|         [Permission("PermissionManagement.Write")] |         [Permission("PermissionManagement.Write")] | ||||||
|         public async Task<IActionResult> CreatePermissionAsync([FromBody] PermissionRequest newPermission) |         public async Task<IActionResult> CreatePermissionAsync([FromBody] PermissionRequest newPermission, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             try |             var result = await service.CreatePermission(newPermission, cancellationToken).ConfigureAwait(false); | ||||||
|             { |             return Created("CreatedWithIdAsync", result); | ||||||
|                 var result = await service.CreatePermissionService(newPermission).ConfigureAwait(false); |  | ||||||
|                 return Created("CreatedWithIdService", result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in CreatePermissionAsync"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Updates a full permission by identifier. |         /// Updates a full permission by mongo identifier. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|  |         /// <param name="_id">The permission mongo identifier.</param> | ||||||
|         /// <param name="entity">The permission to update.</param> |         /// <param name="entity">The permission to update.</param> | ||||||
|         /// <param name="id">The permission identifier.</param> |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// <returns>The <see cref="PermissionAdapter"/> updated entity.</returns> |         /// <returns>The <see cref="PermissionAdapter"/> updated entity.</returns> | ||||||
|         /// <response code="200">The permission updated.</response> |         /// <response code="200">The permission updated.</response> | ||||||
|         /// <response code="404">The permission not found.</response> |         /// <response code="400">Bad request if ID mismatch.</response> | ||||||
|         /// <response code="422">The permission could not be updated.</response> |         /// <response code="422">The permission could not be updated.</response> | ||||||
|         /// <response code="500">The service internal error.</response> |         /// <response code="500">Internal server error.</response> | ||||||
|         [HttpPut] |         [HttpPut] | ||||||
|         [Route(Routes.Id)] |         [Route(Routes.Id)] | ||||||
|         [Consumes(MimeTypes.ApplicationJson)] |         [Consumes(MimeTypes.ApplicationJson)] | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |         [Produces(MimeTypes.ApplicationJson)] | ||||||
|         [ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |  | ||||||
|         [Permission("PermissionManagement.Write")] |         [Permission("PermissionManagement.Write")] | ||||||
|         public async Task<IActionResult> UpdatePermissionAsync(PermissionAdapter entity, string id) |         public async Task<IActionResult> UpdatePermissionAsync([FromRoute] string _id, [FromBody] PermissionAdapter entity, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             try |             if (_id != entity._Id) | ||||||
|             { |             { | ||||||
|                 var result = await service.UpdatePermissionService(entity, id); |                 return BadRequest("Permission ID mismatch"); | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             var result = await service.UpdatePermission(entity, cancellationToken).ConfigureAwait(false); | ||||||
| 
 | 
 | ||||||
|             return Ok(result); |             return Ok(result); | ||||||
|         } |         } | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in UpdatePermissionAsync"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Changes the status of the permission. |         /// Changes the status of the permission. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="id">The permission identifier.</param> |         /// <param name="_id">The permission mongo identifier.</param> | ||||||
|         /// <param name="newStatus">The new status of the permission.</param> |         /// <param name="newStatus">The new status of the permission.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// <returns>The <see cref="PermissionAdapter"/> updated entity.</returns> |         /// <returns>The <see cref="PermissionAdapter"/> updated entity.</returns> | ||||||
|         /// <response code="200">The permission updates.</response> |         /// <response code="200">The permission status was updated.</response> | ||||||
|         /// <response code="404">The permission not found.</response> |         /// <response code="500">Internal server error.</response> | ||||||
|         /// <response code="422">The permission could not be deleted.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpPatch] |         [HttpPatch] | ||||||
|         [Route(Routes.ChangeStatus)] |         [Route(Routes.ChangeStatus)] | ||||||
|         [Consumes(MimeTypes.ApplicationJson)] |         [Consumes(MimeTypes.ApplicationJson)] | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |         [Produces(MimeTypes.ApplicationJson)] | ||||||
|         [ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |  | ||||||
|         [Permission("PermissionManagement.Write")] |         [Permission("PermissionManagement.Write")] | ||||||
|         public async Task<IActionResult> ChangePermissionStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus) |         public async Task<IActionResult> ChangePermissionStatus([FromRoute] string _id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             try |             var result = await service.ChangePermissionStatus(_id, newStatus, cancellationToken).ConfigureAwait(false); | ||||||
|             { | 
 | ||||||
|                 var result = await service.ChangePermissionStatusService(id, newStatus); |             if (result == null) | ||||||
|  |                 return NotFound("Permission not found"); | ||||||
| 
 | 
 | ||||||
|             return Ok(result); |             return Ok(result); | ||||||
|         } |         } | ||||||
|             catch (Exception ex) | 
 | ||||||
|  |         /// <summary> | ||||||
|  |         /// Deletes a permission by its mongo identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The permission mongo identifier.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns>The deleted <see cref="PermissionAdapter"/> entity.</returns> | ||||||
|  |         /// <response code="200">The permission was successfully deleted.</response> | ||||||
|  |         /// <response code="404">The permission was not found.</response> | ||||||
|  |         /// <response code="500">Internal server error occurred.</response> | ||||||
|  |         [HttpDelete] | ||||||
|  |         [Route(Routes.Id)] | ||||||
|  |         [ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)] | ||||||
|  |         [Permission("PermissionManagement.Write")] | ||||||
|  |         public async Task<IActionResult> DeletePermissionAsync([FromRoute] string _id, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|                 logger.LogError(ex, "Error in ChangePermissionStatus"); |             var result = await service.DeletePermission(_id, cancellationToken).ConfigureAwait(false); | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); | 
 | ||||||
|             } |             if (result is null) | ||||||
|  |                 return NotFound("Permission not found."); | ||||||
|  | 
 | ||||||
|  |             return Ok(result); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
							
								
								
									
										195
									
								
								Core.Thalos.DAL.API/Controllers/RoleController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										195
									
								
								Core.Thalos.DAL.API/Controllers/RoleController.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,195 @@ | |||||||
|  | // *********************************************************************** | ||||||
|  | // <copyright file="RoleController.cs"> | ||||||
|  | //     AgileWebs | ||||||
|  | // </copyright> | ||||||
|  | // *********************************************************************** | ||||||
|  |  | ||||||
|  | using Asp.Versioning; | ||||||
|  | using Core.Thalos.BuildingBlocks; | ||||||
|  | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
|  | using Core.Thalos.Provider.Contracts; | ||||||
|  | using Microsoft.AspNetCore.Authorization; | ||||||
|  | using Microsoft.AspNetCore.Mvc; | ||||||
|  | using StatusEnum = Core.Blueprint.Mongo.StatusEnum; | ||||||
|  |  | ||||||
|  | namespace LSA.Core.Thalos.API.Controllers | ||||||
|  | { | ||||||
|  |     /// <summary> | ||||||
|  |     /// Handles all requests for role authentication. | ||||||
|  |     /// </summary> | ||||||
|  |     [ApiVersion(MimeTypes.ApplicationVersion)] | ||||||
|  |     [Route("api/v{api-version:apiVersion}/[controller]")] | ||||||
|  |     [Produces(MimeTypes.ApplicationJson)] | ||||||
|  |     [Consumes(MimeTypes.ApplicationJson)] | ||||||
|  |     [ApiController] | ||||||
|  |     [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |     public class RoleController(IRoleProvider service) : ControllerBase | ||||||
|  |     { | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets all roles. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns>The <see cref="IEnumerable{RoleAdapter}"/> found entities.</returns> | ||||||
|  |         /// <response code="200">The roles found.</response> | ||||||
|  |         /// <response code="500">The service internal error.</response> | ||||||
|  |         [HttpGet] | ||||||
|  |         [ProducesResponseType(typeof(IEnumerable<RoleAdapter>), StatusCodes.Status200OK)] | ||||||
|  |         [Permission("RoleManagement.Read")] | ||||||
|  |         public async Task<IActionResult> GetAllRolesAsync(CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.GetAllRoles(cancellationToken).ConfigureAwait(false); | ||||||
|  |             return Ok(result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets the role by mongo identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The role mongo identifier.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns>The <see cref="RoleAdapter"/> found entity.</returns> | ||||||
|  |         /// <response code="200">The role found.</response> | ||||||
|  |         /// <response code="404">The role not found.</response> | ||||||
|  |         /// <response code="500">The service internal error.</response> | ||||||
|  |         [HttpGet] | ||||||
|  |         [Route(Routes.Id)] | ||||||
|  |         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] | ||||||
|  |         [Permission("RoleManagement.Read")] | ||||||
|  |         public async Task<IActionResult> GetRoleByIdAsync([FromRoute] string _id, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.GetRoleById(_id, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |             if (result == null) | ||||||
|  |             { | ||||||
|  |                 return NotFound("Role not found"); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             return Ok(result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Creates a new role. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="newRole">The role to be added.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns>The <see cref="RoleAdapter"/> created entity.</returns> | ||||||
|  |         /// <response code="201">The role created.</response> | ||||||
|  |         /// <response code="422">The role could not be created.</response> | ||||||
|  |         /// <response code="500">The service internal error.</response> | ||||||
|  |         [HttpPost] | ||||||
|  |         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status201Created)] | ||||||
|  |         [Permission("RoleManagement.Write")] | ||||||
|  |         public async Task<IActionResult> CreateRoleAsync([FromBody] RoleRequest newRole, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.CreateRole(newRole, cancellationToken).ConfigureAwait(false); | ||||||
|  |             return Created("CreatedWithIdAsync", result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Updates a full role by mongo identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The role mongo identifier.</param> | ||||||
|  |         /// <param name="entity">The role to update.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns>The <see cref="RoleAdapter"/> updated entity.</returns> | ||||||
|  |         /// <response code="200">The role updated.</response> | ||||||
|  |         /// <response code="400">Bad request if role ID mismatches.</response> | ||||||
|  |         /// <response code="422">The role could not be updated.</response> | ||||||
|  |         /// <response code="500">The service internal error.</response> | ||||||
|  |         [HttpPut] | ||||||
|  |         [Route(Routes.Id)] | ||||||
|  |         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] | ||||||
|  |         [Permission("RoleManagement.Write")] | ||||||
|  |         public async Task<IActionResult> UpdateRoleAsync([FromRoute] string _id, [FromBody] RoleAdapter entity, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             if (_id != entity._Id) | ||||||
|  |             { | ||||||
|  |                 return BadRequest("Role ID mismatch"); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             var result = await service.UpdateRole(entity, cancellationToken).ConfigureAwait(false); | ||||||
|  |             return Ok(result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Changes the status of the role. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The role mongo identifier.</param> | ||||||
|  |         /// <param name="newStatus">The new status of the role.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns>The <see cref="RoleAdapter"/> updated entity.</returns> | ||||||
|  |         /// <response code="200">The role status updated.</response> | ||||||
|  |         /// <response code="500">The service internal error.</response> | ||||||
|  |         [HttpPatch] | ||||||
|  |         [Route(Routes.ChangeStatus)] | ||||||
|  |         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] | ||||||
|  |         [Permission("RoleManagement.Write")] | ||||||
|  |         public async Task<IActionResult> ChangeRoleStatus([FromRoute] string _id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.ChangeRoleStatus(_id, newStatus, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |             if (result == null) | ||||||
|  |                 return NotFound("Role not found"); | ||||||
|  |  | ||||||
|  |             return Ok(result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Adds an application to the role's list of applications. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="roleId">The mongo identifier of the role to which the application will be added.</param> | ||||||
|  |         /// <param name="application">The application enum value to add.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns>The updated <see cref="RoleAdapter"/> object.</returns> | ||||||
|  |         /// <response code="200">The application was added to the role.</response> | ||||||
|  |         /// <response code="500">The service internal error.</response> | ||||||
|  |         [HttpPost(Routes.AddApplication)] | ||||||
|  |         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] | ||||||
|  |         [Permission("RoleManagement.Write")] | ||||||
|  |         public async Task<IActionResult> AddApplicationToRoleAsync([FromRoute] string roleId, [FromRoute] ApplicationsEnum application, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.AddApplicationToRole(roleId, application, cancellationToken).ConfigureAwait(false); | ||||||
|  |             return Ok(result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Removes an application from the role's list of applications. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="roleId">The mongo identifier of the role from which the application will be removed.</param> | ||||||
|  |         /// <param name="application">The application enum value to remove.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns>The updated <see cref="RoleAdapter"/> object.</returns> | ||||||
|  |         /// <response code="200">The application was removed from the role.</response> | ||||||
|  |         /// <response code="500">The service internal error.</response> | ||||||
|  |         [HttpDelete(Routes.RemoveApplication)] | ||||||
|  |         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] | ||||||
|  |         [Permission("RoleManagement.Write")] | ||||||
|  |         public async Task<IActionResult> RemoveApplicationFromRoleAsync([FromRoute] string roleId, [FromRoute] ApplicationsEnum application, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.RemoveApplicationFromRole(roleId, application, cancellationToken).ConfigureAwait(false); | ||||||
|  |             return Ok(result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Deletes a role by its mongo identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The role mongo identifier.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns>The deleted <see cref="RoleAdapter"/> entity.</returns> | ||||||
|  |         /// <response code="200">The role was deleted successfully.</response> | ||||||
|  |         /// <response code="404">The role was not found.</response> | ||||||
|  |         /// <response code="500">The service internal error.</response> | ||||||
|  |         [HttpDelete] | ||||||
|  |         [Route(Routes.Id)] | ||||||
|  |         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] | ||||||
|  |         [Permission("RoleManagement.Write")] | ||||||
|  |         public async Task<IActionResult> DeleteRoleAsync([FromRoute] string _id, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.DeleteRole(_id, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |             if (result is null) | ||||||
|  |                 return NotFound("Role not found."); | ||||||
|  |  | ||||||
|  |             return Ok(result); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										169
									
								
								Core.Thalos.DAL.API/Controllers/TenantController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										169
									
								
								Core.Thalos.DAL.API/Controllers/TenantController.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,169 @@ | |||||||
|  | // *********************************************************************** | ||||||
|  | // <copyright file="TenantController.cs"> | ||||||
|  | //     AgileWebs | ||||||
|  | // </copyright> | ||||||
|  | // *********************************************************************** | ||||||
|  |  | ||||||
|  | using Asp.Versioning; | ||||||
|  | using Core.Thalos.BuildingBlocks; | ||||||
|  | using Core.Thalos.Provider.Contracts; | ||||||
|  | using Microsoft.AspNetCore.Authorization; | ||||||
|  | using Microsoft.AspNetCore.Mvc; | ||||||
|  | using StatusEnum = Core.Blueprint.Mongo.StatusEnum; | ||||||
|  | using TenantRequest = Core.Thalos.Domain.Contexts.Onboarding.Request.TenantRequest; | ||||||
|  |  | ||||||
|  | namespace LSA.Core.Thalos.API.Controllers | ||||||
|  | { | ||||||
|  |     /// <summary> | ||||||
|  |     /// Handles all requests for Tenant authentication. | ||||||
|  |     /// </summary> | ||||||
|  |     [ApiVersion(MimeTypes.ApplicationVersion)] | ||||||
|  |     [Route("api/v{api-version:apiVersion}/[controller]")] | ||||||
|  |     [Produces(MimeTypes.ApplicationJson)] | ||||||
|  |     [Consumes(MimeTypes.ApplicationJson)] | ||||||
|  |     [ApiController] | ||||||
|  |     [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |     public class TenantController(ITenantProvider service) : ControllerBase | ||||||
|  |     { | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets all Tenants. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns>The <see cref="IEnumerable{TenantAdapter}"/> found entities.</returns> | ||||||
|  |         /// <response code="200">The tenants found.</response> | ||||||
|  |         /// <response code="500">The service internal error.</response> | ||||||
|  |         [HttpGet] | ||||||
|  |         [Consumes(MimeTypes.ApplicationJson)] | ||||||
|  |         [Produces(MimeTypes.ApplicationJson)] | ||||||
|  |         [ProducesResponseType(typeof(IEnumerable<TenantAdapter>), StatusCodes.Status200OK)] | ||||||
|  |         [Permission("TenantManagement.Read, RoleManagement.Read")] | ||||||
|  |         public async Task<IActionResult> GetAllTenantsAsync(CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.GetAllTenants(cancellationToken).ConfigureAwait(false); | ||||||
|  |             return Ok(result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets the Tenant by mongo identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The Tenant mongo identifier.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns>The <see cref="TenantAdapter"/> found entity.</returns> | ||||||
|  |         /// <response code="200">The tenant found.</response> | ||||||
|  |         /// <response code="404">The tenant not found error.</response> | ||||||
|  |         /// <response code="500">The service internal error.</response> | ||||||
|  |         [HttpGet] | ||||||
|  |         [Route(Routes.Id)] | ||||||
|  |         [Consumes(MimeTypes.ApplicationJson)] | ||||||
|  |         [Produces(MimeTypes.ApplicationJson)] | ||||||
|  |         [ProducesResponseType(typeof(TenantAdapter), StatusCodes.Status200OK)] | ||||||
|  |         [Permission("TenantManagement.Read")] | ||||||
|  |         public async Task<IActionResult> GetTenantByIdAsync([FromRoute] string _id, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.GetTenantById(_id, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |             if (result == null) | ||||||
|  |             { | ||||||
|  |                 return NotFound("Tenant not found"); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             return Ok(result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Creates a new Tenant. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="newTenant">The Tenant to be added.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns>The <see cref="TenantAdapter"/> created entity.</returns> | ||||||
|  |         /// <response code="201">The tenant was created.</response> | ||||||
|  |         /// <response code="422">The tenant could not be created.</response> | ||||||
|  |         /// <response code="500">The service internal error.</response> | ||||||
|  |         [HttpPost] | ||||||
|  |         [ProducesResponseType(typeof(TenantAdapter), StatusCodes.Status201Created)] | ||||||
|  |         [Permission("TenantManagement.Write")] | ||||||
|  |         public async Task<IActionResult> CreateTenantAsync([FromBody] TenantRequest newTenant, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.CreateTenant(newTenant, cancellationToken).ConfigureAwait(false); | ||||||
|  |             return Created("CreatedWithIdAsync", result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Updates a full Tenant by mongo identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The Tenant mongo identifier.</param> | ||||||
|  |         /// <param name="entity">The Tenant to update.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns>The <see cref="TenantAdapter"/> updated entity.</returns> | ||||||
|  |         /// <response code="200">The tenant was updated.</response> | ||||||
|  |         /// <response code="400">Tenant ID mismatch.</response> | ||||||
|  |         /// <response code="422">The tenant could not be updated.</response> | ||||||
|  |         /// <response code="500">The service internal error.</response> | ||||||
|  |         [HttpPut] | ||||||
|  |         [Route(Routes.Id)] | ||||||
|  |         [Consumes(MimeTypes.ApplicationJson)] | ||||||
|  |         [Produces(MimeTypes.ApplicationJson)] | ||||||
|  |         [ProducesResponseType(typeof(TenantAdapter), StatusCodes.Status200OK)] | ||||||
|  |         [Permission("TenantManagement.Write")] | ||||||
|  |         public async Task<IActionResult> UpdateTenantAsync([FromRoute] string _id, [FromBody] TenantAdapter entity, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             if (_id != entity._Id) | ||||||
|  |             { | ||||||
|  |                 return BadRequest("Tenant ID mismatch"); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             var result = await service.UpdateTenant(entity, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |             if (result is not null) return Ok(result); | ||||||
|  |             else return NotFound("Tenant not found"); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Changes the status of the Tenant. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The Tenant mongo identifier.</param> | ||||||
|  |         /// <param name="newStatus">The new status of the Tenant.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns>The <see cref="TenantAdapter"/> updated entity.</returns> | ||||||
|  |         /// <response code="200">The tenant status was updated.</response> | ||||||
|  |         /// <response code="500">The service internal error.</response> | ||||||
|  |         [HttpPatch] | ||||||
|  |         [Route(Routes.ChangeStatus)] | ||||||
|  |         [Consumes(MimeTypes.ApplicationJson)] | ||||||
|  |         [Produces(MimeTypes.ApplicationJson)] | ||||||
|  |         [ProducesResponseType(typeof(TenantAdapter), StatusCodes.Status200OK)] | ||||||
|  |         [Permission("TenantManagement.Write")] | ||||||
|  |         public async Task<IActionResult> ChangeTenantStatus([FromRoute] string _id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.ChangeTenantStatus(_id, newStatus, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |             if (result == null) | ||||||
|  |                 return NotFound("Tenant not found"); | ||||||
|  |  | ||||||
|  |             return Ok(result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Deletes a Tenant by mongo identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The Tenant mongo identifier.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns>The deleted <see cref="TenantAdapter"/> entity if found.</returns> | ||||||
|  |         /// <response code="200">The tenant was deleted.</response> | ||||||
|  |         /// <response code="404">The tenant was not found.</response> | ||||||
|  |         /// <response code="500">The service internal error.</response> | ||||||
|  |         [HttpDelete] | ||||||
|  |         [Route(Routes.Id)] | ||||||
|  |         [ProducesResponseType(typeof(TenantAdapter), StatusCodes.Status200OK)] | ||||||
|  |         [Permission("TenantManagement.Write")] | ||||||
|  |         public async Task<IActionResult> DeleteTenantAsync([FromRoute] string _id, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.DeleteTenant(_id, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |             if (result is null) | ||||||
|  |                 return NotFound("Tenant not found."); | ||||||
|  |  | ||||||
|  |             return Ok(result); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										215
									
								
								Core.Thalos.DAL.API/Controllers/UserController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										215
									
								
								Core.Thalos.DAL.API/Controllers/UserController.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,215 @@ | |||||||
|  | // *********************************************************************** | ||||||
|  | // <copyright file="UserController.cs"> | ||||||
|  | //     AgileWebs | ||||||
|  | // </copyright> | ||||||
|  | // *********************************************************************** | ||||||
|  |  | ||||||
|  | using Asp.Versioning; | ||||||
|  | using Core.Thalos.BuildingBlocks; | ||||||
|  | using Core.Thalos.Provider.Contracts; | ||||||
|  | using Microsoft.AspNetCore.Authorization; | ||||||
|  | using Microsoft.AspNetCore.Mvc; | ||||||
|  | using StatusEnum = Core.Blueprint.Mongo.StatusEnum; | ||||||
|  | using UserRequest = Core.Thalos.Domain.Contexts.Onboarding.Request.UserRequest; | ||||||
|  |  | ||||||
|  | namespace LSA.Core.Thalos.API.Controllers | ||||||
|  | { | ||||||
|  |     /// <summary> | ||||||
|  |     /// Handles all requests for user authentication. | ||||||
|  |     /// </summary> | ||||||
|  |     [ApiVersion("1.0")] | ||||||
|  |     [Route("api/v{api-version:apiVersion}/[controller]")] | ||||||
|  |     [Produces(MimeTypes.ApplicationJson)] | ||||||
|  |     [Consumes(MimeTypes.ApplicationJson)] | ||||||
|  |     [ApiController] | ||||||
|  |     public class UserController(IUserProvider service) : ControllerBase | ||||||
|  |     { | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets all users. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns>The <see cref="IEnumerable{UserAdapter}"/> found entity.</returns> | ||||||
|  |         [HttpGet] | ||||||
|  |         [ProducesResponseType(typeof(IEnumerable<UserAdapter>), StatusCodes.Status200OK)] | ||||||
|  |         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |         [Permission("UserManagement.Read")] | ||||||
|  |         public async Task<IActionResult> GetAllUsers(CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.GetAllUsers(cancellationToken).ConfigureAwait(false); | ||||||
|  |             return Ok(result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets the user by mongo identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The user Mongo identifier.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns>The <see cref="UserAdapter"/> found entity.</returns> | ||||||
|  |         [HttpGet] | ||||||
|  |         [Route(Routes.Id)] | ||||||
|  |         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||||
|  |         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |         [Permission("UserManagement.Read")] | ||||||
|  |         public async Task<IActionResult> GetUserById([FromRoute] string _id, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.GetUserById(_id, cancellationToken).ConfigureAwait(false); | ||||||
|  |             return result == null ? NotFound("User not found") : Ok(result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets the user by email. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="email">The user's email.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns>The <see cref="UserAdapter"/> found entity.</returns> | ||||||
|  |         [HttpGet] | ||||||
|  |         [Route(Routes.Email)] | ||||||
|  |         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||||
|  |         [Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.GoogleScheme}")] | ||||||
|  |         public async Task<IActionResult> GetUserByEmail([FromRoute] string email, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.GetUserByEmail(email, cancellationToken).ConfigureAwait(false); | ||||||
|  |             return result == null ? NotFound("User not found") : Ok(result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Validates if a user exists on the database. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="email">The user's email.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns>The <see cref="UserExistenceAdapter"/> indicating existence.</returns> | ||||||
|  |         [HttpGet] | ||||||
|  |         [Route("{email}/ValidateExistence")] | ||||||
|  |         [ProducesResponseType(typeof(UserExistenceAdapter), StatusCodes.Status200OK)] | ||||||
|  |         [AllowAnonymous] | ||||||
|  |         public async Task<IActionResult> ValidateUserExistence([FromRoute] string email, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.ValidateUserExistence(email, cancellationToken).ConfigureAwait(false); | ||||||
|  |             return result == null ? NotFound("User not found") : Ok(result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Creates a new user. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="newUser">The user to be added.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns>The <see cref="UserAdapter"/> created entity.</returns> | ||||||
|  |         [HttpPost(Routes.Register)] | ||||||
|  |         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status201Created)] | ||||||
|  |         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |         [Permission("UserManagement.Write")] | ||||||
|  |         public async Task<IActionResult> CreateUserAsync([FromBody] UserRequest newUser, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.CreateUser(newUser, cancellationToken).ConfigureAwait(false); | ||||||
|  |             return Created("CreatedWithIdAsync", result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Updates a full user by mongo identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The user Mongo identifier.</param> | ||||||
|  |         /// <param name="entity">The user to update.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns>The <see cref="UserAdapter"/> updated entity.</returns> | ||||||
|  |         [HttpPut] | ||||||
|  |         [Route(Routes.Id)] | ||||||
|  |         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||||
|  |         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |         [Permission("UserManagement.Write")] | ||||||
|  |         public async Task<IActionResult> UpdateUserAsync([FromRoute] string _id, [FromBody] UserAdapter entity, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             if (_id != entity._Id) | ||||||
|  |                 return BadRequest("User ID mismatch"); | ||||||
|  |  | ||||||
|  |             var result = await service.UpdateUser(entity, cancellationToken).ConfigureAwait(false); | ||||||
|  |             return Ok(result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Logs in the user. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="email">The user's email.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns>The <see cref="UserAdapter"/> found entity.</returns> | ||||||
|  |         [HttpPatch(Routes.LogIn)] | ||||||
|  |         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||||
|  |         [Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.GoogleScheme}")] | ||||||
|  |         public async Task<IActionResult> LoginUserAsync([FromRoute] string email, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.LogInUser(email, cancellationToken).ConfigureAwait(false); | ||||||
|  |             return result == null ? NotFound($"The user with email: '{email}' was not found") : Ok(result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Logs out the user. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="email">The user's email.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns>The <see cref="UserAdapter"/> updated entity.</returns> | ||||||
|  |         [HttpPatch(Routes.LogOut)] | ||||||
|  |         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||||
|  |         [Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.GoogleScheme}")] | ||||||
|  |         public async Task<IActionResult> LogOutUserSessionAsync([FromRoute] string email, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.LogOutUserSession(email, cancellationToken).ConfigureAwait(false); | ||||||
|  |             return Ok(result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Changes the status of the user. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The user Mongo identifier.</param> | ||||||
|  |         /// <param name="newStatus">The new status of the user.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns>The <see cref="UserAdapter"/> updated entity.</returns> | ||||||
|  |         [HttpPatch] | ||||||
|  |         [Route(Routes.ChangeStatus)] | ||||||
|  |         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||||
|  |         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |         [Permission("UserManagement.Write")] | ||||||
|  |         public async Task<IActionResult> ChangeUserStatus([FromRoute] string _id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.ChangeUserStatus(_id, newStatus, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |             if (result == null) | ||||||
|  |                 return NotFound("User not found"); | ||||||
|  |  | ||||||
|  |             return Ok(result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets a token for the user, including roles, permissions, and modules. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="email">The user's email.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns>The <see cref="TokenAdapter"/> with user details.</returns> | ||||||
|  |         [HttpGet] | ||||||
|  |         [Route("{email}/GetTokenAdapter")] | ||||||
|  |         [ProducesResponseType(typeof(TokenAdapter), StatusCodes.Status200OK)] | ||||||
|  |         [Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.GoogleScheme}")] | ||||||
|  |         public async Task<IActionResult> GetTokenAdapter([FromRoute] string email, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var tokenAdapter = await service.GetToken(email, cancellationToken).ConfigureAwait(false); | ||||||
|  |             return tokenAdapter == null ? NotFound($"User with email: {email} not found") : Ok(tokenAdapter); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Deletes a user by mongo identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The user Mongo identifier.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns>The deleted <see cref="UserAdapter"/> entity.</returns> | ||||||
|  |         /// <response code="200">The user deleted.</response> | ||||||
|  |         /// <response code="404">The user not found.</response> | ||||||
|  |         [HttpDelete] | ||||||
|  |         [Route(Routes.Id)] | ||||||
|  |         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||||
|  |         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |         [Permission("UserManagement.Write")] | ||||||
|  |         public async Task<IActionResult> DeleteUserAsync([FromRoute] string _id, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.DeleteUser(_id, cancellationToken).ConfigureAwait(false); | ||||||
|  |             return result == null ? NotFound("User not found") : Ok(result); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										6
									
								
								Core.Thalos.DAL.API/Core.Cerberos.DAL.API.http
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								Core.Thalos.DAL.API/Core.Cerberos.DAL.API.http
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | |||||||
|  | @Core.Thalos.DAL.API_HostAddress = http://localhost:5211 | ||||||
|  |  | ||||||
|  | GET {{Core.Thalos.DAL.API_HostAddress}}/weatherforecast/ | ||||||
|  | Accept: application/json | ||||||
|  |  | ||||||
|  | ### | ||||||
| @@ -15,13 +15,12 @@ | |||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
| 
 | 
 | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <PackageReference Include="Blueprint.Logging" Version="0.0.1" /> |     <PackageReference Include="Core.Blueprint.Logging" Version="1.0.0" /> | ||||||
|     <PackageReference Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" Version="8.0.0" /> |  | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
| 
 | 
 | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <ProjectReference Include="..\Core.Cerberos.Domain\Core.Cerberos.Domain.csproj" /> |     <ProjectReference Include="..\Core.Thalos.Domain\Core.Thalos.Domain.csproj" /> | ||||||
|     <ProjectReference Include="..\Core.Cerberos.Provider\Core.Cerberos.Provider.csproj" /> |     <ProjectReference Include="..\Core.Thalos.Provider\Core.Thalos.Provider.csproj" /> | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
| 
 | 
 | ||||||
| </Project> | </Project> | ||||||
| @@ -0,0 +1,31 @@ | |||||||
|  | using Microsoft.Extensions.Diagnostics.HealthChecks; | ||||||
|  | using MongoDB.Bson; | ||||||
|  | using MongoDB.Driver; | ||||||
|  |  | ||||||
|  | namespace Core.Thalos.DAL.API.HealthCheck | ||||||
|  | { | ||||||
|  |     public class MongoConnectionHealthCheck(string connectionString, string databaseName) : IHealthCheck | ||||||
|  |     { | ||||||
|  |  | ||||||
|  |         public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default) | ||||||
|  |         { | ||||||
|  |             var settings = MongoClientSettings.FromConnectionString(connectionString); | ||||||
|  |  | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 var mongoClient = new MongoClient(settings); | ||||||
|  |  | ||||||
|  |                 var database = mongoClient.GetDatabase(databaseName); | ||||||
|  |                 var command = new BsonDocument("ping", 1); | ||||||
|  |  | ||||||
|  |                 await database.RunCommandAsync<BsonDocument>(command); | ||||||
|  |  | ||||||
|  |                 return HealthCheckResult.Healthy($"MongoDB is healthy, {databaseName} database from {settings.Server} is reachable."); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 return HealthCheckResult.Degraded($"MongoDB is Degraded, {databaseName} database from {settings?.Server?.Host} is unreachable.", ex); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,30 @@ | |||||||
|  | using Microsoft.Extensions.Diagnostics.HealthChecks; | ||||||
|  | using StackExchange.Redis; | ||||||
|  |  | ||||||
|  | public sealed class RedisConnectionHealthCheck : IHealthCheck | ||||||
|  | { | ||||||
|  |     private readonly string _connectionString; | ||||||
|  |     public RedisConnectionHealthCheck(string connectionString) => _connectionString = connectionString; | ||||||
|  |  | ||||||
|  |     public async Task<HealthCheckResult> CheckHealthAsync( | ||||||
|  |         HealthCheckContext context, | ||||||
|  |         CancellationToken cancellationToken = default) | ||||||
|  |     { | ||||||
|  |         try | ||||||
|  |         { | ||||||
|  |             var options = ConfigurationOptions.Parse(_connectionString); | ||||||
|  |             options.AbortOnConnectFail = false; | ||||||
|  |             options.ConnectTimeout = 2000;   // optional, be snappy | ||||||
|  |  | ||||||
|  |             using var mux = await ConnectionMultiplexer.ConnectAsync(options); | ||||||
|  |             if (!mux.IsConnected) return HealthCheckResult.Unhealthy("Redis not connected."); | ||||||
|  |  | ||||||
|  |             var ping = await mux.GetDatabase().PingAsync(); | ||||||
|  |             return HealthCheckResult.Healthy($"Redis OK (ping {ping.TotalMilliseconds:N0} ms)"); | ||||||
|  |         } | ||||||
|  |         catch (Exception ex) | ||||||
|  |         { | ||||||
|  |             return HealthCheckResult.Unhealthy("Redis check failed.", ex); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,50 @@ | |||||||
|  | using Microsoft.Extensions.Diagnostics.HealthChecks; | ||||||
|  | using System.Text.Json; | ||||||
|  |  | ||||||
|  | namespace Core.Thalos.DAL.API.HealthCheck.Writer | ||||||
|  | { | ||||||
|  |     public static class HealthCheckResponseWriter | ||||||
|  |     { | ||||||
|  |         public static Task WriteResponse(HttpContext context, HealthReport result) | ||||||
|  |         { | ||||||
|  |             context.Response.ContentType = "application/json"; | ||||||
|  |  | ||||||
|  |             context.Response.StatusCode = result.Status switch | ||||||
|  |             { | ||||||
|  |                 HealthStatus.Healthy => StatusCodes.Status200OK, | ||||||
|  |                 HealthStatus.Degraded => StatusCodes.Status500InternalServerError, | ||||||
|  |                 HealthStatus.Unhealthy => StatusCodes.Status503ServiceUnavailable, | ||||||
|  |                 _ => StatusCodes.Status500InternalServerError | ||||||
|  |             }; | ||||||
|  |  | ||||||
|  |             var options = new JsonSerializerOptions | ||||||
|  |             { | ||||||
|  |                 WriteIndented = true, | ||||||
|  |                 PropertyNamingPolicy = JsonNamingPolicy.CamelCase | ||||||
|  |             }; | ||||||
|  |  | ||||||
|  |             var json = new | ||||||
|  |             { | ||||||
|  |                 status = result.Status.ToString(), | ||||||
|  |                 services = result.Entries.Select(e => new | ||||||
|  |                 { | ||||||
|  |                     key = e.Key, | ||||||
|  |                     status = e.Value.Status.ToString(), | ||||||
|  |                     description = e.Value.Description ?? string.Empty, | ||||||
|  |                     exception = e.Value.Exception?.Message, | ||||||
|  |                     duration = e.Value.Duration.ToString(), | ||||||
|  |  | ||||||
|  |                     statusCode = e.Value.Status switch | ||||||
|  |                     { | ||||||
|  |                         HealthStatus.Healthy => StatusCodes.Status200OK, | ||||||
|  |                         HealthStatus.Degraded => StatusCodes.Status500InternalServerError, | ||||||
|  |                         HealthStatus.Unhealthy => StatusCodes.Status503ServiceUnavailable, | ||||||
|  |                         _ => StatusCodes.Status500InternalServerError | ||||||
|  |                     } | ||||||
|  |                 }) | ||||||
|  |             }; | ||||||
|  |  | ||||||
|  |             return context.Response.WriteAsync(JsonSerializer.Serialize(json, options)); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										110
									
								
								Core.Thalos.DAL.API/Program.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										110
									
								
								Core.Thalos.DAL.API/Program.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,110 @@ | |||||||
|  | using Core.Blueprint.DAL.Mongo.Configuration; | ||||||
|  | using Core.Blueprint.KeyVault.Configuration; | ||||||
|  | using Core.Blueprint.Logging.Configuration; | ||||||
|  | using Core.Blueprint.Redis.Configuration; | ||||||
|  | using Core.Thalos.BuildingBlocks; | ||||||
|  | using Core.Thalos.BuildingBlocks.Configuration; | ||||||
|  | using Core.Thalos.DAL.API.HealthCheck; | ||||||
|  | using Core.Thalos.DAL.API.HealthCheck.Writer; | ||||||
|  | using Core.Thalos.Provider; | ||||||
|  | using Microsoft.AspNetCore.Diagnostics.HealthChecks; | ||||||
|  | using Microsoft.AspNetCore.HttpLogging; | ||||||
|  | using Microsoft.Extensions.Diagnostics.HealthChecks; | ||||||
|  | using System.Reflection; | ||||||
|  | using System.Text.Json.Serialization; | ||||||
|  |  | ||||||
|  | var builder = WebApplication.CreateBuilder(args); | ||||||
|  |  | ||||||
|  | builder.Configuration | ||||||
|  |     .AddUserSecrets(Assembly.GetExecutingAssembly()) | ||||||
|  |     .AddEnvironmentVariables(); | ||||||
|  |  | ||||||
|  | var services = builder.Services.AddKeyVault(builder.Configuration); | ||||||
|  |  | ||||||
|  | var authSettings = await AuthHelper.GetAuthSettings(builder.Services, builder, "thalos_common"); | ||||||
|  |  | ||||||
|  | builder.Services.ConfigureAuthentication(builder.Configuration, authSettings); | ||||||
|  |  | ||||||
|  | builder.Services.AddEndpointsApiExplorer(); | ||||||
|  | builder.Services.AddSwaggerGen(builder.Configuration, "Core.Thalos.DAL.API.xml", authSettings); | ||||||
|  | builder.Services.AddVersioning(builder.Configuration); | ||||||
|  | builder.Services.AddResponseCompression(); | ||||||
|  | builder.Services.AddProblemDetails(); | ||||||
|  | builder.Services.AddMemoryCache(); | ||||||
|  | builder.Services.AddLogs(builder); | ||||||
|  | builder.Services.AddRedis(builder.Configuration); | ||||||
|  | builder.Services.AddMongoLayer(builder.Configuration); | ||||||
|  | builder.Services.AddDALLayerServices(builder.Configuration); | ||||||
|  |  | ||||||
|  | builder.Host.ConfigureServices((context, services) => | ||||||
|  | { | ||||||
|  |  | ||||||
|  |     services.AddLogging(); | ||||||
|  |     services.AddControllers(); | ||||||
|  |     services.AddProblemDetails(); | ||||||
|  |     services.AddCors(options | ||||||
|  |         => options.AddDefaultPolicy(policyBuilder | ||||||
|  |             => policyBuilder | ||||||
|  |                 .AllowAnyOrigin() | ||||||
|  |                 .AllowAnyHeader() | ||||||
|  |                 .AllowAnyMethod())); | ||||||
|  |  | ||||||
|  |     builder.Services.Configure<Microsoft.AspNetCore.Http.Json.JsonOptions>(options => | ||||||
|  |     { | ||||||
|  |         options.SerializerOptions.Converters.Add(new JsonStringEnumConverter()); | ||||||
|  |     }); | ||||||
|  |  | ||||||
|  |     services.AddHealthChecks(); | ||||||
|  |     services.AddHttpLogging(options => options.LoggingFields = HttpLoggingFields.All); | ||||||
|  |  | ||||||
|  |     builder.Services.AddOutputCache(options => | ||||||
|  |     { | ||||||
|  |         options.AddBasePolicy(builder => | ||||||
|  |             builder.Expire(TimeSpan.FromSeconds(10))); | ||||||
|  |         options.AddPolicy("Expire20", builder => | ||||||
|  |             builder.Expire(TimeSpan.FromSeconds(20))); | ||||||
|  |         options.AddPolicy("Expire30", builder => | ||||||
|  |             builder.Expire(TimeSpan.FromSeconds(30))); | ||||||
|  |     }); | ||||||
|  | }); | ||||||
|  |  | ||||||
|  | // Add health checks | ||||||
|  | builder.Services.AddHealthChecks() | ||||||
|  |     .AddCheck( | ||||||
|  |         "mongodb", | ||||||
|  |         new MongoConnectionHealthCheck( | ||||||
|  |             connectionString: builder.Configuration.GetConnectionString("MongoDB")!, | ||||||
|  |             databaseName: builder.Configuration.GetSection("MongoDb:DatabaseName").Value!), | ||||||
|  |         failureStatus: HealthStatus.Unhealthy, | ||||||
|  |         tags: new[] { "db", "mongo" }) | ||||||
|  |     .AddCheck( | ||||||
|  |         "redis", | ||||||
|  |         new RedisConnectionHealthCheck(builder.Configuration.GetConnectionString("Redis")!), | ||||||
|  |         failureStatus: HealthStatus.Unhealthy, | ||||||
|  |         tags: new[] { "db", "redis" }); | ||||||
|  |  | ||||||
|  | var app = builder.Build(); | ||||||
|  |  | ||||||
|  | app.UseLogging(builder.Configuration); | ||||||
|  | app.UseSwaggerUI(builder.Configuration, authSettings); | ||||||
|  | app.ConfigureSwagger(builder.Configuration); | ||||||
|  |  | ||||||
|  | app.UseRouting(); | ||||||
|  | app.UseCors(); | ||||||
|  | app.UseHttpsRedirection(); | ||||||
|  | app.UseStaticFiles(); | ||||||
|  | app.UseResponseCompression(); | ||||||
|  | app.UseOutputCache(); | ||||||
|  | app.UseResponseCaching(); | ||||||
|  |  | ||||||
|  | app.UseAuthentication(); | ||||||
|  | app.UseAuthorization(); | ||||||
|  |  | ||||||
|  | app.MapControllers(); | ||||||
|  | app.MapHealthChecks("/health", new HealthCheckOptions | ||||||
|  | { | ||||||
|  |     ResponseWriter = HealthCheckResponseWriter.WriteResponse, | ||||||
|  |     AllowCachingResponses = false | ||||||
|  | }); | ||||||
|  |  | ||||||
|  | app.Run(); | ||||||
| @@ -24,7 +24,7 @@ | |||||||
|       "dotnetRunMessages": true, |       "dotnetRunMessages": true, | ||||||
|       "launchBrowser": true, |       "launchBrowser": true, | ||||||
|       "launchUrl": "swagger", |       "launchUrl": "swagger", | ||||||
|       "applicationUrl": "https://localhost:7031;http://localhost:5211", |       "applicationUrl": "https://localhost:44359;http://localhost:5211", | ||||||
|       "environmentVariables": { |       "environmentVariables": { | ||||||
|         "ASPNETCORE_ENVIRONMENT": "Local" |         "ASPNETCORE_ENVIRONMENT": "Local" | ||||||
|       } |       } | ||||||
							
								
								
									
										22
									
								
								Core.Thalos.DAL.API/appsettings.Development.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								Core.Thalos.DAL.API/appsettings.Development.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,22 @@ | |||||||
|  | { | ||||||
|  |   "Logging": { | ||||||
|  |     "LogLevel": { | ||||||
|  |       "Default": "Information", | ||||||
|  |       "Microsoft.AspNetCore": "Warning" | ||||||
|  |     } | ||||||
|  |   }, | ||||||
|  |   "AllowedHosts": "*", | ||||||
|  |   "ConnectionStrings": { | ||||||
|  |     "MongoDB": "mongodb://localhost:27017", | ||||||
|  |     "Redis": "localhost:6379" | ||||||
|  |   }, | ||||||
|  |   "MongoDb": { | ||||||
|  |     "DatabaseName": "Thalos", | ||||||
|  |     "LocalAudience": "" | ||||||
|  |   }, | ||||||
|  |   "DetailedErrors": true, | ||||||
|  |   "UseRedisCache": true, | ||||||
|  |   "CacheSettings": { | ||||||
|  |     "DefaultCacheDurationInMinutes": 3 | ||||||
|  |   } | ||||||
|  | } | ||||||
							
								
								
									
										36
									
								
								Core.Thalos.DAL.API/appsettings.Local.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								Core.Thalos.DAL.API/appsettings.Local.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,36 @@ | |||||||
|  | { | ||||||
|  |   "Logging": { | ||||||
|  |     "LogLevel": { | ||||||
|  |       "Default": "Information", | ||||||
|  |       "Microsoft.AspNetCore": "Warning" | ||||||
|  |     } | ||||||
|  |   }, | ||||||
|  |   "AllowedHosts": "*", | ||||||
|  |   "ConnectionStrings": { | ||||||
|  |     "MongoDB": "mongodb://admin_agile:AdminAgileWebs@portainer.dream-views.com:27017/?authMechanism=SCRAM-SHA-256", | ||||||
|  |     //"MongoDB": "mongodb://admin_agile:Admin%40agileWebs@portainer.white-enciso.pro:27017/?authMechanism=SCRAM-SHA-256", | ||||||
|  |     "Redis": "172.22.0.2:6379" | ||||||
|  |   }, | ||||||
|  |   "MongoDb": { | ||||||
|  |     "DatabaseName": "Thalos", | ||||||
|  |     "LocalAudience": "" | ||||||
|  |   }, | ||||||
|  |   "DetailedErrors": true, | ||||||
|  |   "UseRedisCache": false, | ||||||
|  |   "CacheSettings": { | ||||||
|  |     "DefaultCacheDurationInMinutes": 3 | ||||||
|  |   }, | ||||||
|  |   "ServiceSettings": { | ||||||
|  |     "ApplicationName": "thalos", | ||||||
|  |     "LayerName": "dal" | ||||||
|  |   }, | ||||||
|  |   "Vault": { | ||||||
|  |     "Address": "https://vault.dream-views.com/", | ||||||
|  |     "Token": "hvs.TGz6P3AsKpYuODMrs11Msiza", | ||||||
|  |     "SecretMount": "thalos" | ||||||
|  |   }, | ||||||
|  |   "IdentityProviders": { | ||||||
|  |     "Google": true, | ||||||
|  |     "Azure": false | ||||||
|  |   } | ||||||
|  | } | ||||||
| @@ -4,5 +4,5 @@ | |||||||
|       "Default": "Information", |       "Default": "Information", | ||||||
|       "Microsoft.AspNetCore": "Warning" |       "Microsoft.AspNetCore": "Warning" | ||||||
|     } |     } | ||||||
|   }, |   } | ||||||
| } | } | ||||||
| @@ -5,7 +5,7 @@ | |||||||
|     "KeyVault": "" //KeyVault Uri |     "KeyVault": "" //KeyVault Uri | ||||||
|   }, |   }, | ||||||
|   "MongoDb": { |   "MongoDb": { | ||||||
|     "DatabaseName": "Cerberos" |     "DatabaseName": "Thalos" | ||||||
|   }, |   }, | ||||||
|   "CacheSettings": { |   "CacheSettings": { | ||||||
|     "DefaultCacheDurationInMinutes": 3 // Default cache duration set to 3 minutes |     "DefaultCacheDurationInMinutes": 3 // Default cache duration set to 3 minutes | ||||||
| @@ -22,11 +22,11 @@ | |||||||
|     "CallbackPath": "", // Path for redirect after authentication |     "CallbackPath": "", // Path for redirect after authentication | ||||||
|     "Scopes": "" // Access scopes for user permissions |     "Scopes": "" // Access scopes for user permissions | ||||||
|   }, |   }, | ||||||
|   "HeathCerberosApp": { |   "ThalosApp": { | ||||||
|     "AuthorizationUrl": "", // URL for authorization endpoint (STORED IN KEY VAULT) |     "AuthorizationUrl": "", // URL for authorization endpoint (STORED IN KEY VAULT) | ||||||
|     "TokenUrl": "", // URL for token endpoint (STORED IN KEY VAULT) |     "TokenUrl": "", // URL for token endpoint (STORED IN KEY VAULT) | ||||||
|     "Scope": "", // Scope for application permissions (STORED IN KEY VAULT) |     "Scope": "", // Scope for application permissions (STORED IN KEY VAULT) | ||||||
|     "ClientId": "" // Client ID for Kerberos application (STORED IN KEY VAULT) |     "ClientId": "" // Client ID for Thalos application (STORED IN KEY VAULT) | ||||||
|   }, |   }, | ||||||
|   "MicrosoftGraph": { |   "MicrosoftGraph": { | ||||||
|     "Scopes": "", // Scopes for Microsoft Graph API access |     "Scopes": "", // Scopes for Microsoft Graph API access | ||||||
| @@ -4,12 +4,12 @@ | |||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| 
 | 
 | ||||||
| using Core.Cerberos.Adapters.Common.Enums; | using Core.Thalos.BuildingBlocks; | ||||||
| using MongoDB.Bson; | using MongoDB.Bson; | ||||||
| using MongoDB.Bson.Serialization.Attributes; | using MongoDB.Bson.Serialization.Attributes; | ||||||
| using System.Text.Json.Serialization; | using System.Text.Json.Serialization; | ||||||
| 
 | 
 | ||||||
| namespace Core.Cerberos.Domain.Contexts.Onboarding.Request | namespace Core.Thalos.Domain.Contexts.Onboarding.Request | ||||||
| { | { | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// Data transfer object (DTO) for adding modules. |     /// Data transfer object (DTO) for adding modules. | ||||||
| @@ -4,12 +4,12 @@ | |||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| 
 | 
 | ||||||
| using Core.Cerberos.Adapters.Common.Constants; | using Core.Thalos.BuildingBlocks; | ||||||
| using MongoDB.Bson; | using MongoDB.Bson; | ||||||
| using MongoDB.Bson.Serialization.Attributes; | using MongoDB.Bson.Serialization.Attributes; | ||||||
| using System.Text.Json.Serialization; | using System.Text.Json.Serialization; | ||||||
| 
 | 
 | ||||||
| namespace Core.Cerberos.Domain.Contexts.Onboarding.Request | namespace Core.Thalos.Domain.Contexts.Onboarding.Request | ||||||
| { | { | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// Data transfer object (DTO) for adding permissions. |     /// Data transfer object (DTO) for adding permissions. | ||||||
| @@ -4,12 +4,12 @@ | |||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| 
 | 
 | ||||||
| using Core.Cerberos.Adapters.Common.Enums; | using Core.Thalos.BuildingBlocks; | ||||||
| using MongoDB.Bson; | using MongoDB.Bson; | ||||||
| using MongoDB.Bson.Serialization.Attributes; | using MongoDB.Bson.Serialization.Attributes; | ||||||
| using System.Text.Json.Serialization; | using System.Text.Json.Serialization; | ||||||
| 
 | 
 | ||||||
| namespace Core.Cerberos.Domain.Contexts.Onboarding.Request | namespace Core.Thalos.Domain.Contexts.Onboarding.Request | ||||||
| { | { | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// Data transfer object (DTO) for adding a role. |     /// Data transfer object (DTO) for adding a role. | ||||||
| @@ -0,0 +1,96 @@ | |||||||
|  | // *********************************************************************** | ||||||
|  | // <copyright file="TenantRequest.cs"> | ||||||
|  | //     AgileWebs | ||||||
|  | // </copyright> | ||||||
|  | // *********************************************************************** | ||||||
|  | using MongoDB.Bson.Serialization.Attributes; | ||||||
|  |  | ||||||
|  | namespace Core.Thalos.Domain.Contexts.Onboarding.Request | ||||||
|  | { | ||||||
|  |     /// <summary> | ||||||
|  |     /// Represents a tenant creation request with business and contact details. | ||||||
|  |     /// </summary> | ||||||
|  |     public class TenantRequest | ||||||
|  |     { | ||||||
|  |         /// <summary> | ||||||
|  |         /// The legal or commercial name of the tenant. | ||||||
|  |         /// </summary> | ||||||
|  |         [BsonElement("name")] | ||||||
|  |         public string Name { get; set; } = null!; | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// The tax identification number of the tenant (e.g., RFC, VAT). | ||||||
|  |         /// </summary> | ||||||
|  |         [BsonElement("taxIdentifier")] | ||||||
|  |         public string TaxIdentifier { get; set; } = null!; | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// The primary address line (street, number, etc.). | ||||||
|  |         /// </summary> | ||||||
|  |         [BsonElement("addressLine1")] | ||||||
|  |         public string AddressLine1 { get; set; } = null!; | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// An optional second address line (apartment, suite, etc.). | ||||||
|  |         /// </summary> | ||||||
|  |         [BsonElement("addressLine2")] | ||||||
|  |         [BsonIgnoreIfNull] | ||||||
|  |         public string? AddressLine2 { get; set; } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// The city where the tenant is located. | ||||||
|  |         /// </summary> | ||||||
|  |         [BsonElement("city")] | ||||||
|  |         public string City { get; set; } = null!; | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// The state, province, or region of the tenant. | ||||||
|  |         /// </summary> | ||||||
|  |         [BsonElement("state")] | ||||||
|  |         public string State { get; set; } = null!; | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// The country of the tenant. | ||||||
|  |         /// </summary> | ||||||
|  |         [BsonElement("country")] | ||||||
|  |         public string Country { get; set; } = null!; | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// The postal or ZIP code of the tenant’s location. | ||||||
|  |         /// </summary> | ||||||
|  |         [BsonElement("postalCode")] | ||||||
|  |         public string PostalCode { get; set; } = null!; | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// The main email address for contacting the tenant. | ||||||
|  |         /// </summary> | ||||||
|  |         [BsonElement("contactEmail")] | ||||||
|  |         public string ContactEmail { get; set; } = null!; | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// The main phone number for contacting the tenant. | ||||||
|  |         /// </summary> | ||||||
|  |         [BsonElement("contactPhone")] | ||||||
|  |         public string ContactPhone { get; set; } = null!; | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// The tenant’s website URL, if available. | ||||||
|  |         /// </summary> | ||||||
|  |         [BsonElement("website")] | ||||||
|  |         [BsonIgnoreIfNull] | ||||||
|  |         public string? Website { get; set; } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// The database connection string for the tenant, if applicable. | ||||||
|  |         /// </summary> | ||||||
|  |         [BsonElement("connectionString")] | ||||||
|  |         [BsonIgnoreIfNull] | ||||||
|  |         public string? ConnectionString { get; set; } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Indicates whether the tenant uses an isolated database. | ||||||
|  |         /// </summary> | ||||||
|  |         [BsonElement("isolated")] | ||||||
|  |         public bool Isolated { get; set; } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -8,7 +8,7 @@ using MongoDB.Bson; | |||||||
| using MongoDB.Bson.Serialization.Attributes; | using MongoDB.Bson.Serialization.Attributes; | ||||||
| using System.Text.Json.Serialization; | using System.Text.Json.Serialization; | ||||||
| 
 | 
 | ||||||
| namespace Core.Cerberos.Domain.Contexts.Onboarding.Request | namespace Core.Thalos.Domain.Contexts.Onboarding.Request | ||||||
| { | { | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// Data transfer object (DTO) for adding a user. |     /// Data transfer object (DTO) for adding a user. | ||||||
| @@ -56,17 +56,11 @@ namespace Core.Cerberos.Domain.Contexts.Onboarding.Request | |||||||
|         public string RoleId { get; set; } = null!; |         public string RoleId { get; set; } = null!; | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets or sets the array of companies associated with the user. |         /// Gets or sets the tenant ID of the user. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         [BsonElement("companies")] |         [BsonElement("tenantId")] | ||||||
|         [JsonPropertyName("companies")] |         [BsonRepresentation(BsonType.ObjectId)] | ||||||
|         public string[] Companies { get; set; } = null!; |         [JsonPropertyName("tenantId")] | ||||||
| 
 |         public string TenantId { get; set; } = null!; | ||||||
|         /// <summary> |  | ||||||
|         /// Gets or sets the array of projects associated with the user. |  | ||||||
|         /// </summary> |  | ||||||
|         [BsonElement("projects")] |  | ||||||
|         [JsonPropertyName("projects")] |  | ||||||
|         public string[]? Projects { get; set; } |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @@ -7,7 +7,8 @@ | |||||||
|   </PropertyGroup> |   </PropertyGroup> | ||||||
| 
 | 
 | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <PackageReference Include="Cerberos.Building.Blocks" Version="0.0.3" /> |     <PackageReference Include="Core.Blueprint.KeyVault" Version="1.0.0" /> | ||||||
|  |     <PackageReference Include="Core.Thalos.BuildingBlocks" Version="1.0.5" /> | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
| 
 | 
 | ||||||
| </Project> | </Project> | ||||||
							
								
								
									
										87
									
								
								Core.Thalos.Provider/Contracts/IModuleProvider.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										87
									
								
								Core.Thalos.Provider/Contracts/IModuleProvider.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,87 @@ | |||||||
|  | // *********************************************************************** | ||||||
|  | // <copyright file="IModuleService.cs"> | ||||||
|  | //     AgileWebs | ||||||
|  | // </copyright> | ||||||
|  | // *********************************************************************** | ||||||
|  |  | ||||||
|  | using Core.Thalos.BuildingBlocks; | ||||||
|  | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
|  |  | ||||||
|  | namespace Core.Thalos.Provider.Contracts | ||||||
|  | { | ||||||
|  |     /// <summary> | ||||||
|  |     /// Interface for Module-related service operations. | ||||||
|  |     /// </summary> | ||||||
|  |     public interface IModuleProvider | ||||||
|  |     { | ||||||
|  |         /// <summary> | ||||||
|  |         /// Creates a new Module. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="newModule">The Module to be created.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{ModuleAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         ValueTask<ModuleAdapter> CreateModule(ModuleRequest newModule, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets a Module by its identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The Module Mongo identifier.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{ModuleAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         ValueTask<ModuleAdapter> GetModuleById(string _id, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets all Modules. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{IEnumerable{ModuleAdapter}}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         ValueTask<IEnumerable<ModuleAdapter>> GetAllModules(CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets all Modules by a list of identifiers. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="modules">The list of Module identifiers.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{IEnumerable{ModuleAdapter}}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         ValueTask<IEnumerable<ModuleAdapter>> GetAllModulesByList(string[] modules, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Changes the status of a Module. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The Module Mongo identifier.</param> | ||||||
|  |         /// <param name="newStatus">The new status of the Module.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{ModuleAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         ValueTask<ModuleAdapter?> ChangeModuleStatus(string _id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Updates a Module by its identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="entity">The Module to be updated.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{ModuleAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         ValueTask<ModuleAdapter?> UpdateModule(ModuleAdapter entity, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Deletes a Module by its identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The Module Mongo identifier.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{ModuleAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         ValueTask<ModuleAdapter?> DeleteModule(string _id, CancellationToken cancellationToken); | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										87
									
								
								Core.Thalos.Provider/Contracts/IPermissionProvider.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										87
									
								
								Core.Thalos.Provider/Contracts/IPermissionProvider.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,87 @@ | |||||||
|  | // *********************************************************************** | ||||||
|  | // <copyright file="IPermissionService.cs"> | ||||||
|  | //     AgileWebs | ||||||
|  | // </copyright> | ||||||
|  | // *********************************************************************** | ||||||
|  |  | ||||||
|  | using Core.Thalos.BuildingBlocks; | ||||||
|  | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
|  |  | ||||||
|  | namespace Core.Thalos.Provider.Contracts | ||||||
|  | { | ||||||
|  |     /// <summary> | ||||||
|  |     /// Interface for Permission-related service operations. | ||||||
|  |     /// </summary> | ||||||
|  |     public interface IPermissionProvider | ||||||
|  |     { | ||||||
|  |         /// <summary> | ||||||
|  |         /// Creates a new Permission. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="newPermission">The Permission to be created.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{PermissionAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         ValueTask<PermissionAdapter> CreatePermission(PermissionRequest newPermission, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets a Permission by its identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The Permission Mongo identifier.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{PermissionAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         ValueTask<PermissionAdapter> GetPermissionById(string _id, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets all Permissions. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{IEnumerable{PermissionAdapter}}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         ValueTask<IEnumerable<PermissionAdapter>> GetAllPermissions(CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets all Permissions by a list of identifiers. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="permissions">The list of Permission identifiers.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{IEnumerable{PermissionAdapter}}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         ValueTask<IEnumerable<PermissionAdapter>> GetAllPermissionsByList(string[] permissions, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Changes the status of a Permission. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The Permission Mongo identifier.</param> | ||||||
|  |         /// <param name="newStatus">The new status of the Permission.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{PermissionAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         ValueTask<PermissionAdapter?> ChangePermissionStatus(string _id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Updates a Permission. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="entity">The Permission to be updated.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{PermissionAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         ValueTask<PermissionAdapter?> UpdatePermission(PermissionAdapter entity, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Deletes a Permission by its identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The Permission Mongo identifier.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{PermissionAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         ValueTask<PermissionAdapter?> DeletePermission(string _id, CancellationToken cancellationToken); | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										99
									
								
								Core.Thalos.Provider/Contracts/IRoleProvider.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										99
									
								
								Core.Thalos.Provider/Contracts/IRoleProvider.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,99 @@ | |||||||
|  | // *********************************************************************** | ||||||
|  | // <copyright file="IRoleService.cs"> | ||||||
|  | //     AgileWebs | ||||||
|  | // </copyright> | ||||||
|  | // *********************************************************************** | ||||||
|  |  | ||||||
|  | using Core.Thalos.BuildingBlocks; | ||||||
|  | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
|  |  | ||||||
|  | namespace Core.Thalos.Provider.Contracts | ||||||
|  | { | ||||||
|  |     /// <summary> | ||||||
|  |     /// Interface for Role-related service operations. | ||||||
|  |     /// </summary> | ||||||
|  |     public interface IRoleProvider | ||||||
|  |     { | ||||||
|  |         /// <summary> | ||||||
|  |         /// Creates a new Role. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="newRole">The Role to be created.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{RoleAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         ValueTask<RoleAdapter> CreateRole(RoleRequest newRole, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets a Role by its identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The Role Mongo identifier.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{RoleAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         ValueTask<RoleAdapter> GetRoleById(string _id, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets all Roles. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{IEnumerable{RoleAdapter}}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         ValueTask<IEnumerable<RoleAdapter>> GetAllRoles(CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Changes the status of a Role. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The Role Mongo identifier.</param> | ||||||
|  |         /// <param name="newStatus">The new status of the Role.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{RoleAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         ValueTask<RoleAdapter?> ChangeRoleStatus(string _id, Core.Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Updates a Role. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="entity">The Role to be updated.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{RoleAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         ValueTask<RoleAdapter?> UpdateRole(RoleAdapter entity, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Adds an application to the Role's list of applications. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="roleId">The identifier of the Role to which the application will be added.</param> | ||||||
|  |         /// <param name="application">The application enum value to add.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{RoleAdapter}"/> representing the asynchronous operation with the updated Role. | ||||||
|  |         /// </returns> | ||||||
|  |         ValueTask<RoleAdapter> AddApplicationToRole(string roleId, ApplicationsEnum application, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Removes an application from the Role's list of applications. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="roleId">The identifier of the Role from which the application will be removed.</param> | ||||||
|  |         /// <param name="application">The application enum value to remove.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{RoleAdapter}"/> representing the asynchronous operation with the updated Role. | ||||||
|  |         /// </returns> | ||||||
|  |         ValueTask<RoleAdapter> RemoveApplicationFromRole(string roleId, ApplicationsEnum application, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Deletes a Role by its identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The Role Mongo identifier.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{RoleAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         ValueTask<RoleAdapter?> DeleteRole(string _id, CancellationToken cancellationToken); | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										77
									
								
								Core.Thalos.Provider/Contracts/ITenantProvider.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										77
									
								
								Core.Thalos.Provider/Contracts/ITenantProvider.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,77 @@ | |||||||
|  | // *********************************************************************** | ||||||
|  | // <copyright file="ITenantService.cs"> | ||||||
|  | //     AgileWebs | ||||||
|  | // </copyright> | ||||||
|  | // *********************************************************************** | ||||||
|  |  | ||||||
|  | using Core.Thalos.BuildingBlocks; | ||||||
|  | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
|  |  | ||||||
|  | namespace Core.Thalos.Provider.Contracts | ||||||
|  | { | ||||||
|  |     /// <summary> | ||||||
|  |     /// Interface for Tenant-related service operations. | ||||||
|  |     /// </summary> | ||||||
|  |     public interface ITenantProvider | ||||||
|  |     { | ||||||
|  |         /// <summary> | ||||||
|  |         /// Creates a new Tenant. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="newTenant">The Tenant to be created.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{TenantAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         ValueTask<TenantAdapter> CreateTenant(TenantRequest newTenant, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets a Tenant by its identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The Tenant Mongo identifier.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{TenantAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         ValueTask<TenantAdapter> GetTenantById(string _id, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets all Tenants. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{IEnumerable{TenantAdapter}}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         ValueTask<IEnumerable<TenantAdapter>> GetAllTenants(CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Changes the status of a Tenant. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The Tenant Mongo identifier.</param> | ||||||
|  |         /// <param name="newStatus">The new status of the Tenant.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{TenantAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         ValueTask<TenantAdapter?> ChangeTenantStatus(string _id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Updates a Tenant. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="entity">The Tenant to be updated.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{TenantAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         ValueTask<TenantAdapter?> UpdateTenant(TenantAdapter entity, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Deletes a Tenant by its identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The Tenant Mongo identifier.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{TenantAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         ValueTask<TenantAdapter?> DeleteTenant(string _id, CancellationToken cancellationToken); | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										127
									
								
								Core.Thalos.Provider/Contracts/IUserProvider.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										127
									
								
								Core.Thalos.Provider/Contracts/IUserProvider.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,127 @@ | |||||||
|  | // *********************************************************************** | ||||||
|  | // <copyright file="IUserService.cs"> | ||||||
|  | //     AgileWebs | ||||||
|  | // </copyright> | ||||||
|  | // *********************************************************************** | ||||||
|  |  | ||||||
|  | using Core.Thalos.BuildingBlocks; | ||||||
|  | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
|  |  | ||||||
|  | namespace Core.Thalos.Provider.Contracts | ||||||
|  | { | ||||||
|  |     /// <summary> | ||||||
|  |     /// Interface for User-related service operations. | ||||||
|  |     /// </summary> | ||||||
|  |     public interface IUserProvider | ||||||
|  |     { | ||||||
|  |         /// <summary> | ||||||
|  |         /// Creates a new User. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="newUser">The User to be created.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{UserAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         ValueTask<UserAdapter> CreateUser(UserRequest newUser, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets a User by Mongo identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The User Mongo identifier.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{UserAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         ValueTask<UserAdapter> GetUserById(string _id, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets all Users. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{IEnumerable{UserAdapter}}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         ValueTask<IEnumerable<UserAdapter>> GetAllUsers(CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets a User by email. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="email">The User's email.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{UserAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         ValueTask<UserAdapter> GetUserByEmail(string email, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Validates if a User exists by email. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="email">The User's email.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{UserExistenceAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         ValueTask<UserExistenceAdapter> ValidateUserExistence(string email, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Changes the status of a User. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The User Mongo identifier.</param> | ||||||
|  |         /// <param name="newStatus">The new status of the User.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{UserAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         ValueTask<UserAdapter?> ChangeUserStatus(string _id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Updates a User. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="entity">The User to be updated.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{UserAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         ValueTask<UserAdapter?> UpdateUser(UserAdapter entity, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Logs in the User. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="email">The User's email.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{UserAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         ValueTask<UserAdapter?> LogInUser(string email, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Logs out the User's session. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="email">The User's email.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{UserAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         ValueTask<UserAdapter?> LogOutUserSession(string email, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets the TokenAdapter for a User. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="email">The User's email.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{TokenAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         ValueTask<TokenAdapter?> GetToken(string email, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Deletes a User by Mongo identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The User Mongo identifier.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{UserAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         ValueTask<UserAdapter?> DeleteUser(string _id, CancellationToken cancellationToken); | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										23
									
								
								Core.Thalos.Provider/Core.Thalos.Provider.csproj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								Core.Thalos.Provider/Core.Thalos.Provider.csproj
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,23 @@ | |||||||
|  | <Project Sdk="Microsoft.NET.Sdk"> | ||||||
|  |  | ||||||
|  |   <PropertyGroup> | ||||||
|  |     <TargetFramework>net8.0</TargetFramework> | ||||||
|  |     <ImplicitUsings>enable</ImplicitUsings> | ||||||
|  |     <Nullable>enable</Nullable> | ||||||
|  |   </PropertyGroup> | ||||||
|  |  | ||||||
|  |   <ItemGroup> | ||||||
|  |     <Compile Remove="Providers\Onboarding\UserService - Copy.cs" /> | ||||||
|  |   </ItemGroup> | ||||||
|  |  | ||||||
|  |   <ItemGroup> | ||||||
|  |     <PackageReference Include="Core.Blueprint.Mongo" Version="1.0.0" /> | ||||||
|  |     <PackageReference Include="Core.Blueprint.Redis" Version="1.0.0" /> | ||||||
|  |     <PackageReference Include="Mapster" Version="7.4.2-pre02" /> | ||||||
|  |   </ItemGroup> | ||||||
|  |  | ||||||
|  |   <ItemGroup> | ||||||
|  |     <ProjectReference Include="..\Core.Thalos.Domain\Core.Thalos.Domain.csproj" /> | ||||||
|  |   </ItemGroup> | ||||||
|  |  | ||||||
|  | </Project> | ||||||
| @@ -7,7 +7,7 @@ | |||||||
| using Microsoft.AspNetCore.Http; | using Microsoft.AspNetCore.Http; | ||||||
| using System.Security.Claims; | using System.Security.Claims; | ||||||
| 
 | 
 | ||||||
| namespace Core.Cerberos.Provider.Providers | namespace Core.Thalos.Provider.Providers | ||||||
| { | { | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// Provides helper methods for common operations. |     /// Provides helper methods for common operations. | ||||||
							
								
								
									
										176
									
								
								Core.Thalos.Provider/Providers/Onboarding/ModuleProvider.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										176
									
								
								Core.Thalos.Provider/Providers/Onboarding/ModuleProvider.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,176 @@ | |||||||
|  | // *********************************************************************** | ||||||
|  | // <copyright file="ModuleService.cs"> | ||||||
|  | //     AgileWebs | ||||||
|  | // </copyright> | ||||||
|  | // *********************************************************************** | ||||||
|  |  | ||||||
|  | using Core.Blueprint.Mongo; | ||||||
|  | using Core.Blueprint.Redis; | ||||||
|  | using Core.Blueprint.Redis.Helpers; | ||||||
|  | using Core.Thalos.BuildingBlocks; | ||||||
|  | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
|  | using Core.Thalos.Provider.Contracts; | ||||||
|  | using Mapster; | ||||||
|  | using MongoDB.Driver; | ||||||
|  | using StatusEnum = Core.Blueprint.Mongo.StatusEnum; | ||||||
|  |  | ||||||
|  | namespace Core.Thalos.Provider.Providers.Onboarding | ||||||
|  | { | ||||||
|  |     /// <summary> | ||||||
|  |     /// Handles all services and business rules related to <see cref="ModuleAdapter"/>. | ||||||
|  |     /// </summary> | ||||||
|  |     public class ModuleProvider : IModuleProvider | ||||||
|  |     { | ||||||
|  |         private readonly CollectionRepository<ModuleAdapter> repository; | ||||||
|  |         private readonly ICacheSettings cacheSettings; | ||||||
|  |         private readonly IRedisCacheProvider cacheProvider; | ||||||
|  |  | ||||||
|  |         public ModuleProvider( | ||||||
|  |             CollectionRepository<ModuleAdapter> repository, | ||||||
|  |             IRedisCacheProvider cacheProvider, | ||||||
|  |             ICacheSettings cacheSettings) | ||||||
|  |         { | ||||||
|  |             this.repository = repository; | ||||||
|  |             this.repository.CollectionInitialization(); | ||||||
|  |             this.cacheProvider = cacheProvider; | ||||||
|  |             this.cacheSettings = cacheSettings; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Creates a new Module. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="newModule">The Module to be created.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{ModuleAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         public async ValueTask<ModuleAdapter> CreateModule(ModuleRequest newModule, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var moduleCollection = newModule.Adapt<ModuleAdapter>(); | ||||||
|  |             await repository.InsertOneAsync(moduleCollection); | ||||||
|  |             return moduleCollection; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets a Module by identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The Module Mongo identifier.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{ModuleAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         public async ValueTask<ModuleAdapter> GetModuleById(string _id, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetModuleById", _id); | ||||||
|  |             var cachedData = await cacheProvider.GetAsync<ModuleAdapter>(cacheKey); | ||||||
|  |  | ||||||
|  |             if (cachedData is not null) return cachedData; | ||||||
|  |  | ||||||
|  |             var module = await repository.FindByIdAsync(_id); | ||||||
|  |             await cacheProvider.SetAsync(cacheKey, module, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes)); | ||||||
|  |  | ||||||
|  |             return module; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets all the Modules. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{IEnumerable{ModuleAdapter}}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         public async ValueTask<IEnumerable<ModuleAdapter>> GetAllModules(CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetModules"); | ||||||
|  |             var cachedData = await cacheProvider.GetAsync<IEnumerable<ModuleAdapter>>(cacheKey) ?? []; | ||||||
|  |  | ||||||
|  |             if (cachedData.Any()) return cachedData; | ||||||
|  |  | ||||||
|  |             var modules = await repository.AsQueryable(); | ||||||
|  |             await cacheProvider.SetAsync(cacheKey, modules); | ||||||
|  |  | ||||||
|  |             return modules; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets all the Modules by a list of identifiers. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="modules">The list of Module identifiers.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{IEnumerable{ModuleAdapter}}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         public async ValueTask<IEnumerable<ModuleAdapter>> GetAllModulesByList(string[] modules, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllModulesByList", modules); | ||||||
|  |             var cachedData = await cacheProvider.GetAsync<IEnumerable<ModuleAdapter>>(cacheKey) ?? []; | ||||||
|  |  | ||||||
|  |             if (cachedData.Any()) return cachedData; | ||||||
|  |  | ||||||
|  |             var builder = Builders<ModuleAdapter>.Filter; | ||||||
|  |             var filters = new List<FilterDefinition<ModuleAdapter>>(); | ||||||
|  |  | ||||||
|  |             if (modules is { Length: > 0 }) | ||||||
|  |             { | ||||||
|  |                 filters.Add(builder.In(x => x._Id, modules)); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             var finalFilter = filters.Any() ? builder.And(filters) : builder.Empty; | ||||||
|  |             var modulesList = await repository.FilterByMongoFilterAsync(finalFilter); | ||||||
|  |  | ||||||
|  |             await cacheProvider.SetAsync(cacheKey, modulesList, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes)); | ||||||
|  |             return modulesList; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Changes the status of the Module. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The Module Mongo identifier.</param> | ||||||
|  |         /// <param name="newStatus">The new status of the Module.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{ModuleAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         public async ValueTask<ModuleAdapter?> ChangeModuleStatus(string _id, StatusEnum newStatus, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var entity = await repository.FindByIdAsync(_id); | ||||||
|  |  | ||||||
|  |             if (entity is not null) | ||||||
|  |             { | ||||||
|  |                 entity.Status = newStatus; | ||||||
|  |  | ||||||
|  |                 return repository.ReplaceOneAsync(entity).Result; | ||||||
|  |             } | ||||||
|  |             else return null; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Updates a Module. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="entity">The Module to be updated.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{ModuleAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         public async ValueTask<ModuleAdapter?> UpdateModule(ModuleAdapter entity, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var updatedEntity = await repository.ReplaceOneAsync(entity); | ||||||
|  |             return updatedEntity; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Deletes a Module by identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The Module Mongo identifier.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{ModuleAdapter}"/> representing the asynchronous deletion result. | ||||||
|  |         /// The deleted Module entity if found; otherwise, null. | ||||||
|  |         /// </returns> | ||||||
|  |         public async ValueTask<ModuleAdapter?> DeleteModule(string _id, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var entity = await this.repository.DeleteOneAsync(doc => doc._Id == _id); | ||||||
|  |             return entity; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										175
									
								
								Core.Thalos.Provider/Providers/Onboarding/PermissionProvider.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										175
									
								
								Core.Thalos.Provider/Providers/Onboarding/PermissionProvider.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,175 @@ | |||||||
|  | // *********************************************************************** | ||||||
|  | // <copyright file="PermissionService.cs"> | ||||||
|  | //     AgileWebs | ||||||
|  | // </copyright> | ||||||
|  | // *********************************************************************** | ||||||
|  |  | ||||||
|  | using Core.Blueprint.Mongo; | ||||||
|  | using Core.Blueprint.Redis; | ||||||
|  | using Core.Blueprint.Redis.Helpers; | ||||||
|  | using Core.Thalos.BuildingBlocks; | ||||||
|  | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
|  | using Core.Thalos.Provider.Contracts; | ||||||
|  | using Mapster; | ||||||
|  | using MongoDB.Driver; | ||||||
|  |  | ||||||
|  | namespace Core.Thalos.Provider.Providers.Onboarding | ||||||
|  | { | ||||||
|  |     /// <summary> | ||||||
|  |     /// Handles all services and business rules related to <see cref="PermissionAdapter"/>. | ||||||
|  |     /// </summary> | ||||||
|  |     public class PermissionProvider : IPermissionProvider | ||||||
|  |     { | ||||||
|  |         private readonly CollectionRepository<PermissionAdapter> repository; | ||||||
|  |         private readonly ICacheSettings cacheSettings; | ||||||
|  |         private readonly IRedisCacheProvider cacheProvider; | ||||||
|  |  | ||||||
|  |         public PermissionProvider( | ||||||
|  |             CollectionRepository<PermissionAdapter> repository, | ||||||
|  |             IRedisCacheProvider cacheProvider, | ||||||
|  |             ICacheSettings cacheSettings) | ||||||
|  |         { | ||||||
|  |             this.repository = repository; | ||||||
|  |             this.repository.CollectionInitialization(); | ||||||
|  |             this.cacheProvider = cacheProvider; | ||||||
|  |             this.cacheSettings = cacheSettings; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Creates a new Permission. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="newPermission">The Permission to be created.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{PermissionAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         public async ValueTask<PermissionAdapter> CreatePermission(PermissionRequest newPermission, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var permissionCollection = newPermission.Adapt<PermissionAdapter>(); | ||||||
|  |             await repository.InsertOneAsync(permissionCollection); | ||||||
|  |             return permissionCollection; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets a Permission by identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The Permission Mongo identifier.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{PermissionAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         public async ValueTask<PermissionAdapter> GetPermissionById(string _id, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetPermissionById", _id); | ||||||
|  |             var cachedData = await cacheProvider.GetAsync<PermissionAdapter>(cacheKey); | ||||||
|  |  | ||||||
|  |             if (cachedData is not null) return cachedData; | ||||||
|  |  | ||||||
|  |             var permission = await repository.FindByIdAsync(_id); | ||||||
|  |             await cacheProvider.SetAsync(cacheKey, permission); | ||||||
|  |  | ||||||
|  |             return permission; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets all Permissions. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{IEnumerable{PermissionAdapter}}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         public async ValueTask<IEnumerable<PermissionAdapter>> GetAllPermissions(CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllPermissions"); | ||||||
|  |             var cachedData = await cacheProvider.GetAsync<IEnumerable<PermissionAdapter>>(cacheKey) ?? []; | ||||||
|  |  | ||||||
|  |             if (cachedData.Any()) return cachedData; | ||||||
|  |  | ||||||
|  |             var permissions = await repository.AsQueryable(); | ||||||
|  |             await cacheProvider.SetAsync(cacheKey, permissions, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes)); | ||||||
|  |  | ||||||
|  |             return permissions; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets all Permissions by a list of identifiers. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="permissions">The list of Permission identifiers.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{IEnumerable{PermissionAdapter}}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         public async ValueTask<IEnumerable<PermissionAdapter>> GetAllPermissionsByList(string[] permissions, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllPermissionsByList", permissions); | ||||||
|  |             var cachedData = await cacheProvider.GetAsync<IEnumerable<PermissionAdapter>>(cacheKey) ?? []; | ||||||
|  |  | ||||||
|  |             if (cachedData.Any()) return cachedData; | ||||||
|  |  | ||||||
|  |             var builder = Builders<PermissionAdapter>.Filter; | ||||||
|  |             var filters = new List<FilterDefinition<PermissionAdapter>>(); | ||||||
|  |  | ||||||
|  |             if (permissions is { Length: > 0 }) | ||||||
|  |             { | ||||||
|  |                 filters.Add(builder.In(x => x._Id, permissions)); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             var finalFilter = filters.Any() ? builder.And(filters) : builder.Empty; | ||||||
|  |             var permissionsList = await repository.FilterByMongoFilterAsync(finalFilter); | ||||||
|  |  | ||||||
|  |             await cacheProvider.SetAsync(cacheKey, permissionsList, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes)); | ||||||
|  |             return permissionsList; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Changes the status of a Permission. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The Permission Mongo identifier.</param> | ||||||
|  |         /// <param name="newStatus">The new status of the Permission.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{PermissionAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         public async ValueTask<PermissionAdapter?> ChangePermissionStatus(string _id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var entity = await repository.FindByIdAsync(_id); | ||||||
|  |  | ||||||
|  |             if (entity is not null) | ||||||
|  |             { | ||||||
|  |                 entity.Status = newStatus; | ||||||
|  |  | ||||||
|  |                 return repository.ReplaceOneAsync(entity).Result; | ||||||
|  |             } | ||||||
|  |             else return null; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Updates a Permission. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="entity">The Permission to be updated.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{PermissionAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         public async ValueTask<PermissionAdapter?> UpdatePermission(PermissionAdapter entity, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var updatedEntity = await repository.ReplaceOneAsync(entity); | ||||||
|  |             return updatedEntity; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Deletes a Permission by identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The Permission Mongo identifier.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{PermissionAdapter}"/> representing the asynchronous deletion result. | ||||||
|  |         /// The deleted Permission entity if found; otherwise, null. | ||||||
|  |         /// </returns> | ||||||
|  |         public async ValueTask<PermissionAdapter?> DeletePermission(string _id, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var entity = await this.repository.DeleteOneAsync(doc => doc._Id == _id); | ||||||
|  |             return entity; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										190
									
								
								Core.Thalos.Provider/Providers/Onboarding/RoleProvider.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										190
									
								
								Core.Thalos.Provider/Providers/Onboarding/RoleProvider.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,190 @@ | |||||||
|  | // *********************************************************************** | ||||||
|  | // <copyright file="RoleService.cs"> | ||||||
|  | //     AgileWebs | ||||||
|  | // </copyright> | ||||||
|  | // *********************************************************************** | ||||||
|  |  | ||||||
|  | using Core.Blueprint.Mongo; | ||||||
|  | using Core.Blueprint.Redis; | ||||||
|  | using Core.Blueprint.Redis.Helpers; | ||||||
|  | using Core.Thalos.BuildingBlocks; | ||||||
|  | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
|  | using Core.Thalos.Provider.Contracts; | ||||||
|  | using Mapster; | ||||||
|  | using MongoDB.Driver; | ||||||
|  |  | ||||||
|  | namespace Core.Thalos.Provider.Providers.Onboarding | ||||||
|  | { | ||||||
|  |     /// <summary> | ||||||
|  |     /// Handles all services and business rules related to <see cref="RoleAdapter"/>. | ||||||
|  |     /// </summary> | ||||||
|  |     public class RoleProvider : IRoleProvider | ||||||
|  |     { | ||||||
|  |         private readonly CollectionRepository<RoleAdapter> repository; | ||||||
|  |         private readonly ICacheSettings cacheSettings; | ||||||
|  |         private readonly IRedisCacheProvider cacheProvider; | ||||||
|  |  | ||||||
|  |         public RoleProvider( | ||||||
|  |             CollectionRepository<RoleAdapter> repository, | ||||||
|  |             IRedisCacheProvider cacheProvider, | ||||||
|  |             ICacheSettings cacheSettings) | ||||||
|  |         { | ||||||
|  |             this.repository = repository; | ||||||
|  |             this.repository.CollectionInitialization(); | ||||||
|  |             this.cacheProvider = cacheProvider; | ||||||
|  |             this.cacheSettings = cacheSettings; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Creates a new Role. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="newRole">The Role to be created.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{RoleAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         public async ValueTask<RoleAdapter> CreateRole(RoleRequest newRole, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var roleCollection = newRole.Adapt<RoleAdapter>(); | ||||||
|  |             await repository.InsertOneAsync(roleCollection); | ||||||
|  |             return roleCollection; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets a Role by its identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The Role Mongo identifier.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{RoleAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         public async ValueTask<RoleAdapter> GetRoleById(string _id, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetRoleById", _id); | ||||||
|  |             var cachedData = await cacheProvider.GetAsync<RoleAdapter>(cacheKey); | ||||||
|  |  | ||||||
|  |             if (cachedData is not null) return cachedData; | ||||||
|  |  | ||||||
|  |             var role = await repository.FindByIdAsync(_id); | ||||||
|  |             await cacheProvider.SetAsync(cacheKey, role, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes)); | ||||||
|  |  | ||||||
|  |             return role; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets all Roles. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{IEnumerable{RoleAdapter}}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         public async ValueTask<IEnumerable<RoleAdapter>> GetAllRoles(CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllRoles"); | ||||||
|  |             var cachedData = await cacheProvider.GetAsync<IEnumerable<RoleAdapter>>(cacheKey) ?? []; | ||||||
|  |  | ||||||
|  |             if (cachedData.Any()) return cachedData; | ||||||
|  |  | ||||||
|  |             var roles = await repository.AsQueryable(); | ||||||
|  |             await cacheProvider.SetAsync(cacheKey, roles, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes)); | ||||||
|  |  | ||||||
|  |             return roles; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Changes the status of a Role. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The Role Mongo identifier.</param> | ||||||
|  |         /// <param name="newStatus">The new status of the Role.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{RoleAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         public async ValueTask<RoleAdapter?> ChangeRoleStatus(string _id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var entity = await repository.FindByIdAsync(_id); | ||||||
|  |  | ||||||
|  |             if (entity is not null) | ||||||
|  |             { | ||||||
|  |                 entity.Status = newStatus; | ||||||
|  |  | ||||||
|  |                 return repository.ReplaceOneAsync(entity).Result; | ||||||
|  |             } | ||||||
|  |             else return null; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Updates a Role. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="entity">The Role to be updated.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{RoleAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         public async ValueTask<RoleAdapter?> UpdateRole(RoleAdapter entity, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var updatedEntity = await repository.ReplaceOneAsync(entity); | ||||||
|  |             return updatedEntity; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Adds an application to the Role's list of applications. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="roleId">The identifier of the Role to which the application will be added.</param> | ||||||
|  |         /// <param name="application">The application enum value to add.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{RoleAdapter}"/> representing the asynchronous operation, with the updated Role object. | ||||||
|  |         /// </returns> | ||||||
|  |         public async ValueTask<RoleAdapter> AddApplicationToRole(string roleId, ApplicationsEnum application, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var role = await repository.FindOneAsync( | ||||||
|  |                 u => u._Id == roleId && u.Status == Blueprint.Mongo.StatusEnum.Active); | ||||||
|  |  | ||||||
|  |             var updatedApplications = role.Applications?.Append(application).Distinct().ToArray(); | ||||||
|  |             role.Applications = updatedApplications; | ||||||
|  |  | ||||||
|  |             await repository.ReplaceOneAsync(role); | ||||||
|  |             return role; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Removes an application from the Role's list of applications. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="roleId">The identifier of the Role from which the application will be removed.</param> | ||||||
|  |         /// <param name="application">The application enum value to remove.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{RoleAdapter}"/> representing the asynchronous operation, with the updated Role object. | ||||||
|  |         /// </returns> | ||||||
|  |         public async ValueTask<RoleAdapter> RemoveApplicationFromRole(string roleId, ApplicationsEnum application, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var role = await repository.FindOneAsync( | ||||||
|  |                 u => u._Id == roleId && u.Status == Blueprint.Mongo.StatusEnum.Active); | ||||||
|  |  | ||||||
|  |             var updatedApplications = role.Applications? | ||||||
|  |                 .Where(c => c != application) | ||||||
|  |                 .ToArray(); | ||||||
|  |  | ||||||
|  |             role.Applications = updatedApplications; | ||||||
|  |             await repository.ReplaceOneAsync(role); | ||||||
|  |  | ||||||
|  |             return role; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Deletes a Role by identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The Role Mongo identifier.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{RoleAdapter}"/> representing the asynchronous deletion result. | ||||||
|  |         /// The deleted Role entity if found; otherwise, null. | ||||||
|  |         /// </returns> | ||||||
|  |         public async ValueTask<RoleAdapter?> DeleteRole(string _id, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var entity = await repository.DeleteOneAsync(doc => doc._Id == _id); | ||||||
|  |             return entity; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										144
									
								
								Core.Thalos.Provider/Providers/Onboarding/TenantProvider.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										144
									
								
								Core.Thalos.Provider/Providers/Onboarding/TenantProvider.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,144 @@ | |||||||
|  | // *********************************************************************** | ||||||
|  | // <copyright file="TenantService.cs"> | ||||||
|  | //     AgileWebs | ||||||
|  | // </copyright> | ||||||
|  | // *********************************************************************** | ||||||
|  |  | ||||||
|  | using Core.Blueprint.Mongo; | ||||||
|  | using Core.Blueprint.Redis; | ||||||
|  | using Core.Blueprint.Redis.Helpers; | ||||||
|  | using Core.Thalos.BuildingBlocks; | ||||||
|  | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
|  | using Core.Thalos.Provider.Contracts; | ||||||
|  | using Mapster; | ||||||
|  |  | ||||||
|  | namespace Core.Thalos.Provider.Providers.Onboarding | ||||||
|  | { | ||||||
|  |     /// <summary> | ||||||
|  |     /// Handles all services and business rules related to <see cref="TenantAdapter"/>. | ||||||
|  |     /// </summary> | ||||||
|  |     public class TenantProvider : ITenantProvider | ||||||
|  |     { | ||||||
|  |         private readonly CollectionRepository<TenantAdapter> repository; | ||||||
|  |         private readonly ICacheSettings cacheSettings; | ||||||
|  |         private readonly IRedisCacheProvider cacheProvider; | ||||||
|  |  | ||||||
|  |         public TenantProvider( | ||||||
|  |             CollectionRepository<TenantAdapter> repository, | ||||||
|  |             IRedisCacheProvider cacheProvider, | ||||||
|  |             ICacheSettings cacheSettings) | ||||||
|  |         { | ||||||
|  |             this.repository = repository; | ||||||
|  |             this.repository.CollectionInitialization(); | ||||||
|  |             this.cacheSettings = cacheSettings; | ||||||
|  |             this.cacheProvider = cacheProvider; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Creates a new Tenant. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="newTenant">The Tenant to be created.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{TenantAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         public async ValueTask<TenantAdapter> CreateTenant(TenantRequest newTenant, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var tenant = newTenant.Adapt<TenantAdapter>(); | ||||||
|  |             await repository.InsertOneAsync(tenant); | ||||||
|  |             return tenant; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets a Tenant by identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The Tenant Mongo identifier.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{TenantAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         public async ValueTask<TenantAdapter> GetTenantById(string _id, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetTenantById", _id); | ||||||
|  |             var cachedData = await cacheProvider.GetAsync<TenantAdapter>(cacheKey); | ||||||
|  |  | ||||||
|  |             if (cachedData is not null) return cachedData; | ||||||
|  |  | ||||||
|  |             var tenant = await repository.FindByIdAsync(_id); | ||||||
|  |             await cacheProvider.SetAsync(cacheKey, tenant, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes)); | ||||||
|  |  | ||||||
|  |             return tenant; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets all Tenants. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{IEnumerable{TenantAdapter}}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         public async ValueTask<IEnumerable<TenantAdapter>> GetAllTenants(CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetTenants"); | ||||||
|  |             var cachedData = await cacheProvider.GetAsync<IEnumerable<TenantAdapter>>(cacheKey) ?? []; | ||||||
|  |  | ||||||
|  |             if (cachedData.Any()) return cachedData; | ||||||
|  |  | ||||||
|  |             var tenants = await repository.AsQueryable(); | ||||||
|  |             await cacheProvider.SetAsync(cacheKey, tenants, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes)); | ||||||
|  |  | ||||||
|  |             return tenants; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Changes the status of a Tenant. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The Tenant Mongo identifier.</param> | ||||||
|  |         /// <param name="newStatus">The new status of the Tenant.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{TenantAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         public async ValueTask<TenantAdapter?> ChangeTenantStatus(string _id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var entity = await repository.FindByIdAsync(_id); | ||||||
|  |  | ||||||
|  |             if (entity is not null) | ||||||
|  |             { | ||||||
|  |                 entity.Status = newStatus; | ||||||
|  |  | ||||||
|  |                 return repository.ReplaceOneAsync(entity).Result; | ||||||
|  |             } | ||||||
|  |             else return null; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Updates a Tenant. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="entity">The Tenant to be updated.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{TenantAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         public async ValueTask<TenantAdapter?> UpdateTenant(TenantAdapter entity, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var updatedEntity = await repository.ReplaceOneAsync(entity); | ||||||
|  |             return updatedEntity; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Deletes a Tenant by identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The Tenant Mongo identifier.</param> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|  |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{TenantAdapter}"/> representing the asynchronous deletion result. | ||||||
|  |         /// The deleted Tenant entity if found; otherwise, null. | ||||||
|  |         /// </returns> | ||||||
|  |         public async ValueTask<TenantAdapter?> DeleteTenant(string _id, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var entity = await repository.DeleteOneAsync(doc => doc._Id == _id); | ||||||
|  |             return entity; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										522
									
								
								Core.Thalos.Provider/Providers/Onboarding/UserProvider.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										522
									
								
								Core.Thalos.Provider/Providers/Onboarding/UserProvider.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,522 @@ | |||||||
|  | // *********************************************************************** | ||||||
|  | // <copyright file="UserService.cs"> | ||||||
|  | //     AgileWebs | ||||||
|  | // </copyright> | ||||||
|  | // *********************************************************************** | ||||||
|  |  | ||||||
|  | using Core.Blueprint.Mongo; | ||||||
|  | using Core.Blueprint.Redis; | ||||||
|  | using Core.Blueprint.Redis.Helpers; | ||||||
|  | using Core.Thalos.BuildingBlocks; | ||||||
|  | using Core.Thalos.Provider.Contracts; | ||||||
|  | using Mapster; | ||||||
|  | using MongoDB.Bson; | ||||||
|  | using MongoDB.Bson.Serialization; | ||||||
|  | using MongoDB.Driver; | ||||||
|  | using System.Text.RegularExpressions; | ||||||
|  |  | ||||||
|  | namespace Core.Thalos.Provider.Providers.Onboarding | ||||||
|  | { | ||||||
|  |     /// <summary> | ||||||
|  |     /// Handles all services and business rules related to <see cref="UserAdapter"/>. | ||||||
|  |     /// </summary> | ||||||
|  |     public class UserProvider : IUserProvider | ||||||
|  |     { | ||||||
|  |         private readonly CollectionRepository<UserAdapter> repository; | ||||||
|  |         private readonly ICacheSettings cacheSettings; | ||||||
|  |         private readonly IRedisCacheProvider cacheProvider; | ||||||
|  |  | ||||||
|  |         public UserProvider(CollectionRepository<UserAdapter> repository, | ||||||
|  |             IRedisCacheProvider cacheProvider, | ||||||
|  |             ICacheSettings cacheSettings | ||||||
|  |             ) | ||||||
|  |         { | ||||||
|  |             this.repository = repository; | ||||||
|  |             this.repository.CollectionInitialization(); | ||||||
|  |             this.cacheSettings = cacheSettings; | ||||||
|  |             this.cacheProvider = cacheProvider; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Creates a new User. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="newUser">The User to be created.</param> | ||||||
|  |         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||||
|  |         /// the asynchronous execution of the service.</returns> | ||||||
|  |         public async ValueTask<UserAdapter> CreateUser(Core.Thalos.Domain.Contexts.Onboarding.Request.UserRequest newUser, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var userCollection = newUser.Adapt<UserAdapter>(); | ||||||
|  |  | ||||||
|  |             await repository.InsertOneAsync(userCollection); | ||||||
|  |  | ||||||
|  |             return userCollection; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets an User by identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The User mongo identifier.</param> | ||||||
|  |         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||||
|  |         /// the asynchronous execution of the service.</returns> | ||||||
|  |         public async ValueTask<UserAdapter> GetUserById(string _id, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetUserById", _id); | ||||||
|  |             var cachedData = await cacheProvider.GetAsync<UserAdapter>(cacheKey); | ||||||
|  |  | ||||||
|  |             if (cachedData is not null) { return cachedData; } | ||||||
|  |  | ||||||
|  |             var user = await repository.FindByIdAsync(_id); | ||||||
|  |  | ||||||
|  |             await cacheProvider.SetAsync(cacheKey, user, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes)); | ||||||
|  |  | ||||||
|  |             return user; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets all the users. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <returns>A <see cref="{Task{IEnumerable{UserAdapter}}}"/> representing | ||||||
|  |         /// the asynchronous execution of the service.</returns> | ||||||
|  |         public async ValueTask<IEnumerable<UserAdapter>> GetAllUsers(CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllUsers"); | ||||||
|  |             var cachedData = await cacheProvider.GetAsync<IEnumerable<UserAdapter>>(cacheKey) ?? []; | ||||||
|  |  | ||||||
|  |             if (cachedData.Any()) return cachedData; | ||||||
|  |  | ||||||
|  |             var users = await repository.AsQueryable(); | ||||||
|  |  | ||||||
|  |             await cacheProvider.SetAsync(cacheKey, users, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes)); | ||||||
|  |  | ||||||
|  |             return users; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets an User by email. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="email">The User email.</param> | ||||||
|  |         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||||
|  |         /// the asynchronous execution of the service.</returns> | ||||||
|  |         public async ValueTask<UserAdapter> GetUserByEmail(string email, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetUserByEmail", email); | ||||||
|  |             var cachedData = await cacheProvider.GetAsync<UserAdapter>(cacheKey); | ||||||
|  |  | ||||||
|  |             //if (cachedData is not null) { return cachedData; } | ||||||
|  |  | ||||||
|  |             var user = await repository.FindOneAsync( | ||||||
|  |                 u => u.Email == email && | ||||||
|  |                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); | ||||||
|  |  | ||||||
|  |             await cacheProvider.SetAsync(cacheKey, user); | ||||||
|  |  | ||||||
|  |             return user; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Validates if a users exists by email.. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="email">The User email.</param> | ||||||
|  |         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||||
|  |         /// the asynchronous execution of the service.</returns> | ||||||
|  |         public async ValueTask<UserExistenceAdapter> ValidateUserExistence(string email, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetUserByEmail", email); | ||||||
|  |             var cachedData = await cacheProvider.GetAsync<UserAdapter>(cacheKey); | ||||||
|  |  | ||||||
|  |             //if (cachedData is not null) { return cachedData; } | ||||||
|  |  | ||||||
|  |             var user = await repository.FindOneAsync( | ||||||
|  |                 u => u.Email == email && | ||||||
|  |                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); | ||||||
|  |  | ||||||
|  |             UserExistenceAdapter userExistance = new UserExistenceAdapter(); | ||||||
|  |  | ||||||
|  |             userExistance.Existence = (user != null) ? true : false; | ||||||
|  |  | ||||||
|  |             await cacheProvider.SetAsync(cacheKey, userExistance); | ||||||
|  |  | ||||||
|  |             return userExistance; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Changes the status of the user. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The user mongo identifier.</param> | ||||||
|  |         /// <param name="newStatus">The new status of the user.</param> | ||||||
|  |         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||||
|  |         /// the asynchronous execution of the service.</returns> | ||||||
|  |         public async ValueTask<UserAdapter?> ChangeUserStatus(string _id, Core.Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var entity = await repository.FindByIdAsync(_id); | ||||||
|  |  | ||||||
|  |             if (entity is not null) | ||||||
|  |             { | ||||||
|  |                 entity.Status = newStatus; | ||||||
|  |  | ||||||
|  |                 return repository.ReplaceOneAsync(entity).Result; | ||||||
|  |             } | ||||||
|  |             else return null; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Updates a User by _id. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="entity">The User to be updated.</param> | ||||||
|  |         /// <param name="_id">The User mongo identifier.</param> | ||||||
|  |         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||||
|  |         /// the asynchronous execution of the service.</returns> | ||||||
|  |         public async ValueTask<UserAdapter?> UpdateUser(UserAdapter entity, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var updatedEntity = await repository.ReplaceOneAsync(entity); | ||||||
|  |             return updatedEntity; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Logs in the user. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The User mongo identifier.</param> | ||||||
|  |         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||||
|  |         /// the asynchronous execution of the service.</returns> | ||||||
|  |         public async ValueTask<UserAdapter?> LogInUser(string email, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var user = await repository.FindOneAsync( | ||||||
|  |                 u => u.Email == email && | ||||||
|  |                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); | ||||||
|  |  | ||||||
|  |             user.LastLogIn = DateTime.UtcNow; | ||||||
|  |  | ||||||
|  |             await repository.ReplaceOneAsync(user); | ||||||
|  |  | ||||||
|  |             return user; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Logs out the user's session. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="email">The User email.</param> | ||||||
|  |         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||||
|  |         /// the asynchronous execution of the service.</returns> | ||||||
|  |         public async ValueTask<UserAdapter?> LogOutUserSession(string email, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var user = await repository.FindOneAsync( | ||||||
|  |                 u => u.Email == email && | ||||||
|  |                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); | ||||||
|  |  | ||||||
|  |             user.LastLogOut = DateTime.UtcNow; | ||||||
|  |  | ||||||
|  |             await repository.ReplaceOneAsync(user); | ||||||
|  |  | ||||||
|  |             return user; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets the token adapter for a user. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="email">The user's email.</param> | ||||||
|  |         /// <returns>A <see cref="{Task{TokenAdapter}}"/> representing the asynchronous execution of the service.</returns> | ||||||
|  |         public async ValueTask<TokenAdapter?> GetToken(string email, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 var pipeline = new[] | ||||||
|  |                 { | ||||||
|  |             new BsonDocument("$match", new BsonDocument | ||||||
|  |             { | ||||||
|  |                 { "email", new BsonDocument | ||||||
|  |                     { | ||||||
|  |                         { "$regex", $"^{Regex.Escape(email)}$" }, | ||||||
|  |                         { "$options", "i" } | ||||||
|  |                     } | ||||||
|  |                 }, | ||||||
|  |                 { "status", Core.Blueprint.Mongo.StatusEnum.Active.ToString() } | ||||||
|  |             }), | ||||||
|  |             new BsonDocument("$lookup", new BsonDocument | ||||||
|  |             { | ||||||
|  |                 { "from", "Roles" }, | ||||||
|  |                 { "localField", "roleId" }, | ||||||
|  |                 { "foreignField", "_id" }, | ||||||
|  |                 { "as", "role" } | ||||||
|  |             }), | ||||||
|  |             new BsonDocument("$unwind", "$role"), | ||||||
|  |             new BsonDocument("$match", new BsonDocument("role.status", Core.Blueprint.Mongo.StatusEnum.Active.ToString())), | ||||||
|  |             new BsonDocument("$lookup", new BsonDocument | ||||||
|  |             { | ||||||
|  |                 { "from", "Tenants" }, | ||||||
|  |                 { "localField", "tenantId" }, | ||||||
|  |                 { "foreignField", "_id" }, | ||||||
|  |                 { "as", "tenant" } | ||||||
|  |             }), | ||||||
|  |             new BsonDocument("$unwind", "$tenant"), | ||||||
|  |             new BsonDocument("$addFields", new BsonDocument | ||||||
|  |             { | ||||||
|  |                 { "role.permissions", new BsonDocument("$map", new BsonDocument | ||||||
|  |                     { | ||||||
|  |                         { "input", "$role.permissions" }, | ||||||
|  |                         { "as", "perm" }, | ||||||
|  |                         { "in", new BsonDocument("$toObjectId", "$$perm") } | ||||||
|  |                     }) | ||||||
|  |                 }, | ||||||
|  |                 { "role.modules", new BsonDocument("$map", new BsonDocument | ||||||
|  |                     { | ||||||
|  |                         { "input", "$role.modules" }, | ||||||
|  |                         { "as", "mod" }, | ||||||
|  |                         { "in", new BsonDocument("$toObjectId", "$$mod") } | ||||||
|  |                     }) | ||||||
|  |                 } | ||||||
|  |             }), | ||||||
|  |             new BsonDocument("$lookup", new BsonDocument | ||||||
|  |             { | ||||||
|  |                 { "from", "Permissions" }, | ||||||
|  |                 { "localField", "role.permissions" }, | ||||||
|  |                 { "foreignField", "_id" }, | ||||||
|  |                 { "as", "permissions" } | ||||||
|  |             }), | ||||||
|  |             new BsonDocument("$lookup", new BsonDocument | ||||||
|  |             { | ||||||
|  |                 { "from", "Modules" }, | ||||||
|  |                 { "localField", "role.modules" }, | ||||||
|  |                 { "foreignField", "_id" }, | ||||||
|  |                 { "as", "modules" } | ||||||
|  |             }), | ||||||
|  |             new BsonDocument("$project", new BsonDocument | ||||||
|  |             { | ||||||
|  |                 { "_id", 1 }, | ||||||
|  |                 { "guid", 1 }, | ||||||
|  |                 { "email", 1 }, | ||||||
|  |                 { "name", 1 }, | ||||||
|  |                 { "middleName", 1 }, | ||||||
|  |                 { "lastName", 1 }, | ||||||
|  |                 { "displayName", 1 }, | ||||||
|  |                 { "roleId", 1 }, | ||||||
|  |                 { "companies", 1 }, | ||||||
|  |                 { "projects", 1 }, | ||||||
|  |                 { "lastLogIn", 1 }, | ||||||
|  |                 { "lastLogOut", 1 }, | ||||||
|  |                 { "createdBy", 1 }, | ||||||
|  |                 { "updatedBy", 1 }, | ||||||
|  |                 { "status", 1 }, | ||||||
|  |                 { "createdAt", 1 }, | ||||||
|  |                 { "updatedAt", 1 }, | ||||||
|  |                 { "role._id", 1 }, | ||||||
|  |                 { "role.name", 1 }, | ||||||
|  |                 { "role.description", 1 }, | ||||||
|  |                 { "role.applications", 1 }, | ||||||
|  |                 { "role.permissions", 1 }, | ||||||
|  |                 { "role.modules", 1 }, | ||||||
|  |                 { "role.status", 1 }, | ||||||
|  |                 { "role.createdAt", 1 }, | ||||||
|  |                 { "role.updatedAt", 1 }, | ||||||
|  |                 { "role.createdBy", 1 }, | ||||||
|  |                 { "role.updatedBy", 1 }, | ||||||
|  |                 { "tenant._id", 1 }, | ||||||
|  |                 { "tenant.name", 1 }, | ||||||
|  |                 { "tenant.taxIdentifier", 1 }, | ||||||
|  |                 { "tenant.addressLine1", 1 }, | ||||||
|  |                 { "tenant.addressLine2", 1 }, | ||||||
|  |                 { "tenant.city", 1 }, | ||||||
|  |                 { "tenant.state", 1 }, | ||||||
|  |                 { "tenant.country", 1 }, | ||||||
|  |                 { "tenant.postalCode", 1 }, | ||||||
|  |                 { "tenant.contactEmail", 1 }, | ||||||
|  |                 { "tenant.contactPhone", 1 }, | ||||||
|  |                 { "tenant.website", 1 }, | ||||||
|  |                 { "tenant.connectionString", 1 }, | ||||||
|  |                 { "tenant.isolated", 1 }, | ||||||
|  |                 { "tenant.status", 1 }, | ||||||
|  |                 { "tenant.createdAt", 1 }, | ||||||
|  |                 { "tenant.updatedAt", 1 }, | ||||||
|  |                 { "tenant.createdBy", 1 }, | ||||||
|  |                 { "tenant.updatedBy", 1 }, | ||||||
|  |                 { "permissions", 1 }, | ||||||
|  |                 { "modules", 1 } | ||||||
|  |             }) | ||||||
|  |         }; | ||||||
|  |  | ||||||
|  |                 var result = await repository.FindOnePipelineAsync<BsonDocument>(pipeline); | ||||||
|  |  | ||||||
|  |                 if (result is null) return null; | ||||||
|  |  | ||||||
|  |                 DateTime SafeToUtc(BsonValue value) | ||||||
|  |                 { | ||||||
|  |                     if (value == null || value.IsBsonNull) return DateTime.MinValue; | ||||||
|  |                     return value.IsBsonDateTime ? value.ToUniversalTime() : DateTime.MinValue; | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 var tokenAdapter = new TokenAdapter | ||||||
|  |                 { | ||||||
|  |                     User = new UserAdapter | ||||||
|  |                     { | ||||||
|  |                         _Id = result["_id"]?.ToString() ?? "", | ||||||
|  |                         Email = result.Contains("email") && !result["email"].IsBsonNull ? result["email"].AsString : string.Empty, | ||||||
|  |                         Name = result.Contains("name") && !result["name"].IsBsonNull ? result["name"].AsString : string.Empty, | ||||||
|  |                         MiddleName = result.Contains("middleName") && !result["middleName"].IsBsonNull ? result["middleName"].AsString : string.Empty, | ||||||
|  |                         LastName = result.Contains("lastName") && !result["lastName"].IsBsonNull ? result["lastName"].AsString : string.Empty, | ||||||
|  |                         DisplayName = result.Contains("displayName") && !result["displayName"].IsBsonNull ? result["displayName"].AsString : string.Empty, | ||||||
|  |                         RoleId = result.Contains("roleId") && !result["roleId"].IsBsonNull ? result["roleId"].ToString() : string.Empty, | ||||||
|  |                         LastLogIn = SafeToUtc(result.Contains("lastLogIn") ? result["lastLogIn"] : null), | ||||||
|  |                         LastLogOut = SafeToUtc(result.Contains("lastLogOut") ? result["lastLogOut"] : null), | ||||||
|  |                         CreatedAt = SafeToUtc(result.Contains("createdAt") ? result["createdAt"] : null), | ||||||
|  |                         UpdatedAt = SafeToUtc(result.Contains("updatedAt") ? result["updatedAt"] : null), | ||||||
|  |                         CreatedBy = result.Contains("createdBy") && !result["createdBy"].IsBsonNull ? result["createdBy"].AsString : string.Empty, | ||||||
|  |                         UpdatedBy = result.Contains("updatedBy") && !result["updatedBy"].IsBsonNull ? result["updatedBy"].AsString : string.Empty, | ||||||
|  |                         Status = result.Contains("status") && !result["status"].IsBsonNull | ||||||
|  |                             ? (Core.Blueprint.Mongo.StatusEnum)Enum.Parse(typeof(Core.Blueprint.Mongo.StatusEnum), result["status"].AsString) | ||||||
|  |                             : Core.Blueprint.Mongo.StatusEnum.Inactive | ||||||
|  |                     }, | ||||||
|  |                     Role = new RoleAdapter | ||||||
|  |                     { | ||||||
|  |                         Id = result.Contains("role") && result["role"].IsBsonDocument && result["role"].AsBsonDocument.Contains("_id") | ||||||
|  |                             ? result["role"]["_id"]?.ToString() ?? "" | ||||||
|  |                             : string.Empty, | ||||||
|  |                         Name = result.Contains("role") && result["role"].IsBsonDocument && result["role"].AsBsonDocument.Contains("name") | ||||||
|  |                             ? result["role"]["name"]?.AsString ?? "" | ||||||
|  |                             : string.Empty, | ||||||
|  |                         Description = result.Contains("role") && result["role"].IsBsonDocument && result["role"].AsBsonDocument.Contains("description") | ||||||
|  |                             ? result["role"]["description"]?.AsString ?? "" | ||||||
|  |                             : string.Empty, | ||||||
|  |                         Applications = result.Contains("role") && result["role"].IsBsonDocument && | ||||||
|  |                        result["role"].AsBsonDocument.Contains("applications") && | ||||||
|  |                        result["role"]["applications"].IsBsonArray | ||||||
|  |                             ? result["role"]["applications"].AsBsonArray | ||||||
|  |                                 .Where(app => app != null && app.IsInt32) | ||||||
|  |                                 .Select(app => (ApplicationsEnum)app.AsInt32) | ||||||
|  |                                 .ToArray() | ||||||
|  |                             : Array.Empty<ApplicationsEnum>(), | ||||||
|  |                         Modules = result.Contains("role") && result["role"].IsBsonDocument && | ||||||
|  |                             result["role"].AsBsonDocument.Contains("modules") && | ||||||
|  |                             result["role"]["modules"].IsBsonArray | ||||||
|  |                             ? result["role"]["modules"].AsBsonArray | ||||||
|  |                                 .Where(m => m != null) | ||||||
|  |                                 .Select(m => m.ToString() ?? "") | ||||||
|  |                                 .ToArray() | ||||||
|  |                             : Array.Empty<string>(), | ||||||
|  |                         Permissions = result.Contains("role") && result["role"].IsBsonDocument && | ||||||
|  |                             result["role"].AsBsonDocument.Contains("permissions") && | ||||||
|  |                             result["role"]["permissions"].IsBsonArray | ||||||
|  |                             ? result["role"]["permissions"].AsBsonArray | ||||||
|  |                                 .Where(p => p != null) | ||||||
|  |                                 .Select(p => p.ToString() ?? "") | ||||||
|  |                                 .ToArray() | ||||||
|  |                             : Array.Empty<string>(), | ||||||
|  |                         Status = result.Contains("role") && result["role"].IsBsonDocument && | ||||||
|  |                              result["role"].AsBsonDocument.Contains("status") && | ||||||
|  |                              !result["role"]["status"].IsBsonNull | ||||||
|  |                             ? (Core.Blueprint.Mongo.StatusEnum)Enum.Parse(typeof(Core.Blueprint.Mongo.StatusEnum), result["role"]["status"].AsString) | ||||||
|  |                             : Core.Blueprint.Mongo.StatusEnum.Inactive, | ||||||
|  |                         CreatedAt = SafeToUtc(result.Contains("role") && result["role"].IsBsonDocument && result["role"].AsBsonDocument.Contains("createdAt") | ||||||
|  |                             ? result["role"]["createdAt"] | ||||||
|  |                             : null), | ||||||
|  |                         UpdatedAt = SafeToUtc(result.Contains("role") && result["role"].IsBsonDocument && result["role"].AsBsonDocument.Contains("updatedAt") | ||||||
|  |                             ? result["role"]["updatedAt"] | ||||||
|  |                             : null), | ||||||
|  |                         CreatedBy = result.Contains("role") && result["role"].IsBsonDocument && | ||||||
|  |                             result["role"].AsBsonDocument.Contains("createdBy") && !result["role"]["createdBy"].IsBsonNull | ||||||
|  |                             ? result["role"]["createdBy"].AsString | ||||||
|  |                             : string.Empty, | ||||||
|  |                         UpdatedBy = result.Contains("role") && result["role"].IsBsonDocument && | ||||||
|  |                             result["role"].AsBsonDocument.Contains("updatedBy") && !result["role"]["updatedBy"].IsBsonNull | ||||||
|  |                             ? result["role"]["updatedBy"].AsString | ||||||
|  |                             : string.Empty | ||||||
|  |                     }, | ||||||
|  |                     Tenant = result.Contains("tenant") && result["tenant"].IsBsonDocument | ||||||
|  |                     ? new TenantAdapter | ||||||
|  |                     { | ||||||
|  |                         Id = result.Contains("tenant") && result["tenant"].IsBsonDocument && result["tenant"].AsBsonDocument.Contains("_id") | ||||||
|  |                             ? result["tenant"]["_id"]?.ToString() ?? "" | ||||||
|  |                             : string.Empty, | ||||||
|  |                         Name = result["tenant"].AsBsonDocument.Contains("name") && !result["tenant"]["name"].IsBsonNull | ||||||
|  |                             ? result["tenant"]["name"].AsString | ||||||
|  |                             : string.Empty, | ||||||
|  |                         TaxIdentifier = result["tenant"].AsBsonDocument.Contains("taxIdentifier") && !result["tenant"]["taxIdentifier"].IsBsonNull | ||||||
|  |                             ? result["tenant"]["taxIdentifier"].AsString | ||||||
|  |                             : string.Empty, | ||||||
|  |                         AddressLine1 = result["tenant"].AsBsonDocument.Contains("addressLine1") && !result["tenant"]["addressLine1"].IsBsonNull | ||||||
|  |                             ? result["tenant"]["addressLine1"].AsString | ||||||
|  |                             : string.Empty, | ||||||
|  |                         AddressLine2 = result["tenant"].AsBsonDocument.Contains("addressLine2") && !result["tenant"]["addressLine2"].IsBsonNull | ||||||
|  |                             ? result["tenant"]["addressLine2"].AsString | ||||||
|  |                             : null, | ||||||
|  |                         City = result["tenant"].AsBsonDocument.Contains("city") && !result["tenant"]["city"].IsBsonNull | ||||||
|  |                             ? result["tenant"]["city"].AsString | ||||||
|  |                             : string.Empty, | ||||||
|  |                         State = result["tenant"].AsBsonDocument.Contains("state") && !result["tenant"]["state"].IsBsonNull | ||||||
|  |                             ? result["tenant"]["state"].AsString | ||||||
|  |                             : string.Empty, | ||||||
|  |                         Country = result["tenant"].AsBsonDocument.Contains("country") && !result["tenant"]["country"].IsBsonNull | ||||||
|  |                             ? result["tenant"]["country"].AsString | ||||||
|  |                             : string.Empty, | ||||||
|  |                         PostalCode = result["tenant"].AsBsonDocument.Contains("postalCode") && !result["tenant"]["postalCode"].IsBsonNull | ||||||
|  |                             ? result["tenant"]["postalCode"].AsString | ||||||
|  |                             : string.Empty, | ||||||
|  |                         ContactEmail = result["tenant"].AsBsonDocument.Contains("contactEmail") && !result["tenant"]["contactEmail"].IsBsonNull | ||||||
|  |                             ? result["tenant"]["contactEmail"].AsString | ||||||
|  |                             : string.Empty, | ||||||
|  |                         ContactPhone = result["tenant"].AsBsonDocument.Contains("contactPhone") && !result["tenant"]["contactPhone"].IsBsonNull | ||||||
|  |                             ? result["tenant"]["contactPhone"].AsString | ||||||
|  |                             : string.Empty, | ||||||
|  |                         Website = result["tenant"].AsBsonDocument.Contains("website") && !result["tenant"]["website"].IsBsonNull | ||||||
|  |                             ? result["tenant"]["website"].AsString | ||||||
|  |                             : null, | ||||||
|  |                         ConnectionString = result["tenant"].AsBsonDocument.Contains("connectionString") && !result["tenant"]["connectionString"].IsBsonNull | ||||||
|  |                             ? result["tenant"]["connectionString"].AsString | ||||||
|  |                             : null, | ||||||
|  |                         Isolated = result["tenant"].AsBsonDocument.Contains("isolated") && !result["tenant"]["isolated"].IsBsonNull | ||||||
|  |                             ? result["tenant"]["isolated"].ToBoolean() | ||||||
|  |                             : false, | ||||||
|  |                         CreatedAt = SafeToUtc(result.Contains("tenant") && result["tenant"].IsBsonDocument && result["tenant"].AsBsonDocument.Contains("createdAt") | ||||||
|  |                             ? result["tenant"]["createdAt"] | ||||||
|  |                             : null), | ||||||
|  |                         UpdatedAt = SafeToUtc(result.Contains("tenant") && result["tenant"].IsBsonDocument && result["tenant"].AsBsonDocument.Contains("updatedAt") | ||||||
|  |                             ? result["tenant"]["updatedAt"] | ||||||
|  |                             : null), | ||||||
|  |                         CreatedBy = result["tenant"].AsBsonDocument.Contains("createdBy") && !result["tenant"]["createdBy"].IsBsonNull | ||||||
|  |                             ? result["tenant"]["createdBy"].AsString | ||||||
|  |                             : string.Empty, | ||||||
|  |                         UpdatedBy = result["tenant"].AsBsonDocument.Contains("updatedBy") && !result["tenant"]["updatedBy"].IsBsonNull | ||||||
|  |                             ? result["tenant"]["updatedBy"].AsString | ||||||
|  |                             : string.Empty, | ||||||
|  |                         Status = result["tenant"].AsBsonDocument.Contains("status") && !result["tenant"]["status"].IsBsonNull | ||||||
|  |                             ? (Core.Blueprint.Mongo.StatusEnum)Enum.Parse(typeof(Core.Blueprint.Mongo.StatusEnum), result["tenant"]["status"].AsString) | ||||||
|  |                             : Core.Blueprint.Mongo.StatusEnum.Active | ||||||
|  |                     } | ||||||
|  |                     : null, | ||||||
|  |                     Permissions = result.Contains("permissions") && result["permissions"].IsBsonArray | ||||||
|  |                         ? result["permissions"].AsBsonArray | ||||||
|  |                             .Where(p => p != null && p.IsBsonDocument) | ||||||
|  |                             .Select(p => BsonSerializer.Deserialize<PermissionAdapter>(p.AsBsonDocument)) | ||||||
|  |                             .Where(p => p.Status == Core.Blueprint.Mongo.StatusEnum.Active) | ||||||
|  |                             .ToList() | ||||||
|  |                         : new List<PermissionAdapter>(), | ||||||
|  |                     Modules = result.Contains("modules") && result["modules"].IsBsonArray | ||||||
|  |                     ? result["modules"].AsBsonArray | ||||||
|  |                         .Where(p => p != null && p.IsBsonDocument) | ||||||
|  |                         .Select(p => BsonSerializer.Deserialize<ModuleAdapter>(p.AsBsonDocument)) | ||||||
|  |                         .Where(p => p.Status == Core.Blueprint.Mongo.StatusEnum.Active) | ||||||
|  |                         .ToList() | ||||||
|  |                     : new List<ModuleAdapter>() | ||||||
|  |                 }; | ||||||
|  |  | ||||||
|  |                 return tokenAdapter; | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 throw new Exception(ex.Message, ex); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Deletes an User by _id. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="_id">The User mongo identifier.</param> | ||||||
|  |         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||||
|  |         /// the asynchronous execution of the service.</returns> | ||||||
|  |         public async ValueTask<UserAdapter?> DeleteUser(string _id, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var entity = await repository.DeleteOneAsync(doc => doc.Id == _id); | ||||||
|  |  | ||||||
|  |             return entity; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										33
									
								
								Core.Thalos.Provider/ServiceCollectionExtensions.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								Core.Thalos.Provider/ServiceCollectionExtensions.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,33 @@ | |||||||
|  | using Core.Blueprint.Mongo; | ||||||
|  | using Core.Thalos.BuildingBlocks; | ||||||
|  | using Core.Thalos.Provider.Contracts; | ||||||
|  | using Core.Thalos.Provider.Providers.Onboarding; | ||||||
|  | using Microsoft.Extensions.Configuration; | ||||||
|  | using Microsoft.Extensions.DependencyInjection; | ||||||
|  |  | ||||||
|  | namespace Core.Thalos.Provider | ||||||
|  | { | ||||||
|  |     public static class ServiceCollectionExtensions | ||||||
|  |     { | ||||||
|  |         public static IServiceCollection AddDALLayerServices(this IServiceCollection services, IConfiguration configuration) | ||||||
|  |         { | ||||||
|  |             //Mongo | ||||||
|  |             services.AddScoped<IModuleProvider, ModuleProvider>(); | ||||||
|  |             services.AddScoped<CollectionRepository<ModuleAdapter>>(); | ||||||
|  |  | ||||||
|  |             services.AddScoped<IPermissionProvider, PermissionProvider>(); | ||||||
|  |             services.AddScoped<CollectionRepository<PermissionAdapter>>(); | ||||||
|  |  | ||||||
|  |             services.AddScoped<IRoleProvider, RoleProvider>(); | ||||||
|  |             services.AddScoped<CollectionRepository<RoleAdapter>>(); | ||||||
|  |  | ||||||
|  |             services.AddScoped<IUserProvider, UserProvider>(); | ||||||
|  |             services.AddScoped<CollectionRepository<UserAdapter>>(); | ||||||
|  |  | ||||||
|  |             services.AddScoped<ITenantProvider, TenantProvider>(); | ||||||
|  |             services.AddScoped<CollectionRepository<TenantAdapter>>(); | ||||||
|  |  | ||||||
|  |             return services; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										40
									
								
								Dockerfile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								Dockerfile
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,40 @@ | |||||||
|  | # ============ Build ============ | ||||||
|  | FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build | ||||||
|  | WORKDIR /src | ||||||
|  |  | ||||||
|  | # Copia opcional del nuget.config si existe en el root | ||||||
|  | COPY nuget.config* ./ | ||||||
|  |  | ||||||
|  | # Copiamos csprojs primero para aprovechar caché de restore | ||||||
|  | COPY Core.Thalos.Domain/Core.Thalos.Domain.csproj Core.Thalos.Domain/ | ||||||
|  | COPY Core.Thalos.Provider/Core.Thalos.Provider.csproj Core.Thalos.Provider/ | ||||||
|  | COPY Core.Thalos.Infraestructure/Core.Thalos.Infrastructure.csproj Core.Thalos.Infraestructure/ | ||||||
|  | COPY Core.Thalos.DAL.API/Core.Thalos.DAL.API.csproj Core.Thalos.DAL.API/ | ||||||
|  |  | ||||||
|  | RUN dotnet restore Core.Thalos.DAL.API/Core.Thalos.DAL.API.csproj | ||||||
|  |  | ||||||
|  | # Copiamos el resto y compilamos | ||||||
|  | COPY . . | ||||||
|  | RUN dotnet build Core.Thalos.DAL.API/Core.Thalos.DAL.API.csproj -c Release -o /app/build | ||||||
|  |  | ||||||
|  | # ============ Publish ============ | ||||||
|  | FROM build AS publish | ||||||
|  | RUN dotnet publish Core.Thalos.DAL.API/Core.Thalos.DAL.API.csproj -c Release -o /app/publish \ | ||||||
|  |     --no-restore | ||||||
|  |  | ||||||
|  | # ============ Runtime ============ | ||||||
|  | FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final | ||||||
|  | # (Opcional) instalar curl para healthcheck HTTP | ||||||
|  | RUN apt-get update && apt-get install -y --no-install-recommends curl && rm -rf /var/lib/apt/lists/* | ||||||
|  |  | ||||||
|  | WORKDIR /app | ||||||
|  | EXPOSE 8080 | ||||||
|  | # Usuario no-root | ||||||
|  | RUN useradd -m appuser | ||||||
|  | USER appuser | ||||||
|  |  | ||||||
|  | ENV ASPNETCORE_URLS=http://+:8080 | ||||||
|  | # Usa env vars y/o UserSecrets; no guardes tokens en la imagen.  :contentReference[oaicite:4]{index=4} | ||||||
|  |  | ||||||
|  | COPY --from=publish /app/publish ./ | ||||||
|  | ENTRYPOINT ["dotnet", "Core.Thalos.DAL.API.dll"] | ||||||
							
								
								
									
										9
									
								
								nuget.config
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								nuget.config
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | |||||||
|  | <?xml version="1.0" encoding="utf-8"?> | ||||||
|  | <configuration> | ||||||
|  |   <packageSources> | ||||||
|  |     <!-- Tu BaGet primero --> | ||||||
|  |     <add key="BaGet" value="https://nuget.dream-views.com/v3/index.json" protocolVersion="3" /> | ||||||
|  |     <!-- NuGet oficial como fallback (si quieres) --> | ||||||
|  |     <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" /> | ||||||
|  |   </packageSources> | ||||||
|  | </configuration> | ||||||
		Reference in New Issue
	
	Block a user