Compare commits
	
		
			20 Commits
		
	
	
		
			bugfix/fix
			...
			bugfix/adj
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 35a0a01221 | |||
| 24a5fd28fb | |||
| 827e5ec270 | |||
| fc8d385a13 | |||
| e456913233 | |||
| 0eadd6e217 | |||
| 7c92a7e791 | |||
| 570e74a199 | |||
| 9590a03cee | |||
|   | 82166f5042 | ||
|   | a14cec8fb1 | ||
| 5922a53b93 | |||
| 13774093b4 | |||
| 7cd08411b9 | |||
| 1d52ee424d | |||
| 4a26ecc83a | |||
| c85897fd1a | |||
| 3511043209 | |||
|   | 99964d14b8 | ||
| 1ae0b600ae | 
| @@ -9,8 +9,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Application", "Application" | |||||||
| EndProject | EndProject | ||||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Thalos.Domain", "Core.Thalos.Domain\Core.Thalos.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.Thalos.Infrastructure", "Core.Thalos.Infraestructure\Core.Thalos.Infrastructure.csproj", "{43BD5F47-132F-4E78-83F1-A1FEED01A502}" |  | ||||||
| EndProject |  | ||||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Thalos.Provider", "Core.Thalos.Provider\Core.Thalos.Provider.csproj", "{8CAE8380-475F-46B8-AF90-C495AAC58606}" | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Thalos.Provider", "Core.Thalos.Provider\Core.Thalos.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}" | ||||||
| @@ -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 | ||||||
|   | |||||||
| @@ -5,98 +5,68 @@ | |||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
|  |  | ||||||
| using Asp.Versioning; | using Asp.Versioning; | ||||||
| using Core.Blueprint.Mongo; | using Core.Thalos.BuildingBlocks; | ||||||
| using Core.Thalos.Adapters; |  | ||||||
| using Core.Thalos.Adapters.Attributes; |  | ||||||
| using Core.Thalos.Adapters.Common.Constants; |  | ||||||
| using Core.Thalos.Provider.Contracts; | using Core.Thalos.Provider.Contracts; | ||||||
| using Microsoft.AspNetCore.Authorization; | using Microsoft.AspNetCore.Authorization; | ||||||
| using Microsoft.AspNetCore.Mvc; | using Microsoft.AspNetCore.Mvc; | ||||||
| using Microsoft.Graph; |  | ||||||
| using ModuleRequest = Core.Thalos.Domain.Contexts.Onboarding.Request.ModuleRequest; | using ModuleRequest = Core.Thalos.Domain.Contexts.Onboarding.Request.ModuleRequest; | ||||||
|  | using StatusEnum = Core.Blueprint.Mongo.StatusEnum; | ||||||
|  |  | ||||||
| namespace LSA.Core.Thalos.API.Controllers | namespace LSA.Core.Thalos.API.Controllers | ||||||
| { | { | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// Handles all requests for module authentication. |     /// Handles all requests for module management. | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [ApiVersion(MimeTypes.ApplicationVersion)] |     [ApiVersion(MimeTypes.ApplicationVersion)] | ||||||
|     [Route("api/v{api-version:apiVersion}/[controller]")] |     [Route("api/v{api-version:apiVersion}/[controller]")] | ||||||
|     [Produces(MimeTypes.ApplicationJson)] |     [Produces(MimeTypes.ApplicationJson)] | ||||||
|     [Consumes(MimeTypes.ApplicationJson)] |     [Consumes(MimeTypes.ApplicationJson)] | ||||||
|     [ApiController] |     [ApiController] | ||||||
|     [AllowAnonymous] |     [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|     public class ModuleController(IModuleProvider service) : ControllerBase |     public class ModuleController(IModuleProvider service) : ControllerBase | ||||||
|     { |     { | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets all the modules. |         /// Gets all modules. | ||||||
|         /// </summary> |         /// </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] |         [HttpGet] | ||||||
|         [Consumes(MimeTypes.ApplicationJson)] |  | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |  | ||||||
|         [ProducesResponseType(typeof(IEnumerable<ModuleAdapter>), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(IEnumerable<ModuleAdapter>), StatusCodes.Status200OK)] | ||||||
|         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |         [Permission("ModuleManagement.Read, RoleManagement.Read")] | ||||||
|         //[Permission("ModuleManagement.Read, RoleManagement.Read")] |  | ||||||
|         public async Task<IActionResult> GetAllModulesAsync(CancellationToken cancellationToken) |         public async Task<IActionResult> GetAllModulesAsync(CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.GetAllModules(cancellationToken).ConfigureAwait(false); |             var result = await service.GetAllModules(cancellationToken); | ||||||
|             return Ok(result); |             return Ok(result); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets all the modules by module identifiers. |         /// Gets all the modules by module identifiers. | ||||||
|         /// </summary> |         /// </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] |         [HttpPost] | ||||||
|         [Route(Routes.GetModuleList)] |         [Route(Routes.GetModuleList)] | ||||||
|         [Consumes(MimeTypes.ApplicationJson)] |  | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |  | ||||||
|         [ProducesResponseType(typeof(IEnumerable<ModuleAdapter>), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(IEnumerable<ModuleAdapter>), StatusCodes.Status200OK)] | ||||||
|         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |         [Permission("ModuleManagement.Read")] | ||||||
|         //[Permission("ModuleManagement.Read")] |  | ||||||
|         public async Task<IActionResult> GetAllModulesByList([FromBody] string[] modules, CancellationToken cancellationToken) |         public async Task<IActionResult> GetAllModulesByList([FromBody] string[] modules, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             if (modules == null || !modules.Any()) |             if (modules == null || !modules.Any()) | ||||||
|             { |  | ||||||
|                 return BadRequest("Module identifiers are required."); |                 return BadRequest("Module identifiers are required."); | ||||||
|             } |  | ||||||
|  |  | ||||||
|             var result = await service.GetAllModulesByList(modules, cancellationToken).ConfigureAwait(false); |             var result = await service.GetAllModulesByList(modules, cancellationToken); | ||||||
|             return Ok(result); |             return Ok(result); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets the module by identifier. |         /// Gets the module by mongo identifier. | ||||||
|         /// </summary> |         /// </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] |         [HttpGet] | ||||||
|         [Route(Routes.Id)] |         [Route(Routes.Id)] | ||||||
|         [Consumes(MimeTypes.ApplicationJson)] |  | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |  | ||||||
|         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)] | ||||||
|         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |         [ProducesResponseType(StatusCodes.Status404NotFound)] | ||||||
|         //[Permission("ModuleManagement.Read")] |         [Permission("ModuleManagement.Read")] | ||||||
|         public async Task<IActionResult> GetModuleByIdAsync([FromRoute] string id, CancellationToken cancellationToken) |         public async Task<IActionResult> GetModuleByIdAsync([FromRoute] string _id, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.GetModuleById(id, cancellationToken).ConfigureAwait(false); |             var result = await service.GetModuleById(_id, cancellationToken); | ||||||
|  |  | ||||||
|             if (result == null) |             if (result == null) | ||||||
|             { |                 return NotFound("Module not found"); | ||||||
|                 return NotFound("Entity not found"); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             return Ok(result); |             return Ok(result); | ||||||
|         } |         } | ||||||
| @@ -104,70 +74,71 @@ namespace LSA.Core.Thalos.API.Controllers | |||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Creates a new module. |         /// Creates a new module. | ||||||
|         /// </summary> |         /// </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] |         [HttpPost] | ||||||
|         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status201Created)] |         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status201Created)] | ||||||
|         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |         [ProducesResponseType(StatusCodes.Status422UnprocessableEntity)] | ||||||
|         //[Permission("ModuleManagement.Write")] |         [Permission("ModuleManagement.Write")] | ||||||
|         public async Task<IActionResult> CreateModuleAsync([FromBody] ModuleRequest newModule, CancellationToken cancellationToken) |         public async Task<IActionResult> CreateModuleAsync([FromBody] ModuleRequest newModule, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.CreateModule(newModule, cancellationToken).ConfigureAwait(false); |             var result = await service.CreateModule(newModule, cancellationToken); | ||||||
|             return Created("CreatedWithIdAsync", result); |             return Created("CreatedWithIdAsync", result); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Updates a full module by identifier. |         /// Updates a full module by mongo identifier. | ||||||
|         /// </summary> |         /// </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] |         [HttpPut] | ||||||
|         [Route(Routes.Id)] |         [Route(Routes.Id)] | ||||||
|         [Consumes(MimeTypes.ApplicationJson)] |  | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |  | ||||||
|         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)] | ||||||
|         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||||
|         //[Permission("ModuleManagement.Write")] |         [ProducesResponseType(StatusCodes.Status422UnprocessableEntity)] | ||||||
|         public async Task<IActionResult> UpdateModuleAsync([FromRoute] string id, ModuleAdapter entity, CancellationToken cancellationToken) |         [Permission("ModuleManagement.Write")] | ||||||
|  |         public async Task<IActionResult> UpdateModuleAsync([FromRoute] string _id, [FromBody] ModuleAdapter entity, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             if (id != entity.Id?.ToString()) |             if (_id != entity._Id) | ||||||
|             { |  | ||||||
|                 return BadRequest("Module ID mismatch"); |                 return BadRequest("Module ID mismatch"); | ||||||
|             } |  | ||||||
|  |  | ||||||
|             var result = await service.UpdateModule(entity, cancellationToken).ConfigureAwait(false); |  | ||||||
|  |  | ||||||
|  |             var result = await service.UpdateModule(entity, cancellationToken); | ||||||
|             return Ok(result); |             return Ok(result); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Changes the status of the module. |         /// Changes the status of the module. | ||||||
|         /// </summary> |         /// </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] |         [HttpPatch] | ||||||
|         [Route(Routes.ChangeStatus)] |         [Route(Routes.ChangeStatus)] | ||||||
|         [Consumes(MimeTypes.ApplicationJson)] |  | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |  | ||||||
|         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)] | ||||||
|         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |         [Permission("ModuleManagement.Write")] | ||||||
|         //[Permission("ModuleManagement.Write")] |         public async Task<IActionResult> ChangeModuleStatus([FromRoute] string _id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) | ||||||
|         public async Task<IActionResult> ChangeModuleStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) |  | ||||||
|         { |         { | ||||||
|             var result = await service.ChangeModuleStatus(id, newStatus, cancellationToken).ConfigureAwait(false); |             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); |             return Ok(result); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -5,15 +5,12 @@ | |||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
|  |  | ||||||
| using Asp.Versioning; | using Asp.Versioning; | ||||||
| using Core.Blueprint.Mongo; | using Core.Thalos.BuildingBlocks; | ||||||
| using Core.Thalos.Adapters; |  | ||||||
| using Core.Thalos.Adapters.Attributes; |  | ||||||
| using Core.Thalos.Adapters.Common.Constants; |  | ||||||
| using Core.Thalos.Provider.Contracts; | using Core.Thalos.Provider.Contracts; | ||||||
| using Microsoft.AspNetCore.Authorization; | using Microsoft.AspNetCore.Authorization; | ||||||
| using Microsoft.AspNetCore.Mvc; | using Microsoft.AspNetCore.Mvc; | ||||||
| using Microsoft.Graph; |  | ||||||
| using PermissionRequest = Core.Thalos.Domain.Contexts.Onboarding.Request.PermissionRequest; | using PermissionRequest = Core.Thalos.Domain.Contexts.Onboarding.Request.PermissionRequest; | ||||||
|  | using StatusEnum = Core.Blueprint.Mongo.StatusEnum; | ||||||
|  |  | ||||||
| namespace LSA.Core.Thalos.API.Controllers | namespace LSA.Core.Thalos.API.Controllers | ||||||
| { | { | ||||||
| @@ -25,21 +22,21 @@ namespace LSA.Core.Thalos.API.Controllers | |||||||
|     [Produces(MimeTypes.ApplicationJson)] |     [Produces(MimeTypes.ApplicationJson)] | ||||||
|     [Consumes(MimeTypes.ApplicationJson)] |     [Consumes(MimeTypes.ApplicationJson)] | ||||||
|     [ApiController] |     [ApiController] | ||||||
|  |     [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|     public class PermissionController(IPermissionProvider service) : ControllerBase |     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.DefaultScheme)] |         [Permission("PermissionManagement.Read, RoleManagement.Read")] | ||||||
|         //[Permission("PermissionManagement.Read, RoleManagement.Read")] |  | ||||||
|         public async Task<IActionResult> GetAllPermissionsAsync(CancellationToken cancellationToken) |         public async Task<IActionResult> GetAllPermissionsAsync(CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.GetAllPermissions(cancellationToken).ConfigureAwait(false); |             var result = await service.GetAllPermissions(cancellationToken).ConfigureAwait(false); | ||||||
| @@ -50,17 +47,17 @@ namespace LSA.Core.Thalos.API.Controllers | |||||||
|         /// 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.DefaultScheme)] |         [Permission("PermissionManagement.Read")] | ||||||
|         //[Permission("PermissionManagement.Read")] |  | ||||||
|         public async Task<IActionResult> GetAllPermissionsByList([FromBody] string[] permissions, CancellationToken cancellationToken) |         public async Task<IActionResult> GetAllPermissionsByList([FromBody] string[] permissions, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             if (permissions == null || !permissions.Any()) |             if (permissions == null || !permissions.Any()) | ||||||
| @@ -73,27 +70,27 @@ namespace LSA.Core.Thalos.API.Controllers | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <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.DefaultScheme)] |         [Permission("PermissionManagement.Read")] | ||||||
|         //[Permission("PermissionManagement.Read")] |         public async Task<IActionResult> GetPermissionByIdAsync([FromRoute] string _id, CancellationToken cancellationToken) | ||||||
|         public async Task<IActionResult> GetPermissionByIdAsync([FromRoute] string id, CancellationToken cancellationToken) |  | ||||||
|         { |         { | ||||||
|             var result = await service.GetPermissionById(id, cancellationToken).ConfigureAwait(false); |             var result = await service.GetPermissionById(_id, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|             if (result == null) |             if (result == null) | ||||||
|             { |             { | ||||||
|                 return NotFound("Entity not found"); |                 return NotFound("Permission not found"); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             return Ok(result); |             return Ok(result); | ||||||
| @@ -103,14 +100,14 @@ namespace LSA.Core.Thalos.API.Controllers | |||||||
|         /// 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.DefaultScheme)] |         [Permission("PermissionManagement.Write")] | ||||||
|         //[Permission("PermissionManagement.Write")] |  | ||||||
|         public async Task<IActionResult> CreatePermissionAsync([FromBody] PermissionRequest newPermission, CancellationToken cancellationToken) |         public async Task<IActionResult> CreatePermissionAsync([FromBody] PermissionRequest newPermission, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.CreatePermission(newPermission, cancellationToken).ConfigureAwait(false); |             var result = await service.CreatePermission(newPermission, cancellationToken).ConfigureAwait(false); | ||||||
| @@ -118,25 +115,25 @@ namespace LSA.Core.Thalos.API.Controllers | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <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.DefaultScheme)] |         [Permission("PermissionManagement.Write")] | ||||||
|         //[Permission("PermissionManagement.Write")] |         public async Task<IActionResult> UpdatePermissionAsync([FromRoute] string _id, [FromBody] PermissionAdapter entity, CancellationToken cancellationToken) | ||||||
|         public async Task<IActionResult> UpdatePermissionAsync([FromRoute] string id, PermissionAdapter entity, CancellationToken cancellationToken) |  | ||||||
|         { |         { | ||||||
|             if (id != entity.Id?.ToString()) |             if (_id != entity._Id) | ||||||
|             { |             { | ||||||
|                 return BadRequest("Permission ID mismatch"); |                 return BadRequest("Permission ID mismatch"); | ||||||
|             } |             } | ||||||
| @@ -149,23 +146,48 @@ namespace LSA.Core.Thalos.API.Controllers | |||||||
|         /// <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.DefaultScheme)] |         [Permission("PermissionManagement.Write")] | ||||||
|         //[Permission("PermissionManagement.Write")] |         public async Task<IActionResult> ChangePermissionStatus([FromRoute] string _id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) | ||||||
|         public async Task<IActionResult> ChangePermissionStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) |  | ||||||
|         { |         { | ||||||
|             var result = await service.ChangePermissionStatus(id, newStatus, cancellationToken).ConfigureAwait(false); |             var result = await service.ChangePermissionStatus(_id, newStatus, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |             if (result == null) | ||||||
|  |                 return NotFound("Permission not found"); | ||||||
|  |  | ||||||
|  |             return Ok(result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <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) | ||||||
|  |         { | ||||||
|  |             var result = await service.DeletePermission(_id, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |             if (result is null) | ||||||
|  |                 return NotFound("Permission not found."); | ||||||
|  |  | ||||||
|             return Ok(result); |             return Ok(result); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -3,11 +3,9 @@ | |||||||
| //     AgileWebs | //     AgileWebs | ||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
|  |  | ||||||
| using Asp.Versioning; | using Asp.Versioning; | ||||||
| using Core.Thalos.Adapters; | using Core.Thalos.BuildingBlocks; | ||||||
| using Core.Thalos.Adapters.Attributes; |  | ||||||
| using Core.Thalos.Adapters.Common.Constants; |  | ||||||
| using Core.Thalos.Adapters.Common.Enums; |  | ||||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
| using Core.Thalos.Provider.Contracts; | using Core.Thalos.Provider.Contracts; | ||||||
| using Microsoft.AspNetCore.Authorization; | using Microsoft.AspNetCore.Authorization; | ||||||
| @@ -24,19 +22,19 @@ namespace LSA.Core.Thalos.API.Controllers | |||||||
|     [Produces(MimeTypes.ApplicationJson)] |     [Produces(MimeTypes.ApplicationJson)] | ||||||
|     [Consumes(MimeTypes.ApplicationJson)] |     [Consumes(MimeTypes.ApplicationJson)] | ||||||
|     [ApiController] |     [ApiController] | ||||||
|  |     [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|     public class RoleController(IRoleProvider service) : ControllerBase |     public class RoleController(IRoleProvider service) : ControllerBase | ||||||
|     { |     { | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets all the roles. |         /// Gets all roles. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <returns>The rol found entities.</returns> |         /// <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="200">The roles 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] | ||||||
|         [ProducesResponseType(typeof(IEnumerable<RoleAdapter>), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(IEnumerable<RoleAdapter>), StatusCodes.Status200OK)] | ||||||
|         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |         [Permission("RoleManagement.Read")] | ||||||
|         //[Permission("RoleManagement.Read")] |  | ||||||
|         public async Task<IActionResult> GetAllRolesAsync(CancellationToken cancellationToken) |         public async Task<IActionResult> GetAllRolesAsync(CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.GetAllRoles(cancellationToken).ConfigureAwait(false); |             var result = await service.GetAllRoles(cancellationToken).ConfigureAwait(false); | ||||||
| @@ -44,25 +42,25 @@ namespace LSA.Core.Thalos.API.Controllers | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets the role by identifier. |         /// Gets the role by mongo identifier. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="id">The role identifier.</param> |         /// <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> |         /// <returns>The <see cref="RoleAdapter"/> found entity.</returns> | ||||||
|         /// <response code="200">The role found.</response> |         /// <response code="200">The role found.</response> | ||||||
|         /// <response code="404">The role not found error.</response> |         /// <response code="404">The role 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)] | ||||||
|         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] | ||||||
|         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |         [Permission("RoleManagement.Read")] | ||||||
|         //[Permission("RoleManagement.Read")] |         public async Task<IActionResult> GetRoleByIdAsync([FromRoute] string _id, CancellationToken cancellationToken) | ||||||
|         public async Task<IActionResult> GetRoleByIdAsync([FromRoute] string id, CancellationToken cancellationToken) |  | ||||||
|         { |         { | ||||||
|             var result = await service.GetRoleById(id, cancellationToken).ConfigureAwait(false); |             var result = await service.GetRoleById(_id, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|             if (result == null) |             if (result == null) | ||||||
|             { |             { | ||||||
|                 return NotFound("Entity not found"); |                 return NotFound("Role not found"); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             return Ok(result); |             return Ok(result); | ||||||
| @@ -72,14 +70,14 @@ namespace LSA.Core.Thalos.API.Controllers | |||||||
|         /// Creates a new role. |         /// Creates a new role. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="newRole">The role to be added.</param> |         /// <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> |         /// <returns>The <see cref="RoleAdapter"/> created entity.</returns> | ||||||
|         /// <response code="201">The role created.</response> |         /// <response code="201">The role created.</response> | ||||||
|         /// <response code="422">The role could not be created.</response> |         /// <response code="422">The role could not be created.</response> | ||||||
|         /// <response code="500">The service internal error.</response> |         /// <response code="500">The service internal error.</response> | ||||||
|         [HttpPost] |         [HttpPost] | ||||||
|         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status201Created)] |         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status201Created)] | ||||||
|         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |         [Permission("RoleManagement.Write")] | ||||||
|         //[Permission("RoleManagement.Write")] |  | ||||||
|         public async Task<IActionResult> CreateRoleAsync([FromBody] RoleRequest newRole, CancellationToken cancellationToken) |         public async Task<IActionResult> CreateRoleAsync([FromBody] RoleRequest newRole, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.CreateRole(newRole, cancellationToken).ConfigureAwait(false); |             var result = await service.CreateRole(newRole, cancellationToken).ConfigureAwait(false); | ||||||
| @@ -87,67 +85,66 @@ namespace LSA.Core.Thalos.API.Controllers | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Updates a full role by identifier. |         /// Updates a full role by mongo identifier. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|  |         /// <param name="_id">The role mongo identifier.</param> | ||||||
|         /// <param name="entity">The role to update.</param> |         /// <param name="entity">The role to update.</param> | ||||||
|         /// <param name="id">The role identifier.</param> |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// <returns>The <see cref="RoleAdapter"/> updated entity.</returns> |         /// <returns>The <see cref="RoleAdapter"/> updated entity.</returns> | ||||||
|         /// <response code="200">The role updated.</response> |         /// <response code="200">The role updated.</response> | ||||||
|         /// <response code="404">The role not found.</response> |         /// <response code="400">Bad request if role ID mismatches.</response> | ||||||
|         /// <response code="422">The role could not be updated.</response> |         /// <response code="422">The role could not be updated.</response> | ||||||
|         /// <response code="500">The service internal error.</response> |         /// <response code="500">The service internal error.</response> | ||||||
|         [HttpPut] |         [HttpPut] | ||||||
|         [Route(Routes.Id)] |         [Route(Routes.Id)] | ||||||
|         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] | ||||||
|         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |         [Permission("RoleManagement.Write")] | ||||||
|         //[Permission("RoleManagement.Write")] |         public async Task<IActionResult> UpdateRoleAsync([FromRoute] string _id, [FromBody] RoleAdapter entity, CancellationToken cancellationToken) | ||||||
|         public async Task<IActionResult> UpdateRoleAsync([FromRoute] string id, [FromBody] RoleAdapter entity, CancellationToken cancellationToken) |  | ||||||
|         { |         { | ||||||
|             if (id != entity.Id?.ToString()) |             if (_id != entity._Id) | ||||||
|             { |             { | ||||||
|                 return BadRequest("Role ID mismatch"); |                 return BadRequest("Role ID mismatch"); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             var result = await service.UpdateRole(entity, cancellationToken).ConfigureAwait(false); |             var result = await service.UpdateRole(entity, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|             return Ok(result); |             return Ok(result); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Changes the status of the role. |         /// Changes the status of the role. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="id">The role identifier.</param> |         /// <param name="_id">The role mongo identifier.</param> | ||||||
|         /// <param name="newStatus">The new status of the role.</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> |         /// <returns>The <see cref="RoleAdapter"/> updated entity.</returns> | ||||||
|         /// <response code="200">The role updates.</response> |         /// <response code="200">The role status updated.</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> |         /// <response code="500">The service internal error.</response> | ||||||
|         [HttpPatch] |         [HttpPatch] | ||||||
|         [Route(Routes.ChangeStatus)] |         [Route(Routes.ChangeStatus)] | ||||||
|         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] | ||||||
|         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |         [Permission("RoleManagement.Write")] | ||||||
|         //[Permission("RoleManagement.Write")] |         public async Task<IActionResult> ChangeRoleStatus([FromRoute] string _id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) | ||||||
|         public async Task<IActionResult> ChangeRoleStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) |  | ||||||
|         { |         { | ||||||
|             var result = await service.ChangeRoleStatus(id, newStatus, cancellationToken).ConfigureAwait(false); |             var result = await service.ChangeRoleStatus(_id, newStatus, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |             if (result == null) | ||||||
|  |                 return NotFound("Role not found"); | ||||||
|  |  | ||||||
|             return Ok(result); |             return Ok(result); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Adds an application to the role's list of applications. |         /// Adds an application to the role's list of applications. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="roleId">The identifier of the role to which the application will be added.</param> |         /// <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="application">The application enum value to add.</param> | ||||||
|         /// <returns>A <see cref="Task{RoleAdapter}"/> representing the asynchronous operation, with the updated role object.</returns> |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// <response code="200">The role updates.</response> |         /// <returns>The updated <see cref="RoleAdapter"/> object.</returns> | ||||||
|         /// <response code="404">The role not found.</response> |         /// <response code="200">The application was added to the role.</response> | ||||||
|         /// <response code="422">The role could not be deleted.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |         /// <response code="500">The service internal error.</response> | ||||||
|         [HttpPost(Routes.AddApplication)] |         [HttpPost(Routes.AddApplication)] | ||||||
|         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] | ||||||
|         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |         [Permission("RoleManagement.Write")] | ||||||
|         //[Permission("RoleManagement.Write")] |  | ||||||
|         public async Task<IActionResult> AddApplicationToRoleAsync([FromRoute] string roleId, [FromRoute] ApplicationsEnum application, CancellationToken cancellationToken) |         public async Task<IActionResult> AddApplicationToRoleAsync([FromRoute] string roleId, [FromRoute] ApplicationsEnum application, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.AddApplicationToRole(roleId, application, cancellationToken).ConfigureAwait(false); |             var result = await service.AddApplicationToRole(roleId, application, cancellationToken).ConfigureAwait(false); | ||||||
| @@ -157,21 +154,42 @@ namespace LSA.Core.Thalos.API.Controllers | |||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Removes an application from the role's list of applications. |         /// Removes an application from the role's list of applications. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="roleId">The identifier of the role from which the application will be removed.</param> |         /// <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="application">The application enum value to remove.</param> | ||||||
|         /// <returns>A <see cref="Task{RoleAdapter}"/> representing the asynchronous operation, with the updated role object.</returns> |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// <response code="200">The role updates.</response> |         /// <returns>The updated <see cref="RoleAdapter"/> object.</returns> | ||||||
|         /// <response code="404">The role not found.</response> |         /// <response code="200">The application was removed from the role.</response> | ||||||
|         /// <response code="422">The role could not be deleted.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |         /// <response code="500">The service internal error.</response> | ||||||
|         [HttpDelete(Routes.RemoveApplication)] |         [HttpDelete(Routes.RemoveApplication)] | ||||||
|         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] | ||||||
|         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |         [Permission("RoleManagement.Write")] | ||||||
|         //[Permission("RoleManagement.Write")] |  | ||||||
|         public async Task<IActionResult> RemoveApplicationFromRoleAsync([FromRoute] string roleId, [FromRoute] ApplicationsEnum application, CancellationToken cancellationToken) |         public async Task<IActionResult> RemoveApplicationFromRoleAsync([FromRoute] string roleId, [FromRoute] ApplicationsEnum application, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.RemoveApplicationFromRole(roleId, application, cancellationToken).ConfigureAwait(false); |             var result = await service.RemoveApplicationFromRole(roleId, application, cancellationToken).ConfigureAwait(false); | ||||||
|             return Ok(result); |             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); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -3,15 +3,13 @@ | |||||||
| //     AgileWebs | //     AgileWebs | ||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
|  |  | ||||||
| using Asp.Versioning; | using Asp.Versioning; | ||||||
| using Core.Blueprint.Mongo; | using Core.Thalos.BuildingBlocks; | ||||||
| using Core.Thalos.Adapters; |  | ||||||
| using Core.Thalos.Adapters.Attributes; |  | ||||||
| using Core.Thalos.Adapters.Common.Constants; |  | ||||||
| using Core.Thalos.Provider.Contracts; | using Core.Thalos.Provider.Contracts; | ||||||
| using Microsoft.AspNetCore.Authorization; | using Microsoft.AspNetCore.Authorization; | ||||||
| using Microsoft.AspNetCore.Mvc; | using Microsoft.AspNetCore.Mvc; | ||||||
| using Microsoft.Graph; | using StatusEnum = Core.Blueprint.Mongo.StatusEnum; | ||||||
| using UserRequest = Core.Thalos.Domain.Contexts.Onboarding.Request.UserRequest; | using UserRequest = Core.Thalos.Domain.Contexts.Onboarding.Request.UserRequest; | ||||||
|  |  | ||||||
| namespace LSA.Core.Thalos.API.Controllers | namespace LSA.Core.Thalos.API.Controllers | ||||||
| @@ -27,16 +25,14 @@ namespace LSA.Core.Thalos.API.Controllers | |||||||
|     public class UserController(IUserProvider service) : ControllerBase |     public class UserController(IUserProvider service) : ControllerBase | ||||||
|     { |     { | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets all the users. |         /// Gets all users. | ||||||
|         /// </summary>   |         /// </summary> | ||||||
|  |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// <returns>The <see cref="IEnumerable{UserAdapter}"/> found entity.</returns> |         /// <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] |         [HttpGet] | ||||||
|         [ProducesResponseType(typeof(IEnumerable<UserAdapter>), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(IEnumerable<UserAdapter>), StatusCodes.Status200OK)] | ||||||
|         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|         //[Permission("UserManagement.Read")] |         [Permission("UserManagement.Read")] | ||||||
|         public async Task<IActionResult> GetAllUsers(CancellationToken cancellationToken) |         public async Task<IActionResult> GetAllUsers(CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.GetAllUsers(cancellationToken).ConfigureAwait(false); |             var result = await service.GetAllUsers(cancellationToken).ConfigureAwait(false); | ||||||
| @@ -44,62 +40,44 @@ namespace LSA.Core.Thalos.API.Controllers | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets the user by identifier. |         /// Gets the user by mongo identifier. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="id">The user identifier.</param> |         /// <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> |         /// <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] |         [HttpGet] | ||||||
|         [Route(Routes.Id)] |         [Route(Routes.Id)] | ||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||||
|         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|         //[Permission("UserManagement.Read")] |         [Permission("UserManagement.Read")] | ||||||
|         public async Task<IActionResult> GetUserById([FromRoute] string id, CancellationToken cancellationToken) |         public async Task<IActionResult> GetUserById([FromRoute] string _id, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.GetUserById(id, cancellationToken).ConfigureAwait(false); |             var result = await service.GetUserById(_id, cancellationToken).ConfigureAwait(false); | ||||||
|  |             return result == null ? NotFound("User not found") : Ok(result); | ||||||
|             if (result == null) |  | ||||||
|             { |  | ||||||
|                 return NotFound("Entity not found"); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             return Ok(result); |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets the user by email. |         /// Gets the user by email. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="email">The user's email.</param> |         /// <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> |         /// <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] |         [HttpGet] | ||||||
|         [Route(Routes.Email)] |         [Route(Routes.Email)] | ||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||||
|         //[Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.AzureScheme}")] |         [Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.GoogleScheme}")] | ||||||
|         public async Task<IActionResult> GetUserByEmail([FromRoute] string email, CancellationToken cancellationToken) |         public async Task<IActionResult> GetUserByEmail([FromRoute] string email, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.GetUserByEmail(email, cancellationToken).ConfigureAwait(false); |             var result = await service.GetUserByEmail(email, cancellationToken).ConfigureAwait(false); | ||||||
|  |             return result == null ? NotFound("User not found") : Ok(result); | ||||||
|             if (result == null) |  | ||||||
|             { |  | ||||||
|                 return NotFound("User not found"); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             return Ok(result); |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Validates if a user exists on the database. |         /// Validates if a user exists on the database. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="email">The user's email.</param> |         /// <param name="email">The user's email.</param> | ||||||
|         /// <returns>The <see cref="UserExistenceAdapter"/> found entity.</returns> |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// <response code="200">The user found.</response> |         /// <returns>The <see cref="UserExistenceAdapter"/> indicating existence.</returns> | ||||||
|         /// <response code="404">The user not found error.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpGet] |         [HttpGet] | ||||||
|         [Route("{email}/ValidateExistence")] |         [Route("{email}/ValidateExistence")] | ||||||
|         [ProducesResponseType(typeof(UserExistenceAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(UserExistenceAdapter), StatusCodes.Status200OK)] | ||||||
| @@ -107,28 +85,19 @@ namespace LSA.Core.Thalos.API.Controllers | |||||||
|         public async Task<IActionResult> ValidateUserExistence([FromRoute] string email, CancellationToken cancellationToken) |         public async Task<IActionResult> ValidateUserExistence([FromRoute] string email, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.ValidateUserExistence(email, cancellationToken).ConfigureAwait(false); |             var result = await service.ValidateUserExistence(email, cancellationToken).ConfigureAwait(false); | ||||||
|  |             return result == null ? NotFound("User not found") : Ok(result); | ||||||
|             if (result == null) |  | ||||||
|             { |  | ||||||
|                 return NotFound("User not found"); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             return Ok(result); |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Creates a new user. |         /// Creates a new user. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="newUser">The user to be added.</param> |         /// <param name="newUser">The user to be added.</param> | ||||||
|         /// <param name="sendInvitation">Sends an invitation in case of third party access.</param> |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// <returns>The <see cref="UserAdapter"/> created entity.</returns> |         /// <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)] |         [HttpPost(Routes.Register)] | ||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status201Created)] |         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status201Created)] | ||||||
|         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|         //[Permission("UserManagement.Write")] |         [Permission("UserManagement.Write")] | ||||||
|         public async Task<IActionResult> CreateUserAsync([FromBody] UserRequest newUser, CancellationToken cancellationToken) |         public async Task<IActionResult> CreateUserAsync([FromBody] UserRequest newUser, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.CreateUser(newUser, cancellationToken).ConfigureAwait(false); |             var result = await service.CreateUser(newUser, cancellationToken).ConfigureAwait(false); | ||||||
| @@ -136,171 +105,75 @@ namespace LSA.Core.Thalos.API.Controllers | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Updates a full user by identifier. |         /// Updates a full user by mongo identifier. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|  |         /// <param name="_id">The user Mongo identifier.</param> | ||||||
|         /// <param name="entity">The user to update.</param> |         /// <param name="entity">The user to update.</param> | ||||||
|         /// <param name="id">The user identifier.</param> |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// <returns>The <see cref="UserAdapter"/> updated entity.</returns> |         /// <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] |         [HttpPut] | ||||||
|         [Route(Routes.Id)] |         [Route(Routes.Id)] | ||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||||
|         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|         //[Permission("UserManagement.Write")] |         [Permission("UserManagement.Write")] | ||||||
|         public async Task<IActionResult> UpdateUserAsync([FromRoute] string id, [FromBody] UserAdapter entity, CancellationToken cancellationToken) |         public async Task<IActionResult> UpdateUserAsync([FromRoute] string _id, [FromBody] UserAdapter entity, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             if (id != entity.Id?.ToString()) |             if (_id != entity._Id) | ||||||
|             { |  | ||||||
|                 return BadRequest("User ID mismatch"); |                 return BadRequest("User ID mismatch"); | ||||||
|             } |  | ||||||
|  |  | ||||||
|             var result = await service.UpdateUser(entity, cancellationToken).ConfigureAwait(false); |             var result = await service.UpdateUser(entity, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|             return Ok(result); |             return Ok(result); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Logs in the user. |         /// Logs in the user. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="email">The User's email.</param> |         /// <param name="email">The user's email.</param> | ||||||
|         /// <returns>A <see cref="UserAdapter"/> representing |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// <returns>The <see cref="UserAdapter"/> found entity.</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)] |         [HttpPatch(Routes.LogIn)] | ||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||||
|         //[Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.AzureScheme}")] |         [Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.GoogleScheme}")] | ||||||
|         public async Task<IActionResult> LoginUserAsync([FromRoute] string email, CancellationToken cancellationToken) |         public async Task<IActionResult> LoginUserAsync([FromRoute] string email, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.LogInUser(email, cancellationToken).ConfigureAwait(false); |             var result = await service.LogInUser(email, cancellationToken).ConfigureAwait(false); | ||||||
|  |             return result == null ? NotFound($"The user with email: '{email}' was not found") : Ok(result); | ||||||
|             if (result is null) |  | ||||||
|                 return new NotFoundObjectResult($"The user with email: '{email}' was not found"); |  | ||||||
|  |  | ||||||
|             return Ok(result); |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Logs out the user. |         /// Logs out the user. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="email">The User's email.</param> |         /// <param name="email">The user's email.</param> | ||||||
|         /// <returns>A <see cref="UserAdapter"/> representing |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// <returns>The <see cref="UserAdapter"/> updated entity.</returns> | ||||||
|         /// <response code="200">The User updated.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpPatch(Routes.LogOut)] |         [HttpPatch(Routes.LogOut)] | ||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||||
|         //[Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.AzureScheme}")] |         [Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.GoogleScheme}")] | ||||||
|         public async Task<IActionResult> LogOutUserSessionAsync([FromRoute] string email, CancellationToken cancellationToken) |         public async Task<IActionResult> LogOutUserSessionAsync([FromRoute] string email, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.LogOutUserSession(email, cancellationToken).ConfigureAwait(false); |             var result = await service.LogOutUserSession(email, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|             return Ok(result); |             return Ok(result); | ||||||
|  |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Changes the status of the user. |         /// Changes the status of the user. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="id">The user identifier.</param> |         /// <param name="_id">The user Mongo identifier.</param> | ||||||
|         /// <param name="newStatus">The new status of the user.</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> |         /// <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] |         [HttpPatch] | ||||||
|         [Route(Routes.ChangeStatus)] |         [Route(Routes.ChangeStatus)] | ||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||||
|         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|         //[Permission("UserManagement.Write")] |         [Permission("UserManagement.Write")] | ||||||
|         public async Task<IActionResult> ChangeUserStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) |         public async Task<IActionResult> ChangeUserStatus([FromRoute] string _id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.ChangeUserStatus(id, newStatus, cancellationToken).ConfigureAwait(false); |             var result = await service.ChangeUserStatus(_id, newStatus, cancellationToken).ConfigureAwait(false); | ||||||
|             return Ok(result); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |             if (result == null) | ||||||
|         /// Adds a company to the user's list of companies. |                 return NotFound("User not found"); | ||||||
|         /// </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.DefaultScheme)] |  | ||||||
|         //[Permission("UserManagement.Write")] |  | ||||||
|         public async Task<IActionResult> AddCompanyToUserAsync([FromRoute] string userId, [FromRoute] string companyId, CancellationToken cancellationToken) |  | ||||||
|         { |  | ||||||
|             var result = await service.AddCompanyToUser(userId, companyId, cancellationToken).ConfigureAwait(false); |  | ||||||
|             return Ok(result); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <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.DefaultScheme)] |  | ||||||
|         //[Permission("UserManagement.Write")] |  | ||||||
|         public async Task<IActionResult> RemoveCompanyFromUserAsync([FromRoute] string userId, [FromRoute] string companyId, CancellationToken cancellationToken) |  | ||||||
|         { |  | ||||||
|             var result = await service.RemoveCompanyFromUser(userId, companyId, cancellationToken).ConfigureAwait(false); ; |  | ||||||
|             return Ok(result); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <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.DefaultScheme)] |  | ||||||
|         //[Permission("UserManagement.Write")] |  | ||||||
|         public async Task<IActionResult> AddProjectToUserAsync([FromRoute] string userId, [FromRoute] string projectId, CancellationToken cancellationToken) |  | ||||||
|         { |  | ||||||
|             var result = await service.AddProjectToUser(userId, projectId, cancellationToken).ConfigureAwait(false); |  | ||||||
|             return Ok(result); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <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.DefaultScheme)] |  | ||||||
|         //[Permission("UserManagement.Write")] |  | ||||||
|         public async Task<IActionResult> RemoveProjectFromUserAsync([FromRoute] string userId, [FromRoute] string projectId, CancellationToken cancellationToken) |  | ||||||
|         { |  | ||||||
|             var result = await service.RemoveProjectFromUser(userId, projectId, cancellationToken).ConfigureAwait(false); |  | ||||||
|             return Ok(result); |             return Ok(result); | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -308,21 +181,35 @@ namespace LSA.Core.Thalos.API.Controllers | |||||||
|         /// Gets a token for the user, including roles, permissions, and modules. |         /// Gets a token for the user, including roles, permissions, and modules. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="email">The user's email.</param> |         /// <param name="email">The user's email.</param> | ||||||
|         /// <returns>The token adapter with user details, role, permissions, and modules.</returns> |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// <response code="200">The token adapter with user details.</response> |         /// <returns>The <see cref="TokenAdapter"/> with user details.</returns> | ||||||
|         /// <response code="404">The user not found.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpGet] |         [HttpGet] | ||||||
|         [Route("{email}/GetTokenAdapter")] |         [Route("{email}/GetTokenAdapter")] | ||||||
|         [ProducesResponseType(typeof(TokenAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(TokenAdapter), StatusCodes.Status200OK)] | ||||||
|         //[Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.AzureScheme}")] |         [Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.GoogleScheme}")] | ||||||
|         public async Task<IActionResult> GetTokenAdapter([FromRoute] string email, CancellationToken cancellationToken) |         public async Task<IActionResult> GetTokenAdapter([FromRoute] string email, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var tokenAdapter = await service.GetToken(email, cancellationToken).ConfigureAwait(false); |             var tokenAdapter = await service.GetToken(email, cancellationToken).ConfigureAwait(false); | ||||||
|  |             return tokenAdapter == null ? NotFound($"User with email: {email} not found") : Ok(tokenAdapter); | ||||||
|  |         } | ||||||
|  |  | ||||||
|             if (tokenAdapter == null) return NotFound($"User with email: {email} not found"); |         /// <summary> | ||||||
|  |         /// Deletes a user by mongo identifier. | ||||||
|             return Ok(tokenAdapter); |         /// </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); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -15,7 +15,7 @@ | |||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|  |  | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <PackageReference Include="Blueprint.Logging" Version="0.0.2" /> |     <PackageReference Include="Core.Blueprint.Logging" Version="1.0.1" /> | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|  |  | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|   | |||||||
| @@ -1,71 +0,0 @@ | |||||||
| using Asp.Versioning.ApiExplorer; |  | ||||||
| using Microsoft.Extensions.Options; |  | ||||||
| using Microsoft.OpenApi.Any; |  | ||||||
| using Swashbuckle.AspNetCore.SwaggerGen; |  | ||||||
| using Swashbuckle.AspNetCore.SwaggerUI; |  | ||||||
|  |  | ||||||
| namespace Core.Thalos.DAL.API.Extensions |  | ||||||
| { |  | ||||||
|     public static class SwaggerExtensions |  | ||||||
|     { |  | ||||||
|         public static void AddSwagger(this IServiceCollection services) |  | ||||||
|         { |  | ||||||
|             services.AddEndpointsApiExplorer(); |  | ||||||
|             services.AddSwaggerGen(); |  | ||||||
|             services.AddTransient<IConfigureOptions<SwaggerGenOptions>, ConfigureSwaggerOptions>(); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         public static void ConfigureSwagger(this WebApplication app) |  | ||||||
|         { |  | ||||||
|             app.UseSwagger(); |  | ||||||
|             app.UseSwaggerUI(options => |  | ||||||
|             { |  | ||||||
|                 foreach (var version in app.DescribeApiVersions().Select(version => version.GroupName)) |  | ||||||
|                     options.SwaggerEndpoint($"/swagger/{version}/swagger.json", version); |  | ||||||
|  |  | ||||||
|                 options.DisplayRequestDuration(); |  | ||||||
|                 options.EnableTryItOutByDefault(); |  | ||||||
|                 options.DocExpansion(DocExpansion.None); |  | ||||||
|             }); |  | ||||||
|         } |  | ||||||
|         public static IServiceCollection AddVersioning(this IServiceCollection services) |  | ||||||
|         { |  | ||||||
|             services.AddApiVersioning(options => options.ReportApiVersions = true) |  | ||||||
|                    .AddApiExplorer(options => |  | ||||||
|                    { |  | ||||||
|                        options.GroupNameFormat = "'v'VVV"; |  | ||||||
|                        options.SubstituteApiVersionInUrl = true; |  | ||||||
|                    }); |  | ||||||
|  |  | ||||||
|             return services; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|     public class ConfigureSwaggerOptions : IConfigureOptions<SwaggerGenOptions> |  | ||||||
|     { |  | ||||||
|         private readonly IApiVersionDescriptionProvider _provider; |  | ||||||
|  |  | ||||||
|         public ConfigureSwaggerOptions(IApiVersionDescriptionProvider provider) |  | ||||||
|         { |  | ||||||
|             _provider = provider; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         public void Configure(SwaggerGenOptions options) |  | ||||||
|         { |  | ||||||
|             foreach (var description in _provider.ApiVersionDescriptions) |  | ||||||
|                 options.SwaggerDoc(description.GroupName, new() |  | ||||||
|                 { |  | ||||||
|                     Title = AppDomain.CurrentDomain.FriendlyName, |  | ||||||
|                     Version = description.ApiVersion.ToString() |  | ||||||
|                 }); |  | ||||||
|  |  | ||||||
|             //Map ALL Values Format TODO |  | ||||||
|             options.MapType<DateOnly>(() => new() |  | ||||||
|             { |  | ||||||
|                 Format = "date", |  | ||||||
|                 Example = new OpenApiString(DateOnly.MinValue.ToString()) |  | ||||||
|             }); |  | ||||||
|  |  | ||||||
|             options.CustomSchemaIds(type => type.ToString().Replace("+", ".")); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,8 +1,9 @@ | |||||||
| using Core.Blueprint.Caching.Configuration; |  | ||||||
| using Core.Blueprint.DAL.Mongo.Configuration; | using Core.Blueprint.DAL.Mongo.Configuration; | ||||||
|  | using Core.Blueprint.KeyVault.Configuration; | ||||||
| using Core.Blueprint.Logging.Configuration; | using Core.Blueprint.Logging.Configuration; | ||||||
| using Core.Thalos.Adapters.Extensions; | using Core.Blueprint.Redis.Configuration; | ||||||
| using Core.Thalos.DAL.API.Extensions; | using Core.Thalos.BuildingBlocks; | ||||||
|  | using Core.Thalos.BuildingBlocks.Configuration; | ||||||
| using Core.Thalos.Provider; | using Core.Thalos.Provider; | ||||||
| using Microsoft.AspNetCore.HttpLogging; | using Microsoft.AspNetCore.HttpLogging; | ||||||
| using System.Reflection; | using System.Reflection; | ||||||
| @@ -10,12 +11,19 @@ using System.Text.Json.Serialization; | |||||||
|  |  | ||||||
| var builder = WebApplication.CreateBuilder(args); | var builder = WebApplication.CreateBuilder(args); | ||||||
|  |  | ||||||
| builder.Services.AddEndpointsApiExplorer(); |  | ||||||
| builder.Services.AddSwaggerGen(); |  | ||||||
| builder.Configuration | builder.Configuration | ||||||
|     .AddUserSecrets(Assembly.GetExecutingAssembly()) |     .AddUserSecrets(Assembly.GetExecutingAssembly()) | ||||||
|     .AddEnvironmentVariables(); |     .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.AddResponseCompression(); | ||||||
| builder.Services.AddProblemDetails(); | builder.Services.AddProblemDetails(); | ||||||
| builder.Services.AddMemoryCache(); | builder.Services.AddMemoryCache(); | ||||||
| @@ -42,11 +50,6 @@ builder.Host.ConfigureServices((context, services) => | |||||||
|         options.SerializerOptions.Converters.Add(new JsonStringEnumConverter()); |         options.SerializerOptions.Converters.Add(new JsonStringEnumConverter()); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     services |  | ||||||
|         .AddEndpointsApiExplorer() |  | ||||||
|         .AddVersioning() |  | ||||||
|         .AddSwagger(); |  | ||||||
|  |  | ||||||
|     services.AddHealthChecks(); |     services.AddHealthChecks(); | ||||||
|     services.AddHttpLogging(options => options.LoggingFields = HttpLoggingFields.All); |     services.AddHttpLogging(options => options.LoggingFields = HttpLoggingFields.All); | ||||||
|  |  | ||||||
| @@ -63,20 +66,22 @@ builder.Host.ConfigureServices((context, services) => | |||||||
|  |  | ||||||
| var app = builder.Build(); | var app = builder.Build(); | ||||||
|  |  | ||||||
| app.UseSwagger(); | app.UseLogging(builder.Configuration); | ||||||
| app.UseSwaggerUI(); | app.UseSwaggerUI(builder.Configuration, authSettings); | ||||||
| app.UseAuthentication(); | app.ConfigureSwagger(builder.Configuration); | ||||||
| app.UseAuthorization(); |  | ||||||
| app.MapControllers(); | app.UseRouting(); | ||||||
| app.UseCors(); | app.UseCors(); | ||||||
| app.ConfigureSwagger(); |  | ||||||
| app.UseHttpsRedirection(); | app.UseHttpsRedirection(); | ||||||
| app.UseStaticFiles(); | app.UseStaticFiles(); | ||||||
| app.UseRouting(); |  | ||||||
| app.UseResponseCompression(); | app.UseResponseCompression(); | ||||||
| app.UseOutputCache(); | app.UseOutputCache(); | ||||||
| app.UseResponseCaching(); | app.UseResponseCaching(); | ||||||
| app.UseLogging(builder.Configuration); |  | ||||||
|  | app.UseAuthentication(); | ||||||
|  | app.UseAuthorization(); | ||||||
|  |  | ||||||
|  | app.MapControllers(); | ||||||
| app.MapHealthChecks("/health"); | app.MapHealthChecks("/health"); | ||||||
|  |  | ||||||
| app.Run(); | app.Run(); | ||||||
							
								
								
									
										35
									
								
								Core.Thalos.DAL.API/appsettings.Local.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								Core.Thalos.DAL.API/appsettings.Local.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,35 @@ | |||||||
|  | { | ||||||
|  |   "Logging": { | ||||||
|  |     "LogLevel": { | ||||||
|  |       "Default": "Information", | ||||||
|  |       "Microsoft.AspNetCore": "Warning" | ||||||
|  |     } | ||||||
|  |   }, | ||||||
|  |   "AllowedHosts": "*", | ||||||
|  |   "ConnectionStrings": { | ||||||
|  |     "MongoDB": "mongodb://admin_agile:Admin%40agileWebs@portainer.white-enciso.pro:27017/?authMechanism=SCRAM-SHA-256", | ||||||
|  |     "Redis": "100.123.31.103:6379" | ||||||
|  |   }, | ||||||
|  |   "MongoDb": { | ||||||
|  |     "DatabaseName": "Thalos", | ||||||
|  |     "LocalAudience": "" | ||||||
|  |   }, | ||||||
|  |   "DetailedErrors": true, | ||||||
|  |   "UseRedisCache": true, | ||||||
|  |   "CacheSettings": { | ||||||
|  |     "DefaultCacheDurationInMinutes": 3 | ||||||
|  |   }, | ||||||
|  |   "ServiceSettings": { | ||||||
|  |     "ApplicationName": "thalos", | ||||||
|  |     "LayerName": "dal" | ||||||
|  |   }, | ||||||
|  |   "Vault": { | ||||||
|  |     "Address": "http://100.123.31.103:8200", | ||||||
|  |     "Token": "hvs.e37LQvLuPhTd5ALS5QQ03Cwm", | ||||||
|  |     "SecretMount": "secret" | ||||||
|  |   }, | ||||||
|  |   "IdentityProviders": { | ||||||
|  |     "Google": true, | ||||||
|  |     "Azure":  true | ||||||
|  |   } | ||||||
|  | } | ||||||
| @@ -4,19 +4,5 @@ | |||||||
|       "Default": "Information", |       "Default": "Information", | ||||||
|       "Microsoft.AspNetCore": "Warning" |       "Microsoft.AspNetCore": "Warning" | ||||||
|     } |     } | ||||||
|   }, |  | ||||||
|   "AllowedHosts": "*", |  | ||||||
|   "ConnectionStrings": { |  | ||||||
|     "MongoDB": "mongodb://localhost:27017", |  | ||||||
|     "Redis": "localhost:6379" |  | ||||||
|   }, |  | ||||||
|   "MongoDb": { |  | ||||||
|     "DatabaseName": "Thalos", |  | ||||||
|     "LocalAudience": "" |  | ||||||
|   }, |  | ||||||
|   "DetailedErrors": true, |  | ||||||
|   "UseRedisCache": true, |  | ||||||
|   "CacheSettings": { |  | ||||||
|     "DefaultCacheDurationInMinutes": 3 |  | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,42 +0,0 @@ | |||||||
| // *********************************************************************** |  | ||||||
| // <copyright file="ModuleMapper.cs"> |  | ||||||
| //    AgileWebs |  | ||||||
| // </copyright> |  | ||||||
| // *********************************************************************** |  | ||||||
| using Core.Thalos.Adapters; |  | ||||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; |  | ||||||
| using Microsoft.AspNetCore.Http; |  | ||||||
| using MongoDB.Bson; |  | ||||||
| using System.Security.Claims; |  | ||||||
| namespace Core.Thalos.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"> |  | ||||||
| //    AgileWebs |  | ||||||
| // </copyright> |  | ||||||
| // *********************************************************************** |  | ||||||
| using Core.Thalos.Adapters; |  | ||||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; |  | ||||||
| using Microsoft.AspNetCore.Http; |  | ||||||
| using MongoDB.Bson; |  | ||||||
| using System.Security.Claims; |  | ||||||
| namespace Core.Thalos.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"> |  | ||||||
| //    AgileWebs |  | ||||||
| // </copyright> |  | ||||||
| // *********************************************************************** |  | ||||||
|  |  | ||||||
| using Core.Thalos.Adapters; |  | ||||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; |  | ||||||
| using Microsoft.AspNetCore.Http; |  | ||||||
| using MongoDB.Bson; |  | ||||||
| using System.Security.Claims; |  | ||||||
| namespace Core.Thalos.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"> |  | ||||||
| //    AgileWebs |  | ||||||
| // </copyright> |  | ||||||
| // *********************************************************************** |  | ||||||
| using Core.Thalos.Adapters; |  | ||||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; |  | ||||||
| using Microsoft.AspNetCore.Http; |  | ||||||
| using MongoDB.Bson; |  | ||||||
| using System.Security.Claims; |  | ||||||
|  |  | ||||||
| namespace Core.Thalos.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 |  | ||||||
|             }; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -4,7 +4,7 @@ | |||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
|  |  | ||||||
| using Core.Thalos.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; | ||||||
|   | |||||||
| @@ -4,7 +4,7 @@ | |||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
|  |  | ||||||
| using Core.Thalos.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; | ||||||
|   | |||||||
| @@ -4,7 +4,7 @@ | |||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
|  |  | ||||||
| using Core.Thalos.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; | ||||||
|   | |||||||
| @@ -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; } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -54,19 +54,5 @@ namespace Core.Thalos.Domain.Contexts.Onboarding.Request | |||||||
|         [BsonRepresentation(BsonType.ObjectId)] |         [BsonRepresentation(BsonType.ObjectId)] | ||||||
|         [JsonPropertyName("roleId")] |         [JsonPropertyName("roleId")] | ||||||
|         public string RoleId { get; set; } = null!; |         public string RoleId { get; set; } = null!; | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets or sets the array of companies associated with the user. |  | ||||||
|         /// </summary> |  | ||||||
|         [BsonElement("companies")] |  | ||||||
|         [JsonPropertyName("companies")] |  | ||||||
|         public string[] Companies { 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="Thalos.Building.Blocks" Version="0.0.5" /> |     <PackageReference Include="Core.Blueprint.KeyVault" Version="1.0.3" /> | ||||||
|  |     <PackageReference Include="Core.Thalos.BuildingBlocks" Version="1.1.2" /> | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|  |  | ||||||
| </Project> | </Project> | ||||||
|   | |||||||
| @@ -1,30 +0,0 @@ | |||||||
| using Core.Thalos.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.Thalos.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.Thalos.Infraestructure.Caching.Configs |  | ||||||
| { |  | ||||||
|     public class CacheSettings |  | ||||||
|     { |  | ||||||
|         public int DefaultCacheDurationInMinutes { get; set; } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,11 +0,0 @@ | |||||||
| namespace Core.Thalos.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.Thalos.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.Thalos.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.Thalos.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; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -3,62 +3,85 @@ | |||||||
| //     AgileWebs | //     AgileWebs | ||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| using Core.Blueprint.Mongo; |  | ||||||
| using Core.Thalos.Adapters; | using Core.Thalos.BuildingBlocks; | ||||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
|  |  | ||||||
| namespace Core.Thalos.Provider.Contracts | namespace Core.Thalos.Provider.Contracts | ||||||
| { | { | ||||||
|  |     /// <summary> | ||||||
|  |     /// Interface for Module-related service operations. | ||||||
|  |     /// </summary> | ||||||
|     public interface IModuleProvider |     public interface IModuleProvider | ||||||
|     { |     { | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Creates a new Module. |         /// Creates a new Module. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="entity">The Module to be created.</param> |         /// <param name="newModule">The Module to be created.</param> | ||||||
|         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{ModuleAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|         ValueTask<ModuleAdapter> CreateModule(ModuleRequest newModule, CancellationToken cancellationToken); |         ValueTask<ModuleAdapter> CreateModule(ModuleRequest newModule, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets an Module by identifier. |         /// Gets a Module by its identifier. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="id">The Module identifier.</param> |         /// <param name="_id">The Module Mongo identifier.</param> | ||||||
|         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{ModuleAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|         ValueTask<ModuleAdapter> GetModuleById(string _id, CancellationToken cancellationToken); |         ValueTask<ModuleAdapter> GetModuleById(string _id, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets all the roles. |         /// Gets all Modules. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <returns>A <see cref="{Task{IEnumerbale{ModuleAdapter}}}"/> representing |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{IEnumerable{ModuleAdapter}}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|         ValueTask<IEnumerable<ModuleAdapter>> GetAllModules(CancellationToken cancellationToken); |         ValueTask<IEnumerable<ModuleAdapter>> GetAllModules(CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets all the permissions by permissions identifier list. |         /// Gets all Modules by a list of identifiers. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="permissions">The list of permissions identifiers.</param> |         /// <param name="modules">The list of Module identifiers.</param> | ||||||
|         /// <returns>A <see cref="Task{IEnumerable{ModuleAdapter}}"/> representing |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{IEnumerable{ModuleAdapter}}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|         ValueTask<IEnumerable<ModuleAdapter>> GetAllModulesByList(string[] modules, CancellationToken cancellationToken); |         ValueTask<IEnumerable<ModuleAdapter>> GetAllModulesByList(string[] modules, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Changes the status of the permission. |         /// Changes the status of a Module. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="id">The permission identifier.</param> |         /// <param name="_id">The Module Mongo identifier.</param> | ||||||
|         /// <param name="newStatus">The new status of the permission.</param> |         /// <param name="newStatus">The new status of the Module.</param> | ||||||
|         /// <returns>The <see cref="ModuleAdapter"/> updated entity.</returns> |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing |         /// <returns> | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// A <see cref="ValueTask{ModuleAdapter}"/> representing the asynchronous execution of the service. | ||||||
|         ValueTask<ModuleAdapter> ChangeModuleStatus(string id, StatusEnum newStatus, CancellationToken cancellationToken); |         /// </returns> | ||||||
|  |         ValueTask<ModuleAdapter?> ChangeModuleStatus(string _id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Updates a Module by id. |         /// Updates a Module by its identifier. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="entity">The Module to be updated.</param> |         /// <param name="entity">The Module to be updated.</param> | ||||||
|         /// <param name="id">The Module identifier.</param> |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing |         /// <returns> | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// A <see cref="ValueTask{ModuleAdapter}"/> representing the asynchronous execution of the service. | ||||||
|         ValueTask<ModuleAdapter> UpdateModule(ModuleAdapter entity, CancellationToken cancellationToken); |         /// </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); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -3,62 +3,85 @@ | |||||||
| //     AgileWebs | //     AgileWebs | ||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| using Core.Blueprint.Mongo; |  | ||||||
| using Core.Thalos.Adapters; | using Core.Thalos.BuildingBlocks; | ||||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
|  |  | ||||||
| namespace Core.Thalos.Provider.Contracts | namespace Core.Thalos.Provider.Contracts | ||||||
| { | { | ||||||
|  |     /// <summary> | ||||||
|  |     /// Interface for Permission-related service operations. | ||||||
|  |     /// </summary> | ||||||
|     public interface IPermissionProvider |     public interface IPermissionProvider | ||||||
|     { |     { | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Creates a new Permission. |         /// Creates a new Permission. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="entity">The Permission to be created.</param> |         /// <param name="newPermission">The Permission to be created.</param> | ||||||
|         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{PermissionAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|         ValueTask<PermissionAdapter> CreatePermission(PermissionRequest newPermission, CancellationToken cancellationToken); |         ValueTask<PermissionAdapter> CreatePermission(PermissionRequest newPermission, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets an Permission by identifier. |         /// Gets a Permission by its identifier. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="id">The Permission identifier.</param> |         /// <param name="_id">The Permission Mongo identifier.</param> | ||||||
|         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{PermissionAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|         ValueTask<PermissionAdapter> GetPermissionById(string _id, CancellationToken cancellationToken); |         ValueTask<PermissionAdapter> GetPermissionById(string _id, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets all the roles. |         /// Gets all Permissions. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <returns>A <see cref="{Task{IEnumerbale{PermissionAdapter}}}"/> representing |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{IEnumerable{PermissionAdapter}}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|         ValueTask<IEnumerable<PermissionAdapter>> GetAllPermissions(CancellationToken cancellationToken); |         ValueTask<IEnumerable<PermissionAdapter>> GetAllPermissions(CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets all the permissions by permissions identifier list. |         /// Gets all Permissions by a list of identifiers. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="permissions">The list of permissions identifiers.</param> |         /// <param name="permissions">The list of Permission identifiers.</param> | ||||||
|         /// <returns>A <see cref="Task{IEnumerable{PermissionAdapter}}"/> representing |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{IEnumerable{PermissionAdapter}}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|         ValueTask<IEnumerable<PermissionAdapter>> GetAllPermissionsByList(string[] permissions, CancellationToken cancellationToken); |         ValueTask<IEnumerable<PermissionAdapter>> GetAllPermissionsByList(string[] permissions, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Changes the status of the permission. |         /// Changes the status of a 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> | ||||||
|         /// <returns>The <see cref="PermissionAdapter"/> updated entity.</returns> |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing |         /// <returns> | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// A <see cref="ValueTask{PermissionAdapter}"/> representing the asynchronous execution of the service. | ||||||
|         ValueTask<PermissionAdapter> ChangePermissionStatus(string id, StatusEnum newStatus, CancellationToken cancellationToken); |         /// </returns> | ||||||
|  |         ValueTask<PermissionAdapter?> ChangePermissionStatus(string _id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Updates a Permission by id. |         /// Updates a Permission. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="entity">The Permission to be updated.</param> |         /// <param name="entity">The Permission to be updated.</param> | ||||||
|         /// <param name="id">The Permission identifier.</param> |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing |         /// <returns> | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// A <see cref="ValueTask{PermissionAdapter}"/> representing the asynchronous execution of the service. | ||||||
|         ValueTask<PermissionAdapter> UpdatePermission(PermissionAdapter entity, CancellationToken cancellationToken); |         /// </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); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -3,70 +3,97 @@ | |||||||
| //     AgileWebs | //     AgileWebs | ||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| using Core.Thalos.Adapters; |  | ||||||
| using Core.Thalos.Adapters.Common.Enums; | using Core.Thalos.BuildingBlocks; | ||||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
|  |  | ||||||
| namespace Core.Thalos.Provider.Contracts | namespace Core.Thalos.Provider.Contracts | ||||||
| { | { | ||||||
|  |     /// <summary> | ||||||
|  |     /// Interface for Role-related service operations. | ||||||
|  |     /// </summary> | ||||||
|     public interface IRoleProvider |     public interface IRoleProvider | ||||||
|     { |     { | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Creates a new Role. |         /// Creates a new Role. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="entity">The Role to be created.</param> |         /// <param name="newRole">The Role to be created.</param> | ||||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{RoleAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|         ValueTask<RoleAdapter> CreateRole(RoleRequest newRole, CancellationToken cancellationToken); |         ValueTask<RoleAdapter> CreateRole(RoleRequest newRole, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets an Role by identifier. |         /// Gets a Role by its identifier. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="id">The Role identifier.</param> |         /// <param name="_id">The Role Mongo identifier.</param> | ||||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{RoleAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|         ValueTask<RoleAdapter> GetRoleById(string _id, CancellationToken cancellationToken); |         ValueTask<RoleAdapter> GetRoleById(string _id, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets all the roles. |         /// Gets all Roles. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <returns>A <see cref="{Task{IEnumerbale{RoleAdapter}}}"/> representing |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{IEnumerable{RoleAdapter}}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|         ValueTask<IEnumerable<RoleAdapter>> GetAllRoles(CancellationToken cancellationToken); |         ValueTask<IEnumerable<RoleAdapter>> GetAllRoles(CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Changes the status of the role. |         /// Changes the status of a Role. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="id">The role identifier.</param> |         /// <param name="_id">The Role Mongo identifier.</param> | ||||||
|         /// <param name="newStatus">The new status of the role.</param> |         /// <param name="newStatus">The new status of the Role.</param> | ||||||
|         /// <returns>The <see cref="RoleAdapter"/> updated entity.</returns> |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing |         /// <returns> | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// A <see cref="ValueTask{RoleAdapter}"/> representing the asynchronous execution of the service. | ||||||
|         ValueTask<RoleAdapter> ChangeRoleStatus(string id, Core.Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken); |         /// </returns> | ||||||
|  |         ValueTask<RoleAdapter?> ChangeRoleStatus(string _id, Core.Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Updates a Role by id. |         /// Updates a Role. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="entity">The Role to be updated.</param> |         /// <param name="entity">The Role to be updated.</param> | ||||||
|         /// <param name="id">The Role identifier.</param> |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing |         /// <returns> | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// A <see cref="ValueTask{RoleAdapter}"/> representing the asynchronous execution of the service. | ||||||
|         ValueTask<RoleAdapter> UpdateRole(RoleAdapter entity, CancellationToken cancellationToken); |         /// </returns> | ||||||
|  |         ValueTask<RoleAdapter?> UpdateRole(RoleAdapter entity, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Adds an application to the role's list of applications. |         /// Adds an application to the Role's list of applications. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="roleId">The identifier of the role to which the application will be added.</param> |         /// <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="application">The application enum value to add.</param> | ||||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing the asynchronous operation, with the updated role object.</returns> |         /// <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); |         ValueTask<RoleAdapter> AddApplicationToRole(string roleId, ApplicationsEnum application, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Removes an application from the role's list of applications. |         /// Removes an application from the Role's list of applications. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="roleId">The identifier of the role from which the application will be removed.</param> |         /// <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="application">The application enum value to remove.</param> | ||||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing the asynchronous operation, with the updated role object.</returns> |         /// <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); |         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); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -3,134 +3,125 @@ | |||||||
| //     AgileWebs | //     AgileWebs | ||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| using Core.Blueprint.Mongo; |  | ||||||
| using Core.Thalos.Adapters; | using Core.Thalos.BuildingBlocks; | ||||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
|  |  | ||||||
| namespace Core.Thalos.Provider.Contracts | namespace Core.Thalos.Provider.Contracts | ||||||
| { | { | ||||||
|  |     /// <summary> | ||||||
|  |     /// Interface for User-related service operations. | ||||||
|  |     /// </summary> | ||||||
|     public interface IUserProvider |     public interface IUserProvider | ||||||
|     { |     { | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Creates a new User. |         /// Creates a new User. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="entity">The User to be created.</param> |         /// <param name="newUser">The User to be created.</param> | ||||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{UserAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|         ValueTask<UserAdapter> CreateUser(UserRequest newUser, CancellationToken cancellationToken); |         ValueTask<UserAdapter> CreateUser(UserRequest newUser, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets an User by identifier. |         /// Gets a User by Mongo identifier. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="id">The User identifier.</param> |         /// <param name="_id">The User Mongo identifier.</param> | ||||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{UserAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|         ValueTask<UserAdapter> GetUserById(string _id, CancellationToken cancellationToken); |         ValueTask<UserAdapter> GetUserById(string _id, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets all the users. |         /// Gets all Users. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <returns>A <see cref="{Task{IEnumerable{UserAdapter}}}"/> representing |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{IEnumerable{UserAdapter}}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|         ValueTask<IEnumerable<UserAdapter>> GetAllUsers(CancellationToken cancellationToken); |         ValueTask<IEnumerable<UserAdapter>> GetAllUsers(CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets an User by email. |         /// Gets a 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> |  | ||||||
|         ValueTask<UserAdapter> GetUserByEmail(string? email, CancellationToken cancellationToken); |  | ||||||
|  |  | ||||||
|         /// <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> |  | ||||||
|         ValueTask<UserExistenceAdapter> ValidateUserExistence(string? email, CancellationToken cancellationToken); |  | ||||||
|  |  | ||||||
|         /// <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> |  | ||||||
|         ValueTask<UserAdapter> ChangeUserStatus(string id, StatusEnum newStatus, CancellationToken cancellationToken); |  | ||||||
|  |  | ||||||
|         /// <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> |  | ||||||
|         ValueTask<UserAdapter> UpdateUser(UserAdapter entity, CancellationToken cancellationToken); |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Logs in the user. |  | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="email">The User's email.</param> |         /// <param name="email">The User's email.</param> | ||||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// <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); |         ValueTask<UserAdapter?> LogInUser(string email, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Logs out the user's session. |         /// Logs out the User's session. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="email">The User's email.</param> |         /// <param name="email">The User's email.</param> | ||||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{UserAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|         ValueTask<UserAdapter?> LogOutUserSession(string email, CancellationToken cancellationToken); |         ValueTask<UserAdapter?> LogOutUserSession(string email, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Adds a company to the user's list of companies. |         /// Gets the TokenAdapter for a User. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="userId">The identifier of the user to whom the company will be added.</param> |         /// <param name="email">The User's email.</param> | ||||||
|         /// <param name="companyId">The identifier of the company to add.</param> |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// <returns>A <see cref="Task{UserAdapter}"/> representing the asynchronous operation, with the updated user object.</returns> |         /// <returns> | ||||||
|         ValueTask<UserAdapter> AddCompanyToUser(string userId, string companyId, CancellationToken cancellationToken); |         /// A <see cref="ValueTask{TokenAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|         /// <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> |  | ||||||
|         ValueTask<UserAdapter> RemoveCompanyFromUser(string userId, string companyId, CancellationToken cancellationToken); |  | ||||||
|  |  | ||||||
|         /// <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> |  | ||||||
|         ValueTask<UserAdapter> AddProjectToUser(string userId, string projectId, CancellationToken cancellationToken); |  | ||||||
|  |  | ||||||
|  |  | ||||||
|         /// <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> |  | ||||||
|         ValueTask<UserAdapter> RemoveProjectFromUser(string userId, string projectId, CancellationToken cancellationToken); |  | ||||||
|  |  | ||||||
|         /// <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> |  | ||||||
|         ValueTask<TokenAdapter?> GetToken(string email, CancellationToken cancellationToken); |         ValueTask<TokenAdapter?> GetToken(string email, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Delete an User by identifier. |         /// Deletes a User by Mongo identifier. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="id">The User identifier.</param> |         /// <param name="_id">The User Mongo identifier.</param> | ||||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// <returns> | ||||||
|         ValueTask<UserAdapter> DeleteUser(string _id, CancellationToken cancellationToken); |         /// A <see cref="ValueTask{UserAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|  |         ValueTask<UserAdapter?> DeleteUser(string _id, CancellationToken cancellationToken); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -11,15 +11,13 @@ | |||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|  |  | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <PackageReference Include="Blueprint.Mongo" Version="0.0.8" /> |     <PackageReference Include="Core.Blueprint.Mongo" Version="1.0.1" /> | ||||||
|     <PackageReference Include="Blueprint.Redis" Version="0.0.4" /> |     <PackageReference Include="Core.Blueprint.Redis" Version="1.0.2" /> | ||||||
|     <PackageReference Include="BuildingBlocks.Library" Version="0.0.1" /> |  | ||||||
|     <PackageReference Include="Mapster" Version="7.4.2-pre02" /> |     <PackageReference Include="Mapster" Version="7.4.2-pre02" /> | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|  |  | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <ProjectReference Include="..\Core.Thalos.Domain\Core.Thalos.Domain.csproj" /> |     <ProjectReference Include="..\Core.Thalos.Domain\Core.Thalos.Domain.csproj" /> | ||||||
|     <ProjectReference Include="..\Core.Thalos.Infraestructure\Core.Thalos.Infrastructure.csproj" /> |  | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|  |  | ||||||
| </Project> | </Project> | ||||||
|   | |||||||
| @@ -1,16 +0,0 @@ | |||||||
| using MongoDB.Driver; |  | ||||||
|  |  | ||||||
| namespace Core.Thalos.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.Thalos.Adapters.Common.Constants; |  | ||||||
| using MongoDB.Driver.Authentication.Oidc; |  | ||||||
|  |  | ||||||
| namespace Core.Thalos.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}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -3,16 +3,16 @@ | |||||||
| //     AgileWebs | //     AgileWebs | ||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| using Core.Thalos.Adapters; |  | ||||||
| using Core.Blueprint.Mongo; | using Core.Blueprint.Mongo; | ||||||
| using Core.Blueprint.Caching.Helpers; | using Core.Blueprint.Redis; | ||||||
| using Mapster; | using Core.Blueprint.Redis.Helpers; | ||||||
| using Microsoft.Extensions.Options; | using Core.Thalos.BuildingBlocks; | ||||||
| using MongoDB.Driver; |  | ||||||
| using Core.Thalos.Provider.Contracts; |  | ||||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
| using Core.Blueprint.Caching.Contracts; | using Core.Thalos.Provider.Contracts; | ||||||
| using Core.Blueprint.Caching.Adapters; | using Mapster; | ||||||
|  | using MongoDB.Driver; | ||||||
|  | using StatusEnum = Core.Blueprint.Mongo.StatusEnum; | ||||||
|  |  | ||||||
| namespace Core.Thalos.Provider.Providers.Onboarding | namespace Core.Thalos.Provider.Providers.Onboarding | ||||||
| { | { | ||||||
| @@ -22,59 +22,63 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|     public class ModuleProvider : IModuleProvider |     public class ModuleProvider : IModuleProvider | ||||||
|     { |     { | ||||||
|         private readonly CollectionRepository<ModuleAdapter> repository; |         private readonly CollectionRepository<ModuleAdapter> repository; | ||||||
|         private readonly CacheSettings cacheSettings; |         private readonly ICacheSettings cacheSettings; | ||||||
|         private readonly ICacheProvider cacheProvider; |         private readonly IRedisCacheProvider cacheProvider; | ||||||
|  |  | ||||||
|         public ModuleProvider(CollectionRepository<ModuleAdapter> repository, |         public ModuleProvider( | ||||||
|             ICacheProvider cacheProvider, |             CollectionRepository<ModuleAdapter> repository, | ||||||
|             IOptions<CacheSettings> cacheSettings) |             IRedisCacheProvider cacheProvider, | ||||||
|  |             ICacheSettings cacheSettings) | ||||||
|         { |         { | ||||||
|             this.repository = repository; |             this.repository = repository; | ||||||
|             this.repository.CollectionInitialization(); |             this.repository.CollectionInitialization(); | ||||||
|             this.cacheSettings = cacheSettings.Value; |  | ||||||
|             this.cacheProvider = cacheProvider; |             this.cacheProvider = cacheProvider; | ||||||
|  |             this.cacheSettings = cacheSettings; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Creates a new Module. |         /// Creates a new Module. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="entity">The Module to be created.</param> |         /// <param name="newModule">The Module to be created.</param> | ||||||
|         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{ModuleAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|         public async ValueTask<ModuleAdapter> CreateModule(ModuleRequest newModule, CancellationToken cancellationToken) |         public async ValueTask<ModuleAdapter> CreateModule(ModuleRequest newModule, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var moduleCollection = newModule.Adapt<ModuleAdapter>(); |             var moduleCollection = newModule.Adapt<ModuleAdapter>(); | ||||||
|  |  | ||||||
|             await repository.InsertOneAsync(moduleCollection); |             await repository.InsertOneAsync(moduleCollection); | ||||||
|  |  | ||||||
|             return moduleCollection; |             return moduleCollection; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets an Module by identifier. |         /// Gets a Module by identifier. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="id">The Module identifier.</param> |         /// <param name="_id">The Module Mongo identifier.</param> | ||||||
|         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// the asynchronous execution of the service.</returns>0 |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{ModuleAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|         public async ValueTask<ModuleAdapter> GetModuleById(string _id, CancellationToken cancellationToken) |         public async ValueTask<ModuleAdapter> GetModuleById(string _id, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetModuleById", _id); |             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetModuleById", _id); | ||||||
|             var cachedData = await cacheProvider.GetAsync<ModuleAdapter>(cacheKey); |             var cachedData = await cacheProvider.GetAsync<ModuleAdapter>(cacheKey); | ||||||
|  |  | ||||||
|             if (cachedData is not null) { return cachedData; } |             if (cachedData is not null) return cachedData; | ||||||
|  |  | ||||||
|             var module = await repository.FindByIdAsync(_id); |             var module = await repository.FindByIdAsync(_id); | ||||||
|  |             await cacheProvider.SetAsync(cacheKey, module, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes)); | ||||||
|             await cacheProvider.SetAsync(cacheKey, module); |  | ||||||
|  |  | ||||||
|             return module; |             return module; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets all the modules. |         /// Gets all the Modules. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <returns>A <see cref="{Task{IEnumerbale{ModuleAdapter}}}"/> representing |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{IEnumerable{ModuleAdapter}}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|         public async ValueTask<IEnumerable<ModuleAdapter>> GetAllModules(CancellationToken cancellationToken) |         public async ValueTask<IEnumerable<ModuleAdapter>> GetAllModules(CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetModules"); |             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetModules"); | ||||||
| @@ -83,22 +87,22 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|             if (cachedData.Any()) return cachedData; |             if (cachedData.Any()) return cachedData; | ||||||
|  |  | ||||||
|             var modules = await repository.AsQueryable(); |             var modules = await repository.AsQueryable(); | ||||||
|  |  | ||||||
|             await cacheProvider.SetAsync(cacheKey, modules); |             await cacheProvider.SetAsync(cacheKey, modules); | ||||||
|  |  | ||||||
|             return modules; |             return modules; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets all the modules by modules identifier list. |         /// Gets all the Modules by a list of identifiers. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="modules">The list of modules identifiers.</param> |         /// <param name="modules">The list of Module identifiers.</param> | ||||||
|         /// <returns>A <see cref="Task{IEnumerable{ModuleAdapter}}"/> representing |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// <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) |         public async ValueTask<IEnumerable<ModuleAdapter>> GetAllModulesByList(string[] modules, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllModulesByList", modules); |             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllModulesByList", modules); | ||||||
|  |  | ||||||
|             var cachedData = await cacheProvider.GetAsync<IEnumerable<ModuleAdapter>>(cacheKey) ?? []; |             var cachedData = await cacheProvider.GetAsync<IEnumerable<ModuleAdapter>>(cacheKey) ?? []; | ||||||
|  |  | ||||||
|             if (cachedData.Any()) return cachedData; |             if (cachedData.Any()) return cachedData; | ||||||
| @@ -106,49 +110,66 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|             var builder = Builders<ModuleAdapter>.Filter; |             var builder = Builders<ModuleAdapter>.Filter; | ||||||
|             var filters = new List<FilterDefinition<ModuleAdapter>>(); |             var filters = new List<FilterDefinition<ModuleAdapter>>(); | ||||||
|  |  | ||||||
|             if (modules != null || !modules.Any()) |             if (modules is { Length: > 0 }) | ||||||
|             { |             { | ||||||
|                 filters.Add(builder.In(x => x._Id, modules)); |                 filters.Add(builder.In(x => x._Id, modules)); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             var finalFilter = filters.Any() ? builder.And(filters) : builder.Empty; |             var finalFilter = filters.Any() ? builder.And(filters) : builder.Empty; | ||||||
|  |  | ||||||
|             var modulesList = await repository.FilterByMongoFilterAsync(finalFilter); |             var modulesList = await repository.FilterByMongoFilterAsync(finalFilter); | ||||||
|  |  | ||||||
|             await cacheProvider.SetAsync(cacheKey, modulesList); |             await cacheProvider.SetAsync(cacheKey, modulesList, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes)); | ||||||
|  |  | ||||||
|             return modulesList; |             return modulesList; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Changes the status of the module. |         /// Changes the status of the Module. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="id">The module identifier.</param> |         /// <param name="_id">The Module Mongo identifier.</param> | ||||||
|         /// <param name="newStatus">The new status of the module.</param> |         /// <param name="newStatus">The new status of the Module.</param> | ||||||
|         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// <returns> | ||||||
|         public async ValueTask<ModuleAdapter> ChangeModuleStatus(string id, Core.Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken) |         /// 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); |             var entity = await repository.FindByIdAsync(_id); | ||||||
|             entity.Status = newStatus; |  | ||||||
|  |  | ||||||
|             await repository.ReplaceOneAsync(entity); |             if (entity is not null) | ||||||
|  |             { | ||||||
|  |                 entity.Status = newStatus; | ||||||
|  |  | ||||||
|             return entity; |                 return repository.ReplaceOneAsync(entity).Result; | ||||||
|  |             } | ||||||
|  |             else return null; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Updates a Module by id. |         /// Updates a Module. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="entity">The Module to be updated.</param> |         /// <param name="entity">The Module to be updated.</param> | ||||||
|         /// <param name="id">The Module identifier.</param> |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing |         /// <returns> | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// A <see cref="ValueTask{ModuleAdapter}"/> representing the asynchronous execution of the service. | ||||||
|         public async ValueTask<ModuleAdapter> UpdateModule(ModuleAdapter entity, CancellationToken cancellationToken) |         /// </returns> | ||||||
|  |         public async ValueTask<ModuleAdapter?> UpdateModule(ModuleAdapter entity, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             await repository.ReplaceOneAsync(entity); |             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; |             return entity; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -3,15 +3,14 @@ | |||||||
| //     AgileWebs | //     AgileWebs | ||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| using Core.Blueprint.Caching.Adapters; |  | ||||||
| using Core.Blueprint.Caching.Contracts; |  | ||||||
| using Core.Blueprint.Caching.Helpers; |  | ||||||
| using Core.Blueprint.Mongo; | using Core.Blueprint.Mongo; | ||||||
| using Core.Thalos.Adapters; | using Core.Blueprint.Redis; | ||||||
|  | using Core.Blueprint.Redis.Helpers; | ||||||
|  | using Core.Thalos.BuildingBlocks; | ||||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
| using Core.Thalos.Provider.Contracts; | using Core.Thalos.Provider.Contracts; | ||||||
| using Mapster; | using Mapster; | ||||||
| using Microsoft.Extensions.Options; |  | ||||||
| using MongoDB.Driver; | using MongoDB.Driver; | ||||||
|  |  | ||||||
| namespace Core.Thalos.Provider.Providers.Onboarding | namespace Core.Thalos.Provider.Providers.Onboarding | ||||||
| @@ -22,60 +21,63 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|     public class PermissionProvider : IPermissionProvider |     public class PermissionProvider : IPermissionProvider | ||||||
|     { |     { | ||||||
|         private readonly CollectionRepository<PermissionAdapter> repository; |         private readonly CollectionRepository<PermissionAdapter> repository; | ||||||
|         private readonly CacheSettings cacheSettings; |         private readonly ICacheSettings cacheSettings; | ||||||
|         private readonly ICacheProvider cacheProvider; |         private readonly IRedisCacheProvider cacheProvider; | ||||||
|  |  | ||||||
|         public PermissionProvider(CollectionRepository<PermissionAdapter> repository, |         public PermissionProvider( | ||||||
|             ICacheProvider cacheProvider, |             CollectionRepository<PermissionAdapter> repository, | ||||||
|             IOptions<CacheSettings> cacheSettings |             IRedisCacheProvider cacheProvider, | ||||||
|             ) |             ICacheSettings cacheSettings) | ||||||
|         { |         { | ||||||
|             this.repository = repository; |             this.repository = repository; | ||||||
|             this.repository.CollectionInitialization(); |             this.repository.CollectionInitialization(); | ||||||
|             this.cacheSettings = cacheSettings.Value; |  | ||||||
|             this.cacheProvider = cacheProvider; |             this.cacheProvider = cacheProvider; | ||||||
|  |             this.cacheSettings = cacheSettings; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Creates a new Permission. |         /// Creates a new Permission. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="entity">The Permission to be created.</param> |         /// <param name="newPermission">The Permission to be created.</param> | ||||||
|         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{PermissionAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|         public async ValueTask<PermissionAdapter> CreatePermission(PermissionRequest newPermission, CancellationToken cancellationToken) |         public async ValueTask<PermissionAdapter> CreatePermission(PermissionRequest newPermission, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var permissionCollection = newPermission.Adapt<PermissionAdapter>(); |             var permissionCollection = newPermission.Adapt<PermissionAdapter>(); | ||||||
|  |  | ||||||
|             await repository.InsertOneAsync(permissionCollection); |             await repository.InsertOneAsync(permissionCollection); | ||||||
|  |  | ||||||
|             return permissionCollection; |             return permissionCollection; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets an Permission by identifier. |         /// Gets a Permission by identifier. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="id">The Permission identifier.</param> |         /// <param name="_id">The Permission Mongo identifier.</param> | ||||||
|         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// the asynchronous execution of the service.</returns>0 |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{PermissionAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|         public async ValueTask<PermissionAdapter> GetPermissionById(string _id, CancellationToken cancellationToken) |         public async ValueTask<PermissionAdapter> GetPermissionById(string _id, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetPermissionById", _id); |             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetPermissionById", _id); | ||||||
|             var cachedData = await cacheProvider.GetAsync<PermissionAdapter>(cacheKey); |             var cachedData = await cacheProvider.GetAsync<PermissionAdapter>(cacheKey); | ||||||
|  |  | ||||||
|             //if (cachedData is not null) { return cachedData; } |             if (cachedData is not null) return cachedData; | ||||||
|  |  | ||||||
|             var permission = await repository.FindByIdAsync(_id); |             var permission = await repository.FindByIdAsync(_id); | ||||||
|  |  | ||||||
|             await cacheProvider.SetAsync(cacheKey, permission); |             await cacheProvider.SetAsync(cacheKey, permission); | ||||||
|  |  | ||||||
|             return permission; |             return permission; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets all the permissions. |         /// Gets all Permissions. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <returns>A <see cref="{Task{IEnumerbale{PermissionAdapter}}}"/> representing |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{IEnumerable{PermissionAdapter}}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|         public async ValueTask<IEnumerable<PermissionAdapter>> GetAllPermissions(CancellationToken cancellationToken) |         public async ValueTask<IEnumerable<PermissionAdapter>> GetAllPermissions(CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllPermissions"); |             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllPermissions"); | ||||||
| @@ -84,22 +86,22 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|             if (cachedData.Any()) return cachedData; |             if (cachedData.Any()) return cachedData; | ||||||
|  |  | ||||||
|             var permissions = await repository.AsQueryable(); |             var permissions = await repository.AsQueryable(); | ||||||
|  |             await cacheProvider.SetAsync(cacheKey, permissions, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes)); | ||||||
|             await cacheProvider.SetAsync(cacheKey, permissions); |  | ||||||
|  |  | ||||||
|             return permissions; |             return permissions; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets all the permissions by permissions identifier list. |         /// Gets all Permissions by a list of identifiers. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="permissions">The list of permissions identifiers.</param> |         /// <param name="permissions">The list of Permission identifiers.</param> | ||||||
|         /// <returns>A <see cref="Task{IEnumerable{PermissionAdapter}}"/> representing |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// <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) |         public async ValueTask<IEnumerable<PermissionAdapter>> GetAllPermissionsByList(string[] permissions, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllPermissionsByList", permissions); |             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllPermissionsByList", permissions); | ||||||
|  |  | ||||||
|             var cachedData = await cacheProvider.GetAsync<IEnumerable<PermissionAdapter>>(cacheKey) ?? []; |             var cachedData = await cacheProvider.GetAsync<IEnumerable<PermissionAdapter>>(cacheKey) ?? []; | ||||||
|  |  | ||||||
|             if (cachedData.Any()) return cachedData; |             if (cachedData.Any()) return cachedData; | ||||||
| @@ -107,49 +109,66 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|             var builder = Builders<PermissionAdapter>.Filter; |             var builder = Builders<PermissionAdapter>.Filter; | ||||||
|             var filters = new List<FilterDefinition<PermissionAdapter>>(); |             var filters = new List<FilterDefinition<PermissionAdapter>>(); | ||||||
|  |  | ||||||
|             if (permissions != null || !permissions.Any()) |             if (permissions is { Length: > 0 }) | ||||||
|             { |             { | ||||||
|                 filters.Add(builder.In(x => x._Id, permissions)); |                 filters.Add(builder.In(x => x._Id, permissions)); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             var finalFilter = filters.Any() ? builder.And(filters) : builder.Empty; |             var finalFilter = filters.Any() ? builder.And(filters) : builder.Empty; | ||||||
|  |  | ||||||
|             var permissionsList = await repository.FilterByMongoFilterAsync(finalFilter); |             var permissionsList = await repository.FilterByMongoFilterAsync(finalFilter); | ||||||
|  |  | ||||||
|             await cacheProvider.SetAsync(cacheKey, permissionsList); |             await cacheProvider.SetAsync(cacheKey, permissionsList, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes)); | ||||||
|  |  | ||||||
|             return permissionsList; |             return permissionsList; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Changes the status of the permission. |         /// Changes the status of a 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> | ||||||
|         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// <returns> | ||||||
|         public async ValueTask<PermissionAdapter> ChangePermissionStatus(string id, StatusEnum newStatus, CancellationToken cancellationToken) |         /// 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); |             var entity = await repository.FindByIdAsync(_id); | ||||||
|             entity.Status = newStatus; |  | ||||||
|  |  | ||||||
|             await repository.ReplaceOneAsync(entity); |             if (entity is not null) | ||||||
|  |             { | ||||||
|  |                 entity.Status = newStatus; | ||||||
|  |  | ||||||
|             return entity; |                 return repository.ReplaceOneAsync(entity).Result; | ||||||
|  |             } | ||||||
|  |             else return null; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Updates a Permission by id. |         /// Updates a Permission. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="entity">The Permission to be updated.</param> |         /// <param name="entity">The Permission to be updated.</param> | ||||||
|         /// <param name="id">The Permission identifier.</param> |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing |         /// <returns> | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// A <see cref="ValueTask{PermissionAdapter}"/> representing the asynchronous execution of the service. | ||||||
|         public async ValueTask<PermissionAdapter> UpdatePermission(PermissionAdapter entity, CancellationToken cancellationToken) |         /// </returns> | ||||||
|  |         public async ValueTask<PermissionAdapter?> UpdatePermission(PermissionAdapter entity, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             await repository.ReplaceOneAsync(entity); |             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; |             return entity; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -3,22 +3,15 @@ | |||||||
| //     AgileWebs | //     AgileWebs | ||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| using Core.Blueprint.Caching.Adapters; |  | ||||||
| using Core.Blueprint.Caching.Contracts; |  | ||||||
| using Core.Blueprint.Caching.Helpers; |  | ||||||
| using Core.Blueprint.Mongo; | using Core.Blueprint.Mongo; | ||||||
| using Core.Thalos.Adapters; | using Core.Blueprint.Redis; | ||||||
| using Core.Thalos.Adapters.Common.Enums; | using Core.Blueprint.Redis.Helpers; | ||||||
|  | using Core.Thalos.BuildingBlocks; | ||||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
| using Core.Thalos.Provider.Contracts; | using Core.Thalos.Provider.Contracts; | ||||||
| using Mapster; | using Mapster; | ||||||
| using Microsoft.Extensions.Options; |  | ||||||
| using Microsoft.Graph; |  | ||||||
| using MongoDB.Bson; |  | ||||||
| using MongoDB.Bson.Serialization; |  | ||||||
| using MongoDB.Driver; | using MongoDB.Driver; | ||||||
| using System.ComponentModel.Design; |  | ||||||
| using System.Text.RegularExpressions; |  | ||||||
|  |  | ||||||
| namespace Core.Thalos.Provider.Providers.Onboarding | namespace Core.Thalos.Provider.Providers.Onboarding | ||||||
| { | { | ||||||
| @@ -28,60 +21,63 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|     public class RoleProvider : IRoleProvider |     public class RoleProvider : IRoleProvider | ||||||
|     { |     { | ||||||
|         private readonly CollectionRepository<RoleAdapter> repository; |         private readonly CollectionRepository<RoleAdapter> repository; | ||||||
| 		private readonly CacheSettings cacheSettings; |         private readonly ICacheSettings cacheSettings; | ||||||
| 		private readonly ICacheProvider cacheProvider; |         private readonly IRedisCacheProvider cacheProvider; | ||||||
|  |  | ||||||
| 		public RoleProvider(CollectionRepository<RoleAdapter> repository, |         public RoleProvider( | ||||||
| 		    ICacheProvider cacheProvider, |             CollectionRepository<RoleAdapter> repository, | ||||||
| 			IOptions<CacheSettings> cacheSettings |             IRedisCacheProvider cacheProvider, | ||||||
| 			) |             ICacheSettings cacheSettings) | ||||||
|         { |         { | ||||||
|             this.repository = repository; |             this.repository = repository; | ||||||
|             this.repository.CollectionInitialization(); |             this.repository.CollectionInitialization(); | ||||||
| 			this.cacheSettings = cacheSettings.Value; |             this.cacheProvider = cacheProvider; | ||||||
| 			this.cacheProvider = cacheProvider; |             this.cacheSettings = cacheSettings; | ||||||
| 		} |         } | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Creates a new Role. |         /// Creates a new Role. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="entity">The Role to be created.</param> |         /// <param name="newRole">The Role to be created.</param> | ||||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{RoleAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|         public async ValueTask<RoleAdapter> CreateRole(RoleRequest newRole, CancellationToken cancellationToken) |         public async ValueTask<RoleAdapter> CreateRole(RoleRequest newRole, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var roleCollection = newRole.Adapt<RoleAdapter>(); |             var roleCollection = newRole.Adapt<RoleAdapter>(); | ||||||
|  |  | ||||||
|             await repository.InsertOneAsync(roleCollection); |             await repository.InsertOneAsync(roleCollection); | ||||||
|  |  | ||||||
|             return roleCollection; |             return roleCollection; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets an Role by identifier. |         /// Gets a Role by its identifier. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="id">The Role identifier.</param> |         /// <param name="_id">The Role Mongo identifier.</param> | ||||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{RoleAdapter}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|         public async ValueTask<RoleAdapter> GetRoleById(string _id, CancellationToken cancellationToken) |         public async ValueTask<RoleAdapter> GetRoleById(string _id, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetRoleById", _id); |             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetRoleById", _id); | ||||||
|             var cachedData = await cacheProvider.GetAsync<RoleAdapter>(cacheKey); |             var cachedData = await cacheProvider.GetAsync<RoleAdapter>(cacheKey); | ||||||
|  |  | ||||||
|             if (cachedData is not null) { return cachedData; } |             if (cachedData is not null) return cachedData; | ||||||
|  |  | ||||||
|             var role = await repository.FindByIdAsync(_id); |             var role = await repository.FindByIdAsync(_id); | ||||||
|  |             await cacheProvider.SetAsync(cacheKey, role, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes)); | ||||||
|             await cacheProvider.SetAsync(cacheKey, role); |  | ||||||
|  |  | ||||||
|             return role; |             return role; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets all the roles. |         /// Gets all Roles. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <returns>A <see cref="{Task{IEnumerbale{RoleAdapter}}}"/> representing |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// <returns> | ||||||
|  |         /// A <see cref="ValueTask{IEnumerable{RoleAdapter}}"/> representing the asynchronous execution of the service. | ||||||
|  |         /// </returns> | ||||||
|         public async ValueTask<IEnumerable<RoleAdapter>> GetAllRoles(CancellationToken cancellationToken) |         public async ValueTask<IEnumerable<RoleAdapter>> GetAllRoles(CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllRoles"); |             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllRoles"); | ||||||
| @@ -90,84 +86,105 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|             if (cachedData.Any()) return cachedData; |             if (cachedData.Any()) return cachedData; | ||||||
|  |  | ||||||
|             var roles = await repository.AsQueryable(); |             var roles = await repository.AsQueryable(); | ||||||
|  |             await cacheProvider.SetAsync(cacheKey, roles, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes)); | ||||||
|             await cacheProvider.SetAsync(cacheKey, roles); |  | ||||||
|  |  | ||||||
|             return roles; |             return roles; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Changes the status of the role. |         /// Changes the status of a Role. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="id">The role identifier.</param> |         /// <param name="_id">The Role Mongo identifier.</param> | ||||||
|         /// <param name="newStatus">The new status of the role.</param> |         /// <param name="newStatus">The new status of the Role.</param> | ||||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// <returns> | ||||||
|         public async ValueTask<RoleAdapter> ChangeRoleStatus(string id, Core.Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken) |         /// 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); |             var entity = await repository.FindByIdAsync(_id); | ||||||
|             entity.Status = newStatus; |  | ||||||
|  |  | ||||||
|             await repository.ReplaceOneAsync(entity); |             if (entity is not null) | ||||||
|  |             { | ||||||
|  |                 entity.Status = newStatus; | ||||||
|  |  | ||||||
|             return entity; |                 return repository.ReplaceOneAsync(entity).Result; | ||||||
|  |             } | ||||||
|  |             else return null; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Updates a Role by id. |         /// Updates a Role. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="entity">The Role to be updated.</param> |         /// <param name="entity">The Role to be updated.</param> | ||||||
|         /// <param name="id">The Role identifier.</param> |         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing |         /// <returns> | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// A <see cref="ValueTask{RoleAdapter}"/> representing the asynchronous execution of the service. | ||||||
|         public async ValueTask<RoleAdapter> UpdateRole(RoleAdapter entity, CancellationToken cancellationToken) |         /// </returns> | ||||||
|  |         public async ValueTask<RoleAdapter?> UpdateRole(RoleAdapter entity, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             await repository.ReplaceOneAsync(entity); |             var updatedEntity = await repository.ReplaceOneAsync(entity); | ||||||
|  |             return updatedEntity; | ||||||
|             return entity; |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Adds an application to the role's list of applications. |         /// Adds an application to the Role's list of applications. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="roleId">The identifier of the role to which the application will be added.</param> |         /// <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="application">The application enum value to add.</param> | ||||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing the asynchronous operation, with the updated role object.</returns> |         /// <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) |         public async ValueTask<RoleAdapter> AddApplicationToRole(string roleId, ApplicationsEnum application, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var role = await repository.FindOneAsync( |             var role = await repository.FindOneAsync( | ||||||
|                 u => u._Id == roleId && |                 u => u._Id == roleId && u.Status == Blueprint.Mongo.StatusEnum.Active); | ||||||
|                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); |  | ||||||
|  |  | ||||||
|             var updatedApplications = role.Applications.Append(application).Distinct().ToArray(); |             var updatedApplications = role.Applications?.Append(application).Distinct().ToArray(); | ||||||
|             role.Applications = updatedApplications; |             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); |             await repository.ReplaceOneAsync(role); | ||||||
|  |  | ||||||
|             return role; |             return role; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Removes an application from the role's list of applications. |         /// Deletes a Role by identifier. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="roleId">The identifier of the role from which the application will be removed.</param> |         /// <param name="_id">The Role Mongo identifier.</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="{Task{RoleAdapter}}"/> representing the asynchronous operation, with the updated role object.</returns> |         /// <returns> | ||||||
|         public async ValueTask<RoleAdapter> RemoveApplicationFromRole(string roleId, ApplicationsEnum application, CancellationToken cancellationToken) |         /// 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 role = await repository.FindOneAsync( |             var entity = await repository.DeleteOneAsync(doc => doc._Id == _id); | ||||||
|                 u => u._Id == roleId && |             return entity; | ||||||
|                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); |  | ||||||
|  |  | ||||||
|             var updatedApplications = role.Applications |  | ||||||
|                     ?.Where(c => c != application) |  | ||||||
|                     .ToArray(); |  | ||||||
|  |  | ||||||
|             role.Applications = updatedApplications; |  | ||||||
|  |  | ||||||
|             await repository.ReplaceOneAsync(role); |  | ||||||
|  |  | ||||||
|             return role; |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
							
								
								
									
										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; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -4,19 +4,15 @@ | |||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
|  |  | ||||||
| using Core.Blueprint.Caching.Adapters; |  | ||||||
| using Core.Blueprint.Caching.Contracts; |  | ||||||
| using Core.Blueprint.Caching.Helpers; |  | ||||||
| using Core.Blueprint.Mongo; | using Core.Blueprint.Mongo; | ||||||
| using Core.Thalos.Adapters; | using Core.Blueprint.Redis; | ||||||
| using Core.Thalos.Adapters.Common.Enums; | using Core.Blueprint.Redis.Helpers; | ||||||
|  | using Core.Thalos.BuildingBlocks; | ||||||
| using Core.Thalos.Provider.Contracts; | using Core.Thalos.Provider.Contracts; | ||||||
| using Mapster; | using Mapster; | ||||||
| using Microsoft.Extensions.Options; |  | ||||||
| using MongoDB.Bson; | using MongoDB.Bson; | ||||||
| using MongoDB.Bson.Serialization; | using MongoDB.Bson.Serialization; | ||||||
| using MongoDB.Driver; | using MongoDB.Driver; | ||||||
| using System.Reflection; |  | ||||||
| using System.Text.RegularExpressions; | using System.Text.RegularExpressions; | ||||||
|  |  | ||||||
| namespace Core.Thalos.Provider.Providers.Onboarding | namespace Core.Thalos.Provider.Providers.Onboarding | ||||||
| @@ -27,19 +23,19 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|     public class UserProvider : IUserProvider |     public class UserProvider : IUserProvider | ||||||
|     { |     { | ||||||
|         private readonly CollectionRepository<UserAdapter> repository; |         private readonly CollectionRepository<UserAdapter> repository; | ||||||
| 		private readonly CacheSettings cacheSettings; |         private readonly ICacheSettings cacheSettings; | ||||||
| 		private readonly ICacheProvider cacheProvider; |         private readonly IRedisCacheProvider cacheProvider; | ||||||
|  |  | ||||||
| 		public UserProvider(CollectionRepository<UserAdapter> repository, |         public UserProvider(CollectionRepository<UserAdapter> repository, | ||||||
|             ICacheProvider cacheProvider, |             IRedisCacheProvider cacheProvider, | ||||||
| 			IOptions<CacheSettings> cacheSettings |             ICacheSettings cacheSettings | ||||||
|             ) |             ) | ||||||
|         { |         { | ||||||
|             this.repository = repository; |             this.repository = repository; | ||||||
|             this.repository.CollectionInitialization(); |             this.repository.CollectionInitialization(); | ||||||
| 			this.cacheSettings = cacheSettings.Value; |             this.cacheSettings = cacheSettings; | ||||||
| 			this.cacheProvider = cacheProvider; |             this.cacheProvider = cacheProvider; | ||||||
| 		} |         } | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Creates a new User. |         /// Creates a new User. | ||||||
| @@ -59,7 +55,7 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets an User by identifier. |         /// Gets an User by identifier. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="id">The User identifier.</param> |         /// <param name="_id">The User mongo identifier.</param> | ||||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing |         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         public async ValueTask<UserAdapter> GetUserById(string _id, CancellationToken cancellationToken) |         public async ValueTask<UserAdapter> GetUserById(string _id, CancellationToken cancellationToken) | ||||||
| @@ -67,11 +63,11 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetUserById", _id); |             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetUserById", _id); | ||||||
|             var cachedData = await cacheProvider.GetAsync<UserAdapter>(cacheKey); |             var cachedData = await cacheProvider.GetAsync<UserAdapter>(cacheKey); | ||||||
|  |  | ||||||
|             //if (cachedData is not null) { return cachedData; } |             if (cachedData is not null) { return cachedData; } | ||||||
|  |  | ||||||
|             var user = await repository.FindByIdAsync(_id); |             var user = await repository.FindByIdAsync(_id); | ||||||
|  |  | ||||||
|             await cacheProvider.SetAsync(cacheKey, user); |             await cacheProvider.SetAsync(cacheKey, user, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes)); | ||||||
|  |  | ||||||
|             return user; |             return user; | ||||||
|         } |         } | ||||||
| @@ -86,11 +82,11 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllUsers"); |             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllUsers"); | ||||||
|             var cachedData = await cacheProvider.GetAsync<IEnumerable<UserAdapter>>(cacheKey) ?? []; |             var cachedData = await cacheProvider.GetAsync<IEnumerable<UserAdapter>>(cacheKey) ?? []; | ||||||
|  |  | ||||||
|             if (cachedData.Any()) return cachedData; |             //if (cachedData.Any()) return cachedData; | ||||||
|  |  | ||||||
|             var users = await repository.AsQueryable(); |             var users = await repository.AsQueryable(); | ||||||
|  |  | ||||||
|             await cacheProvider.SetAsync(cacheKey, users); |             await cacheProvider.SetAsync(cacheKey, users, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes)); | ||||||
|  |  | ||||||
|             return users; |             return users; | ||||||
|         } |         } | ||||||
| @@ -101,7 +97,7 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|         /// <param name="email">The User email.</param> |         /// <param name="email">The User email.</param> | ||||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing |         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         public async ValueTask<UserAdapter> GetUserByEmail(string? email, CancellationToken cancellationToken) |         public async ValueTask<UserAdapter> GetUserByEmail(string email, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetUserByEmail", email); |             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetUserByEmail", email); | ||||||
|             var cachedData = await cacheProvider.GetAsync<UserAdapter>(cacheKey); |             var cachedData = await cacheProvider.GetAsync<UserAdapter>(cacheKey); | ||||||
| @@ -109,7 +105,7 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|             //if (cachedData is not null) { return cachedData; } |             //if (cachedData is not null) { return cachedData; } | ||||||
|  |  | ||||||
|             var user = await repository.FindOneAsync( |             var user = await repository.FindOneAsync( | ||||||
|                 u => u.Email == email &&  |                 u => u.Email == email && | ||||||
|                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); |                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); | ||||||
|  |  | ||||||
|             await cacheProvider.SetAsync(cacheKey, user); |             await cacheProvider.SetAsync(cacheKey, user); | ||||||
| @@ -123,7 +119,7 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|         /// <param name="email">The User email.</param> |         /// <param name="email">The User email.</param> | ||||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing |         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         public async ValueTask<UserExistenceAdapter> ValidateUserExistence(string? email, CancellationToken cancellationToken) |         public async ValueTask<UserExistenceAdapter> ValidateUserExistence(string email, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetUserByEmail", email); |             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetUserByEmail", email); | ||||||
|             var cachedData = await cacheProvider.GetAsync<UserAdapter>(cacheKey); |             var cachedData = await cacheProvider.GetAsync<UserAdapter>(cacheKey); | ||||||
| @@ -146,38 +142,40 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Changes the status of the user. |         /// Changes the status of the user. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="id">The user identifier.</param> |         /// <param name="_id">The user mongo identifier.</param> | ||||||
|         /// <param name="newStatus">The new status of the user.</param> |         /// <param name="newStatus">The new status of the user.</param> | ||||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing |         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         public async ValueTask<UserAdapter> ChangeUserStatus(string id, Core.Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken) |         public async ValueTask<UserAdapter?> ChangeUserStatus(string _id, Core.Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var entity = await repository.FindByIdAsync(id); |             var entity = await repository.FindByIdAsync(_id); | ||||||
|             entity.Status = newStatus; |  | ||||||
|  |  | ||||||
|             await repository.ReplaceOneAsync(entity); |             if (entity is not null) | ||||||
|  |             { | ||||||
|  |                 entity.Status = newStatus; | ||||||
|  |  | ||||||
|             return entity; |                 return repository.ReplaceOneAsync(entity).Result; | ||||||
|  |             } | ||||||
|  |             else return null; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Updates a User by id. |         /// Updates a User by _id. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="entity">The User to be updated.</param> |         /// <param name="entity">The User to be updated.</param> | ||||||
|         /// <param name="id">The User identifier.</param> |         /// <param name="_id">The User mongo identifier.</param> | ||||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing |         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         public async ValueTask<UserAdapter> UpdateUser(UserAdapter entity, CancellationToken cancellationToken) |         public async ValueTask<UserAdapter?> UpdateUser(UserAdapter entity, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             await repository.ReplaceOneAsync(entity); |             var updatedEntity = await repository.ReplaceOneAsync(entity); | ||||||
|  |             return updatedEntity; | ||||||
|             return entity; |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Logs in the user. |         /// Logs in the user. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="id">The User identifier.</param> |         /// <param name="_id">The User mongo identifier.</param> | ||||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing |         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         public async ValueTask<UserAdapter?> LogInUser(string email, CancellationToken cancellationToken) |         public async ValueTask<UserAdapter?> LogInUser(string email, CancellationToken cancellationToken) | ||||||
| @@ -212,92 +210,6 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|             return user; |             return user; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <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 ValueTask<UserAdapter> AddCompanyToUser(string userId, string companyId, CancellationToken cancellationToken) |  | ||||||
|         { |  | ||||||
|             var user = await repository.FindOneAsync( |  | ||||||
|                 u => u._Id == userId && |  | ||||||
|                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); |  | ||||||
|  |  | ||||||
|             var updatedCompanies = user.Companies.Append(companyId).Distinct().ToArray(); |  | ||||||
|             user.Companies = updatedCompanies; |  | ||||||
|  |  | ||||||
|             await repository.ReplaceOneAsync(user); |  | ||||||
|  |  | ||||||
|             return user; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <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 ValueTask<UserAdapter> RemoveCompanyFromUser(string userId, string companyId, CancellationToken cancellationToken) |  | ||||||
|         { |  | ||||||
|             var user = await repository.FindOneAsync( |  | ||||||
|                 u => u._Id == userId && |  | ||||||
|                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); |  | ||||||
|  |  | ||||||
|             var updatedCompanies = user.Companies |  | ||||||
|                     ?.Where(c => c != companyId) |  | ||||||
|                     .ToArray(); |  | ||||||
|  |  | ||||||
|             user.Companies = updatedCompanies; |  | ||||||
|  |  | ||||||
|             await repository.ReplaceOneAsync(user); |  | ||||||
|  |  | ||||||
|             return user; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <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 ValueTask<UserAdapter> AddProjectToUser(string userId, string projectId, CancellationToken cancellationToken) |  | ||||||
|         { |  | ||||||
|             var user = await repository.FindOneAsync( |  | ||||||
|                 u => u._Id == userId && |  | ||||||
|                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); |  | ||||||
|  |  | ||||||
|             var updatedProjects = user.Projects.Append(projectId).Distinct().ToArray(); |  | ||||||
|             user.Projects = updatedProjects; |  | ||||||
|  |  | ||||||
|             await repository.ReplaceOneAsync(user); |  | ||||||
|  |  | ||||||
|             return user; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <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 ValueTask<UserAdapter> RemoveProjectFromUser(string userId, string projectId, CancellationToken cancellationToken) |  | ||||||
|         { |  | ||||||
|             var user = await repository.FindOneAsync( |  | ||||||
|                 u => u._Id == userId && |  | ||||||
|                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); |  | ||||||
|  |  | ||||||
|             var updatedProjects = user.Projects |  | ||||||
|                     ?.Where(c => c != projectId) |  | ||||||
|                     .ToArray(); |  | ||||||
|  |  | ||||||
|             user.Projects = updatedProjects; |  | ||||||
|  |  | ||||||
|             await repository.ReplaceOneAsync(user); |  | ||||||
|  |  | ||||||
|             return user; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets the token adapter for a user. |         /// Gets the token adapter for a user. | ||||||
|         /// </summary> |         /// </summary> | ||||||
| @@ -407,31 +319,19 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|                     User = new UserAdapter |                     User = new UserAdapter | ||||||
|                     { |                     { | ||||||
|                         Id = result["_id"]?.ToString() ?? "", |                         Id = result["_id"]?.ToString() ?? "", | ||||||
|                         Guid = result.Contains("guid") && !result["guid"].IsBsonNull ? result["guid"].AsString : "", |                         Guid = result.Contains("guid") && !result["guid"].IsBsonNull ? result["guid"].AsString : string.Empty, | ||||||
|                         Email = result.Contains("email") && !result["email"].IsBsonNull ? result["email"].AsString : "", |                         Email = result.Contains("email") && !result["email"].IsBsonNull ? result["email"].AsString : string.Empty, | ||||||
|                         Name = result.Contains("name") && !result["name"].IsBsonNull ? result["name"].AsString : "", |                         Name = result.Contains("name") && !result["name"].IsBsonNull ? result["name"].AsString : string.Empty, | ||||||
|                         MiddleName = result.Contains("middleName") && !result["middleName"].IsBsonNull ? result["middleName"].AsString : "", |                         MiddleName = result.Contains("middleName") && !result["middleName"].IsBsonNull ? result["middleName"].AsString : string.Empty, | ||||||
|                         LastName = result.Contains("lastName") && !result["lastName"].IsBsonNull ? result["lastName"].AsString : "", |                         LastName = result.Contains("lastName") && !result["lastName"].IsBsonNull ? result["lastName"].AsString : string.Empty, | ||||||
|                         DisplayName = result.Contains("displayName") && !result["displayName"].IsBsonNull ? result["displayName"].AsString : "", |                         DisplayName = result.Contains("displayName") && !result["displayName"].IsBsonNull ? result["displayName"].AsString : string.Empty, | ||||||
|                         RoleId = result.Contains("roleId") && !result["roleId"].IsBsonNull ? result["roleId"].ToString() : "", |                         RoleId = result.Contains("roleId") && !result["roleId"].IsBsonNull ? result["roleId"].ToString() : string.Empty, | ||||||
|                         Companies = result.Contains("companies") && result["companies"].IsBsonArray |  | ||||||
|                             ? result["companies"].AsBsonArray |  | ||||||
|                                 .Where(c => c != null && !c.IsBsonNull) |  | ||||||
|                                 .Select(c => c.AsString) |  | ||||||
|                                 .ToArray() |  | ||||||
|                             : Array.Empty<string>(), |  | ||||||
|                                         Projects = result.Contains("projects") && result["projects"].IsBsonArray |  | ||||||
|                             ? result["projects"].AsBsonArray |  | ||||||
|                                 .Where(p => p != null && !p.IsBsonNull) |  | ||||||
|                                 .Select(p => p.AsString) |  | ||||||
|                                 .ToArray() |  | ||||||
|                             : Array.Empty<string>(), |  | ||||||
|                         LastLogIn = result.Contains("lastLogIn") && !result["lastLogIn"].IsBsonNull ? result["lastLogIn"].ToUniversalTime() : DateTime.MinValue, |                         LastLogIn = result.Contains("lastLogIn") && !result["lastLogIn"].IsBsonNull ? result["lastLogIn"].ToUniversalTime() : DateTime.MinValue, | ||||||
|                         LastLogOut = result.Contains("lastLogOut") && !result["lastLogOut"].IsBsonNull ? result["lastLogOut"].ToUniversalTime() : DateTime.MinValue, |                         LastLogOut = result.Contains("lastLogOut") && !result["lastLogOut"].IsBsonNull ? result["lastLogOut"].ToUniversalTime() : DateTime.MinValue, | ||||||
|                         CreatedAt = result.Contains("createdAt") && !result["createdAt"].IsBsonNull ? result["createdAt"].ToUniversalTime() : DateTime.MinValue, |                         CreatedAt = result.Contains("createdAt") && !result["createdAt"].IsBsonNull ? result["createdAt"].ToUniversalTime() : DateTime.MinValue, | ||||||
|                         CreatedBy = result.Contains("createdBy") && !result["createdBy"].IsBsonNull ? result["createdBy"].AsString : "", |                         CreatedBy = result.Contains("createdBy") && !result["createdBy"].IsBsonNull ? result["createdBy"].AsString : string.Empty, | ||||||
|                         UpdatedAt = result.Contains("updatedAt") && !result["updatedAt"].IsBsonNull ? result["updatedAt"].ToUniversalTime() : DateTime.MinValue, |                         UpdatedAt = result.Contains("updatedAt") && !result["updatedAt"].IsBsonNull ? result["updatedAt"].ToUniversalTime() : DateTime.MinValue, | ||||||
|                         UpdatedBy = result.Contains("updatedBy") && !result["updatedBy"].IsBsonNull ? result["updatedBy"].AsString : "", |                         UpdatedBy = result.Contains("updatedBy") && !result["updatedBy"].IsBsonNull ? result["updatedBy"].AsString : string.Empty, | ||||||
|                         Status = result.Contains("status") && !result["status"].IsBsonNull |                         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)Enum.Parse(typeof(Core.Blueprint.Mongo.StatusEnum), result["status"].AsString) | ||||||
|                             : Core.Blueprint.Mongo.StatusEnum.Inactive |                             : Core.Blueprint.Mongo.StatusEnum.Inactive | ||||||
| @@ -440,13 +340,13 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|                     { |                     { | ||||||
|                         Id = result.Contains("role") && result["role"].IsBsonDocument && result["role"].AsBsonDocument.Contains("_id") |                         Id = result.Contains("role") && result["role"].IsBsonDocument && result["role"].AsBsonDocument.Contains("_id") | ||||||
|                             ? result["role"]["_id"]?.ToString() ?? "" |                             ? result["role"]["_id"]?.ToString() ?? "" | ||||||
|                             : "", |                             : string.Empty, | ||||||
|                         Name = result.Contains("role") && result["role"].IsBsonDocument && result["role"].AsBsonDocument.Contains("name") |                         Name = result.Contains("role") && result["role"].IsBsonDocument && result["role"].AsBsonDocument.Contains("name") | ||||||
|                             ? result["role"]["name"]?.AsString ?? "" |                             ? result["role"]["name"]?.AsString ?? "" | ||||||
|                             : "", |                             : string.Empty, | ||||||
|                         Description = result.Contains("role") && result["role"].IsBsonDocument && result["role"].AsBsonDocument.Contains("description") |                         Description = result.Contains("role") && result["role"].IsBsonDocument && result["role"].AsBsonDocument.Contains("description") | ||||||
|                             ? result["role"]["description"]?.AsString ?? "" |                             ? result["role"]["description"]?.AsString ?? "" | ||||||
|                             : "", |                             : string.Empty, | ||||||
|                         Applications = result.Contains("role") && result["role"].IsBsonDocument && |                         Applications = result.Contains("role") && result["role"].IsBsonDocument && | ||||||
|                        result["role"].AsBsonDocument.Contains("applications") && |                        result["role"].AsBsonDocument.Contains("applications") && | ||||||
|                        result["role"]["applications"].IsBsonArray |                        result["role"]["applications"].IsBsonArray | ||||||
| @@ -490,12 +390,12 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|                             result["role"].AsBsonDocument.Contains("createdBy") && |                             result["role"].AsBsonDocument.Contains("createdBy") && | ||||||
|                             !result["role"]["createdBy"].IsBsonNull |                             !result["role"]["createdBy"].IsBsonNull | ||||||
|                             ? result["role"]["createdBy"].AsString |                             ? result["role"]["createdBy"].AsString | ||||||
|                             : "", |                             : string.Empty, | ||||||
|                         UpdatedBy = result.Contains("role") && result["role"].IsBsonDocument && |                         UpdatedBy = result.Contains("role") && result["role"].IsBsonDocument && | ||||||
|                             result["role"].AsBsonDocument.Contains("updatedBy") && |                             result["role"].AsBsonDocument.Contains("updatedBy") && | ||||||
|                             !result["role"]["updatedBy"].IsBsonNull |                             !result["role"]["updatedBy"].IsBsonNull | ||||||
|                             ? result["role"]["updatedBy"].AsString |                             ? result["role"]["updatedBy"].AsString | ||||||
|                             : "" |                             : string.Empty | ||||||
|                     }, |                     }, | ||||||
|                     Permissions = result.Contains("permissions") && result["permissions"].IsBsonArray |                     Permissions = result.Contains("permissions") && result["permissions"].IsBsonArray | ||||||
|                         ? result["permissions"].AsBsonArray |                         ? result["permissions"].AsBsonArray | ||||||
| @@ -517,12 +417,12 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Deletes an User by id. |         /// Deletes an User by _id. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="id">The User identifier.</param> |         /// <param name="_id">The User mongo identifier.</param> | ||||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing |         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         public async ValueTask<UserAdapter> DeleteUser(string _id, CancellationToken cancellationToken) |         public async ValueTask<UserAdapter?> DeleteUser(string _id, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var entity = await repository.DeleteOneAsync(doc => doc.Id == _id); |             var entity = await repository.DeleteOneAsync(doc => doc.Id == _id); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,16 +1,9 @@ | |||||||
| using Core.Blueprint.Mongo; | using Core.Blueprint.Mongo; | ||||||
| using Core.Thalos.Adapters; | using Core.Thalos.BuildingBlocks; | ||||||
| using Core.Thalos.Infraestructure.Caching.Contracts; |  | ||||||
| using Core.Thalos.Infraestructure.Contexts.Mongo; |  | ||||||
| using Core.Thalos.Provider.Contracts; | using Core.Thalos.Provider.Contracts; | ||||||
| using Core.Thalos.Provider.Providers; |  | ||||||
| using Core.Thalos.Provider.Providers.Onboarding; | using Core.Thalos.Provider.Providers.Onboarding; | ||||||
| using LSA.Core.Dapper.Service.Caching; |  | ||||||
| using Microsoft.Extensions.Configuration; | using Microsoft.Extensions.Configuration; | ||||||
| using Microsoft.Extensions.DependencyInjection; | using Microsoft.Extensions.DependencyInjection; | ||||||
| using Microsoft.Extensions.Logging; |  | ||||||
| using Microsoft.Extensions.Options; |  | ||||||
| using MongoDB.Driver; |  | ||||||
|  |  | ||||||
| namespace Core.Thalos.Provider | namespace Core.Thalos.Provider | ||||||
| { | { | ||||||
| @@ -31,33 +24,8 @@ namespace Core.Thalos.Provider | |||||||
|             services.AddScoped<IUserProvider, UserProvider>(); |             services.AddScoped<IUserProvider, UserProvider>(); | ||||||
|             services.AddScoped<CollectionRepository<UserAdapter>>(); |             services.AddScoped<CollectionRepository<UserAdapter>>(); | ||||||
|  |  | ||||||
|             return services; |             services.AddScoped<ITenantProvider, TenantProvider>(); | ||||||
|         } |             services.AddScoped<CollectionRepository<TenantAdapter>>(); | ||||||
|  |  | ||||||
|         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; |             return services; | ||||||
|         } |         } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user