Use Blueprint.Mongo package in module service
This commit is contained in:
		| @@ -5,14 +5,15 @@ | ||||
| // *********************************************************************** | ||||
|  | ||||
| using Asp.Versioning; | ||||
| using Core.Blueprint.Mongo; | ||||
| using Core.Thalos.Adapters; | ||||
| 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.Provider.Contracts; | ||||
| using Microsoft.AspNetCore.Authorization; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
| using Microsoft.Graph; | ||||
| using ModuleRequest = Core.Thalos.Domain.Contexts.Onboarding.Request.ModuleRequest; | ||||
|  | ||||
| namespace LSA.Core.Kerberos.API.Controllers | ||||
| { | ||||
| @@ -24,7 +25,7 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|     [Produces(MimeTypes.ApplicationJson)] | ||||
|     [Consumes(MimeTypes.ApplicationJson)] | ||||
|     [ApiController] | ||||
|     public class ModuleController(IModuleService service, ILogger<ModuleController> logger) : ControllerBase | ||||
|     public class ModuleController(IModuleProvider service) : ControllerBase | ||||
|     { | ||||
|         /// <summary> | ||||
|         /// Gets all the modules. | ||||
| @@ -39,19 +40,10 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|         [ProducesResponseType(typeof(IEnumerable<ModuleAdapter>), StatusCodes.Status200OK)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         [Permission("ModuleManagement.Read, RoleManagement.Read")] | ||||
|         public async Task<IActionResult> GetAllModulesAsync() | ||||
|         public async Task<IActionResult> GetAllModulesAsync(CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var result = await service.GetAllModulesService(); | ||||
|  | ||||
|                 return Ok(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError(ex, "Error in GetAllModulesAsync"); | ||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); | ||||
|             } | ||||
|             var result = await service.GetAllModules(cancellationToken).ConfigureAwait(false); | ||||
|             return Ok(result); | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
| @@ -69,29 +61,15 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|         [ProducesResponseType(typeof(IEnumerable<ModuleAdapter>), StatusCodes.Status200OK)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         [Permission("ModuleManagement.Read")] | ||||
|         public async Task<IActionResult> GetAllModulesByList([FromBody] string[] modules) | ||||
|         public async Task<IActionResult> GetAllModulesByList([FromBody] string[] modules, CancellationToken cancellationToken) | ||||
|         { | ||||
|             if (modules == null || !modules.Any()) | ||||
|             { | ||||
|                 return BadRequest("Module identifiers are required."); | ||||
|             } | ||||
|  | ||||
|             try | ||||
|             { | ||||
|                 var result = await service.GetAllModulesByListService(modules); | ||||
|  | ||||
|                 if (result == null || !result.Any()) | ||||
|                 { | ||||
|                     return NotFound("No modules found for the given identifiers."); | ||||
|                 } | ||||
|  | ||||
|                 return Ok(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError(ex, "Error in GetAllModulesByList"); | ||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); | ||||
|             } | ||||
|             var result = await service.GetAllModulesByList(modules, cancellationToken).ConfigureAwait(false); | ||||
|             return Ok(result); | ||||
|         } | ||||
|  | ||||
|  | ||||
| @@ -110,21 +88,16 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         [Permission("ModuleManagement.Read")] | ||||
|         public async Task<IActionResult> GetModuleByIdAsync([FromRoute] string id) | ||||
|         public async Task<IActionResult> GetModuleByIdAsync([FromRoute] string _id, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var result = await service.GetModuleByIdService(id); | ||||
|             var result = await service.GetModuleById(_id, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result is null) return NotFound($"module with id: '{id}' not found"); | ||||
|  | ||||
|                 return Ok(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             if (result == null) | ||||
|             { | ||||
|                 logger.LogError(ex, "Error in GetModuleByIdAsync"); | ||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); | ||||
|                 return NotFound("Entity not found"); | ||||
|             } | ||||
|  | ||||
|             return Ok(result); | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
| @@ -139,18 +112,10 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status201Created)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         [Permission("ModuleManagement.Write")] | ||||
|         public async Task<IActionResult> CreateModuleAsync([FromBody] ModuleRequest newModule) | ||||
|         public async Task<IActionResult> CreateModuleAsync([FromBody] ModuleRequest newModule, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var result = await service.CreateModuleService(newModule).ConfigureAwait(false); | ||||
|                 return Created("CreatedWithIdService", result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError(ex, "Error in CreateModuleAsync"); | ||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); | ||||
|             } | ||||
|             var result = await service.CreateModule(newModule, cancellationToken).ConfigureAwait(false); | ||||
|             return Created("CreatedWithIdAsync", result); | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
| @@ -170,19 +135,16 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         [Permission("ModuleManagement.Write")] | ||||
|         public async Task<IActionResult> UpdateModuleAsync(ModuleAdapter entity, string id) | ||||
|         public async Task<IActionResult> UpdateModuleAsync([FromRoute] string _id, ModuleAdapter entity, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             if (_id != entity._Id?.ToString()) | ||||
|             { | ||||
|                 var result = await service.UpdateModuleService(entity, id); | ||||
|                 return BadRequest("User ID mismatch"); | ||||
|             } | ||||
|  | ||||
|                 return Ok(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError(ex, "Error in UpdateModuleAsync"); | ||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); | ||||
|             } | ||||
|             var result = await service.UpdateModule(entity, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return Ok(result); | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
| @@ -202,19 +164,10 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         [Permission("ModuleManagement.Write")] | ||||
|         public async Task<IActionResult> ChangeModuleStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus) | ||||
|         public async Task<IActionResult> ChangeModuleStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var result = await service.ChangeModuleStatusService(id, newStatus); | ||||
|  | ||||
|                 return Ok(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError(ex, "Error in ChangeModuleStatus"); | ||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); | ||||
|             } | ||||
|             var result = await service.ChangeModuleStatus(id, newStatus, cancellationToken).ConfigureAwait(false); | ||||
|             return Ok(result); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Oscar Morales
					Oscar Morales