Add project files.
This commit is contained in:
		| @@ -0,0 +1,19 @@ | ||||
| using Core.Cerberos.Adapters; | ||||
| using Core.Cerberos.Application.UseCases.Modules.Ports; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Modules.Adapter | ||||
| { | ||||
|     public class ModulePort : BasePresenter, IModulePort | ||||
|     { | ||||
|         public void Success(ModuleAdapter output) | ||||
|         { | ||||
|             ViewModel = new OkObjectResult(output); | ||||
|         } | ||||
|         public void Success(List<ModuleAdapter> output) | ||||
|         { | ||||
|             ViewModel = new OkObjectResult(output); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,16 @@ | ||||
| using Core.Cerberos.Adapters.Common.Enums; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Modules.Input | ||||
| { | ||||
|     public class ChangeModuleStatusRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Id { get; set; } | ||||
|         public StatusEnum Status { get; set; } | ||||
|  | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return Id != null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,20 @@ | ||||
| using Core.Cerberos.Adapters.Common.Enums; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Modules.Input | ||||
| { | ||||
|     public class CreateModuleRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Name { get; set; } = null!; | ||||
|         public string? Description { get; set; } | ||||
|         public string? Icon { get; set; } | ||||
|         public string? Route { get; set; } | ||||
|         public int? Order { get; set; } | ||||
|         public ApplicationsEnum? Application { get; set; } = null!; | ||||
|  | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return Name != null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,14 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Modules.Input | ||||
| { | ||||
|     public class GetAllModulesByListRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string[] Modules { get; set; } | ||||
|  | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return Modules != null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,12 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Modules.Input | ||||
| { | ||||
|     public class GetAllModulesRequest : ICommand | ||||
|     { | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return true; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,13 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Modules.Input | ||||
| { | ||||
|     public class GetModuleRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Id { get; set; } | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return Id != null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,21 @@ | ||||
| using Core.Cerberos.Adapters.Common.Enums; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Modules.Input | ||||
| { | ||||
|     public class UpdateModuleRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Id { get; set; } = null!; | ||||
|         public string Name { get; set; } = null!; | ||||
|         public string? Description { get; set; } | ||||
|         public string? Icon { get; set; } | ||||
|         public string Route { get; set; } = null!; | ||||
|         public int? Order { get; set; } | ||||
|         public ApplicationsEnum? Application { get; set; } = null!; | ||||
|         public StatusEnum Status { get; set; } | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return Id != null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										219
									
								
								Core.Cerberos.Application/UseCases/Modules/ModuleHandler.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										219
									
								
								Core.Cerberos.Application/UseCases/Modules/ModuleHandler.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,219 @@ | ||||
| using Core.Cerberos.Adapters; | ||||
| using Core.Cerberos.Application.UseCases.Modules.Input; | ||||
| using Core.Cerberos.Application.UseCases.Modules.Ports; | ||||
| using Core.Cerberos.External.Clients; | ||||
| using Core.Cerberos.External.Clients.Requests; | ||||
| using FluentValidation; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Lib.Architecture.BuildingBlocks.Helpers; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Modules | ||||
| { | ||||
|     public class ModuleHandler : | ||||
|         IComponentHandler<ChangeModuleStatusRequest>, | ||||
|         IComponentHandler<GetAllModulesRequest>, | ||||
|         IComponentHandler<GetAllModulesByListRequest>, | ||||
|         IComponentHandler<UpdateModuleRequest>, | ||||
|         IComponentHandler<GetModuleRequest>, | ||||
|         IComponentHandler<CreateModuleRequest> | ||||
|     { | ||||
|         private readonly IModulePort _port; | ||||
|         private readonly IValidator<ChangeModuleStatusRequest> _changeModuleStatusValidator; | ||||
|         private readonly IValidator<CreateModuleRequest> _registerModuleValidator; | ||||
|         private readonly IValidator<UpdateModuleRequest> _updateModuleValidator; | ||||
|         private readonly IValidator<GetAllModulesByListRequest> _modulesByListValidator; | ||||
|         private readonly ICerberosServiceClient _cerberosDALService; | ||||
|  | ||||
|         public ModuleHandler( | ||||
|             IModulePort port, | ||||
|             IValidator<ChangeModuleStatusRequest> changeModuleStatusValidator, | ||||
|             IValidator<CreateModuleRequest> registerModuleValidator, | ||||
|             IValidator<UpdateModuleRequest> updateModuleValidator, | ||||
|             IValidator<GetAllModulesByListRequest> modulesByListValidator, | ||||
|             ICerberosServiceClient cerberosDALService) | ||||
|         { | ||||
|             _port = port ?? throw new ArgumentNullException(nameof(port)); | ||||
|             _changeModuleStatusValidator = changeModuleStatusValidator ?? throw new ArgumentNullException(nameof(changeModuleStatusValidator)); | ||||
|             _registerModuleValidator = registerModuleValidator ?? throw new ArgumentNullException(nameof(registerModuleValidator)); | ||||
|             _updateModuleValidator = updateModuleValidator ?? throw new ArgumentNullException(nameof(updateModuleValidator)); | ||||
|             _cerberosDALService = cerberosDALService ?? throw new ArgumentNullException(nameof(cerberosDALService)); | ||||
|             _modulesByListValidator = modulesByListValidator ?? throw new ArgumentNullException(nameof(modulesByListValidator)); | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(GetModuleRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 var result = await _cerberosDALService.GetModuleByIdAsync(command.Id, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(GetAllModulesRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 var _result = await _cerberosDALService.GetAllModulesAsync().ConfigureAwait(false); | ||||
|                 if (!_result.Any()) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|                 _port.Success(_result.ToList()); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(GetAllModulesByListRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 if (!command.IsValid(_modulesByListValidator)) | ||||
|                 { | ||||
|                     _port.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 var _result = await _cerberosDALService.GetAllModulesByListAsync(command.Modules, cancellationToken).ConfigureAwait(false); | ||||
|                 if (!_result.Any()) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|                 _port.Success(_result.ToList()); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(ChangeModuleStatusRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 if (!command.IsValid(_changeModuleStatusValidator)) | ||||
|                 { | ||||
|                     _port.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 var result = await _cerberosDALService.ChangeStatusModuleAsync(command.Id, command.Status, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(CreateModuleRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 if (!command.IsValid(_registerModuleValidator)) | ||||
|                 { | ||||
|                     _port.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 var request = new ModuleRequest | ||||
|                 { | ||||
|                     Name = command.Name, | ||||
|                     Description = command.Description, | ||||
|                     Icon = command.Icon, | ||||
|                     Route = command.Route, | ||||
|                     Order = command.Order, | ||||
|                     Application = command.Application, | ||||
|                 }; | ||||
|  | ||||
|                 var result = await _cerberosDALService.CreateModuleAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(UpdateModuleRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 if (!command.IsValid(_updateModuleValidator)) | ||||
|                 { | ||||
|                     _port.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 var request = new ModuleAdapter | ||||
|                 { | ||||
|                     Id = command.Id, | ||||
|                     Name = command.Name, | ||||
|                     Description = command.Description, | ||||
|                     Application = command.Application, | ||||
|                     Route = command.Route, | ||||
|                     Order = command.Order, | ||||
|                     Icon = command.Icon, | ||||
|                     Status = command.Status | ||||
|                 }; | ||||
|  | ||||
|                 string id = command.Id; | ||||
|  | ||||
|                 var result = await _cerberosDALService.UpdateModuleAsync(request, id, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,13 @@ | ||||
| using Core.Cerberos.Adapters; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Modules.Ports | ||||
| { | ||||
|     public interface IModulePort : IBasePort, | ||||
|         ICommandSuccessPort<ModuleAdapter>, | ||||
|         ICommandSuccessPort<List<ModuleAdapter>>, | ||||
|         INoContentPort, IBusinessErrorPort, ITimeoutPort, IValidationErrorPort, | ||||
|         INotFoundPort, IForbiddenPort, IUnauthorizedPort, IInternalServerErrorPort | ||||
|     { | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,14 @@ | ||||
| using Core.Cerberos.Application.UseCases.Modules.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Modules.Validator | ||||
| { | ||||
|     public class ChangeModuleStatusValidator : AbstractValidator<ChangeModuleStatusRequest> | ||||
|     { | ||||
|         public ChangeModuleStatusValidator() | ||||
|         { | ||||
|             RuleFor(i => i.Id).NotEmpty().NotNull().OverridePropertyName(x => x.Id).WithName("Module ID").WithMessage("Module ID is Obligatory."); | ||||
|             RuleFor(i => i.Status).NotNull().OverridePropertyName(x => x.Status).WithName("Status").WithMessage("Status is Obligatory."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,15 @@ | ||||
| using Core.Cerberos.Application.UseCases.Modules.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Modules.Validator | ||||
| { | ||||
|     public class CreateModuleValidator : AbstractValidator<CreateModuleRequest> | ||||
|     { | ||||
|         public CreateModuleValidator() | ||||
|         { | ||||
|             RuleFor(i => i.Name).NotEmpty().NotNull().OverridePropertyName(x => x.Name).WithName("Module Name").WithMessage("Module Name is Obligatory."); | ||||
|             RuleFor(i => i.Route).NotEmpty().NotNull().OverridePropertyName(x => x.Route).WithName("Module Route").WithMessage("Module Route is Obligatory."); | ||||
|             RuleFor(i => i.Application).NotEmpty().NotNull().OverridePropertyName(x => x.Application).WithName("Application").WithMessage("Application is Obligatory."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,14 @@ | ||||
| using Core.Cerberos.Application.UseCases.Modules.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Modules.Validator | ||||
| { | ||||
|     public class GetAllModulesByListValidator : AbstractValidator<GetAllModulesByListRequest> | ||||
|     { | ||||
|         public GetAllModulesByListValidator() | ||||
|         { | ||||
|             RuleFor(i => i.Modules).NotEmpty().NotNull().OverridePropertyName(x => x.Modules).WithName("Modules").WithMessage("Modules are Obligatory."); | ||||
|         } | ||||
|  | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,15 @@ | ||||
| using Core.Cerberos.Application.UseCases.Modules.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Modules.Validator | ||||
| { | ||||
|     public class UpdateModuleValidator : AbstractValidator<UpdateModuleRequest> | ||||
|     { | ||||
|         public UpdateModuleValidator() | ||||
|         { | ||||
|             RuleFor(i => i.Name).NotEmpty().NotNull().OverridePropertyName(x => x.Name).WithName("Module Name").WithMessage("Module Name is Obligatory."); | ||||
|             RuleFor(i => i.Application).NotEmpty().NotNull().OverridePropertyName(x => x.Application).WithName("Application").WithMessage("Application is Obligatory."); | ||||
|             RuleFor(i => i.Route).NotEmpty().NotNull().OverridePropertyName(x => x.Route).WithName("Module Route").WithMessage("Module Route is Obligatory."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,19 @@ | ||||
| using Core.Cerberos.Adapters; | ||||
| using Core.Cerberos.Application.UseCases.Permissions.Ports; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Permissions.Adapter | ||||
| { | ||||
|     public class PermissionPort : BasePresenter, IPermissionPort | ||||
|     { | ||||
|         public void Success(PermissionAdapter output) | ||||
|         { | ||||
|             ViewModel = new OkObjectResult(output); | ||||
|         } | ||||
|         public void Success(List<PermissionAdapter> output) | ||||
|         { | ||||
|             ViewModel = new OkObjectResult(output); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,16 @@ | ||||
| using Core.Cerberos.Adapters.Common.Enums; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Permissions.Input | ||||
| { | ||||
|     public class ChangePermissionStatusRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Id { get; set; } | ||||
|         public StatusEnum Status { get; set; } | ||||
|  | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return Id != null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,17 @@ | ||||
| using Core.Cerberos.Adapters.Common.Constants; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Permissions.Input | ||||
| { | ||||
|     public class CreatePermissionRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Name { get; set; } = null!; | ||||
|         public string Description { get; set; } = null!; | ||||
|         public AccessLevelEnum? AccessLevel { get; set; } = null!; | ||||
|  | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return Name != null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,14 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Permissions.Input | ||||
| { | ||||
|     public class GetAllPermissionsByListRequest : ICommand | ||||
|     { | ||||
|         public string[]? Permissions { get; set; } | ||||
|  | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return Permissions != null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,12 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Permissions.Input | ||||
| { | ||||
|     public class GetAllPermissionsRequest : ICommand | ||||
|     { | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return true; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,13 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Permissions.Input | ||||
| { | ||||
|     public class GetPermissionRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Id { get; set; } | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return Id != null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,19 @@ | ||||
| using Core.Cerberos.Adapters.Common.Constants; | ||||
| using Core.Cerberos.Adapters.Common.Enums; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Permissions.Input | ||||
| { | ||||
|     public class UpdatePermissionRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Id { get; set; } = null!; | ||||
|         public string Name { get; set; } = null!; | ||||
|         public string? Description { get; set; } | ||||
|         public AccessLevelEnum? AccessLevel { get; set; } = null!; | ||||
|         public StatusEnum Status { get; set; } | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return Id != null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,204 @@ | ||||
| using Core.Cerberos.Adapters; | ||||
| using Core.Cerberos.Application.UseCases.Permissions.Input; | ||||
| using Core.Cerberos.Application.UseCases.Permissions.Ports; | ||||
| using Core.Cerberos.External.Clients; | ||||
| using Core.Cerberos.External.Clients.Requests; | ||||
| using FluentValidation; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Lib.Architecture.BuildingBlocks.Helpers; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Permissions | ||||
| { | ||||
|     public class PermissionHandler : | ||||
|         IComponentHandler<ChangePermissionStatusRequest>, | ||||
|         IComponentHandler<GetAllPermissionsRequest>, | ||||
|         IComponentHandler<GetAllPermissionsByListRequest>, | ||||
|         IComponentHandler<UpdatePermissionRequest>, | ||||
|         IComponentHandler<GetPermissionRequest>, | ||||
|         IComponentHandler<CreatePermissionRequest> | ||||
|     { | ||||
|         private readonly IPermissionPort _port; | ||||
|         private readonly IValidator<ChangePermissionStatusRequest> _changePermissionStatusValidator; | ||||
|         private readonly IValidator<CreatePermissionRequest> _registerPermissionValidator; | ||||
|         private readonly IValidator<UpdatePermissionRequest> _updatePermissionValidator; | ||||
|         private readonly ICerberosServiceClient _cerberosDALService; | ||||
|  | ||||
|         public PermissionHandler( | ||||
|             IPermissionPort port, | ||||
|             IValidator<ChangePermissionStatusRequest> changePermissionStatusValidator, | ||||
|             IValidator<CreatePermissionRequest> registerPermissionValidator, | ||||
|             IValidator<UpdatePermissionRequest> updatePermissionValidator, | ||||
|             ICerberosServiceClient cerberosDALService) | ||||
|         { | ||||
|             _port = port ?? throw new ArgumentNullException(nameof(port)); | ||||
|             _changePermissionStatusValidator = changePermissionStatusValidator ?? throw new ArgumentNullException(nameof(changePermissionStatusValidator)); | ||||
|             _registerPermissionValidator = registerPermissionValidator ?? throw new ArgumentNullException(nameof(registerPermissionValidator)); | ||||
|             _updatePermissionValidator = updatePermissionValidator ?? throw new ArgumentNullException(nameof(updatePermissionValidator)); | ||||
|             _cerberosDALService = cerberosDALService ?? throw new ArgumentNullException(nameof(cerberosDALService)); | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(GetPermissionRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 var result = await _cerberosDALService.GetPermissionByIdAsync(command.Id, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(GetAllPermissionsRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 var _result = await _cerberosDALService.GetAllPermissionsAsync().ConfigureAwait(false); | ||||
|                 if (!_result.Any()) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|                 _port.Success(_result.ToList()); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(GetAllPermissionsByListRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 var _result = await _cerberosDALService.GetAllPermissionsByListAsync(command.Permissions, cancellationToken).ConfigureAwait(false); | ||||
|                 if (!_result.Any()) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|                 _port.Success(_result.ToList()); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(ChangePermissionStatusRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 if (!command.IsValid(_changePermissionStatusValidator)) | ||||
|                 { | ||||
|                     _port.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 var result = await _cerberosDALService.ChangeStatusPermissionAsync(command.Id, command.Status, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(CreatePermissionRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 if (!command.IsValid(_registerPermissionValidator)) | ||||
|                 { | ||||
|                     _port.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 var request = new PermissionRequest | ||||
|                 { | ||||
|                     Name = command.Name, | ||||
|                     Description = command.Description, | ||||
|                     AccessLevel = command.AccessLevel | ||||
|                 }; | ||||
|  | ||||
|                 var result = await _cerberosDALService.CreatePermissionAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(UpdatePermissionRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 if (!command.IsValid(_updatePermissionValidator)) | ||||
|                 { | ||||
|                     _port.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 var request = new PermissionAdapter | ||||
|                 { | ||||
|                     Id = command.Id, | ||||
|                     Name = command.Name, | ||||
|                     Description = command.Description, | ||||
|                     AccessLevel = command.AccessLevel, | ||||
|                     Status = command.Status | ||||
|                 }; | ||||
|  | ||||
|                 string id = command.Id; | ||||
|  | ||||
|                 var result = await _cerberosDALService.UpdatePermissionAsync(request, id, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,13 @@ | ||||
| using Core.Cerberos.Adapters; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Permissions.Ports | ||||
| { | ||||
|     public interface IPermissionPort : IBasePort, | ||||
|         ICommandSuccessPort<PermissionAdapter>, | ||||
|         ICommandSuccessPort<List<PermissionAdapter>>, | ||||
|         INoContentPort, IBusinessErrorPort, ITimeoutPort, IValidationErrorPort, | ||||
|         INotFoundPort, IForbiddenPort, IUnauthorizedPort, IInternalServerErrorPort | ||||
|     { | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,15 @@ | ||||
| using Core.Cerberos.Application.UseCases.Permissions.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Permissions.Validator | ||||
| { | ||||
|     public class ChangePermissionStatusValidator : AbstractValidator<ChangePermissionStatusRequest> | ||||
|     { | ||||
|         public ChangePermissionStatusValidator() | ||||
|         { | ||||
|             RuleFor(i => i.Id).NotEmpty().NotNull().OverridePropertyName(x => x.Id).WithName("Permission ID").WithMessage("Permission ID is Obligatory."); | ||||
|             RuleFor(i => i.Status).NotNull().OverridePropertyName(x => x.Status).WithName("Status").WithMessage("Status is Obligatory."); | ||||
|         } | ||||
|  | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,15 @@ | ||||
| using Core.Cerberos.Application.UseCases.Permissions.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Permissions.Validator | ||||
| { | ||||
|     public class CreatePermissionValidator : AbstractValidator<CreatePermissionRequest> | ||||
|     { | ||||
|         public CreatePermissionValidator() | ||||
|         { | ||||
|             RuleFor(i => i.Name).NotEmpty().NotNull().OverridePropertyName(x => x.Name).WithName("Permission Name").WithMessage("Permission Name is Obligatory."); | ||||
|             RuleFor(i => i.Description).NotEmpty().NotNull().OverridePropertyName(x => x.Description).WithName("Permission Description").WithMessage("Permission Description is Obligatory."); | ||||
|             RuleFor(i => i.AccessLevel).NotEmpty().NotNull().OverridePropertyName(x => x.AccessLevel).WithName("AccesLevel").WithMessage("AccesLevel is Obligatory."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,14 @@ | ||||
| using Core.Cerberos.Application.UseCases.Permissions.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Permissions.Validator | ||||
| { | ||||
|     public class UpdatePermissionValidator : AbstractValidator<UpdatePermissionRequest> | ||||
|     { | ||||
|         public UpdatePermissionValidator() | ||||
|         { | ||||
|             RuleFor(i => i.Name).NotEmpty().NotNull().OverridePropertyName(x => x.Name).WithName("Permission Name").WithMessage("Permission Name is Obligatory."); | ||||
|             RuleFor(i => i.Description).NotEmpty().NotNull().OverridePropertyName(x => x.Description).WithName("Permission Description").WithMessage("Permission Description is Obligatory."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										19
									
								
								Core.Cerberos.Application/UseCases/Roles/Adapter/RolePort.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								Core.Cerberos.Application/UseCases/Roles/Adapter/RolePort.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,19 @@ | ||||
| using Core.Cerberos.Adapters; | ||||
| using Core.Cerberos.Application.UseCases.Roles.Ports; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Roles.Adapter | ||||
| { | ||||
|     public class RolePort : BasePresenter, IRolePort | ||||
|     { | ||||
|         public void Success(RoleAdapter output) | ||||
|         { | ||||
|             ViewModel = new OkObjectResult(output); | ||||
|         } | ||||
|         public void Success(List<RoleAdapter> output) | ||||
|         { | ||||
|             ViewModel = new OkObjectResult(output); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,15 @@ | ||||
| using Core.Cerberos.Adapters.Common.Enums; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Roles.Input | ||||
| { | ||||
|     public class AddApplicationToRoleRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string RoleId { get; set; } | ||||
|         public ApplicationsEnum Application { get; set; } | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return true; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,15 @@ | ||||
| using Core.Cerberos.Adapters.Common.Enums; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Roles.Input | ||||
| { | ||||
|     public class ChangeRoleStatusRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Id { get; set; } | ||||
|         public StatusEnum Status { get; set; } | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return Id != null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,22 @@ | ||||
| using Core.Cerberos.Adapters.Common.Enums; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using System.Text.Json.Serialization; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Roles.Input | ||||
| { | ||||
|     public class CreateRoleRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Name { get; set; } = null!; | ||||
|         public string Description { get; set; } = null!; | ||||
|  | ||||
|         [JsonConverter(typeof(EnumArrayJsonConverter<ApplicationsEnum>))] | ||||
|         public ApplicationsEnum[]? Applications { get; set; } = null!; | ||||
|         public string[] Modules { get; set; } = null!; | ||||
|         public string[] Permissions { get; set; } = null!; | ||||
|  | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return Name != null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,12 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Roles.Input | ||||
| { | ||||
|     public class GetAllRolesRequest : ICommand | ||||
|     { | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return true; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,13 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Roles.Input | ||||
| { | ||||
|     public class GetRoleRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Id { get; set; } | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return Id != null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,15 @@ | ||||
| using Core.Cerberos.Adapters.Common.Enums; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Roles.Input | ||||
| { | ||||
|     public class RemoveApplicationFromRoleRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string RoleId { get; set; } | ||||
|         public ApplicationsEnum Application { get; set; } | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return true; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,24 @@ | ||||
| using Core.Cerberos.Adapters.Common.Enums; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using System.Text.Json.Serialization; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Roles.Input | ||||
| { | ||||
|     public class UpdateRoleRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Id { get; set; } = null!; | ||||
|         public string Name { get; set; } = null!; | ||||
|         public string? Description { get; set; } | ||||
|  | ||||
|         [JsonConverter(typeof(EnumArrayJsonConverter<ApplicationsEnum>))] | ||||
|         public ApplicationsEnum[]? Applications { get; set; } | ||||
|         public string[] Modules { get; set; } = null!; | ||||
|         public string[] Permissions { get; set; } = null!; | ||||
|         public StatusEnum Status { get; set; } | ||||
|  | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return Id != null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										12
									
								
								Core.Cerberos.Application/UseCases/Roles/Ports/IRolePort.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								Core.Cerberos.Application/UseCases/Roles/Ports/IRolePort.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | ||||
| using Core.Cerberos.Adapters; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Roles.Ports | ||||
| { | ||||
|     public interface IRolePort : IBasePort, | ||||
|         ICommandSuccessPort<RoleAdapter>, ICommandSuccessPort<List<RoleAdapter>>, | ||||
|         INoContentPort, IBusinessErrorPort, ITimeoutPort, IValidationErrorPort, | ||||
|         INotFoundPort, IForbiddenPort, IUnauthorizedPort, IInternalServerErrorPort | ||||
|     { | ||||
|     } | ||||
| } | ||||
							
								
								
									
										235
									
								
								Core.Cerberos.Application/UseCases/Roles/RoleHandler.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										235
									
								
								Core.Cerberos.Application/UseCases/Roles/RoleHandler.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,235 @@ | ||||
| using Core.Cerberos.Adapters; | ||||
| using Core.Cerberos.Application.UseCases.Roles.Input; | ||||
| using Core.Cerberos.Application.UseCases.Roles.Ports; | ||||
| using Core.Cerberos.External.Clients; | ||||
| using Core.Cerberos.External.Clients.Requests; | ||||
| using FluentValidation; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Lib.Architecture.BuildingBlocks.Helpers; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Role | ||||
| { | ||||
|     public class RoleHandler : | ||||
|         IComponentHandler<ChangeRoleStatusRequest>, | ||||
|         IComponentHandler<GetAllRolesRequest>, | ||||
|         IComponentHandler<UpdateRoleRequest>, | ||||
|         IComponentHandler<CreateRoleRequest>, | ||||
|         IComponentHandler<GetRoleRequest>, | ||||
|         IComponentHandler<AddApplicationToRoleRequest>, | ||||
|         IComponentHandler<RemoveApplicationFromRoleRequest> | ||||
|  | ||||
|     { | ||||
|         private readonly IRolePort _port; | ||||
|         private readonly IValidator<ChangeRoleStatusRequest> _changeRoleStatusValidator; | ||||
|         private readonly IValidator<CreateRoleRequest> _registerRoleValidator; | ||||
|         private readonly IValidator<UpdateRoleRequest> _updateRoleValidator; | ||||
|         private readonly ICerberosServiceClient _cerberosDALService; | ||||
|  | ||||
|         public RoleHandler( | ||||
|             IRolePort port, | ||||
|             IValidator<ChangeRoleStatusRequest> changeRoleStatusValidator, | ||||
|             IValidator<CreateRoleRequest> registerRoleValidator, | ||||
|             IValidator<UpdateRoleRequest> updateRoleValidator, | ||||
|             ICerberosServiceClient cerberosDALService) | ||||
|         { | ||||
|             _port = port ?? throw new ArgumentNullException(nameof(port)); | ||||
|             _changeRoleStatusValidator = changeRoleStatusValidator ?? throw new ArgumentNullException(nameof(changeRoleStatusValidator)); | ||||
|             _registerRoleValidator = registerRoleValidator ?? throw new ArgumentNullException(nameof(registerRoleValidator)); | ||||
|             _updateRoleValidator = updateRoleValidator ?? throw new ArgumentNullException(nameof(updateRoleValidator)); | ||||
|             _cerberosDALService = cerberosDALService ?? throw new ArgumentNullException(nameof(cerberosDALService)); | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(GetRoleRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 var result = await _cerberosDALService.GetRoleByIdAsync(command.Id, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(GetAllRolesRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 var _result = await _cerberosDALService.GetAllRolesAsync().ConfigureAwait(false); | ||||
|                 if (!_result.Any()) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|                 _port.Success(_result.ToList()); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(ChangeRoleStatusRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 if (!command.IsValid(_changeRoleStatusValidator)) | ||||
|                 { | ||||
|                     _port.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 var result = await _cerberosDALService.ChangeRoleStatusAsync(command.Id, command.Status, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(CreateRoleRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 if (!command.IsValid(_registerRoleValidator)) | ||||
|                 { | ||||
|                     _port.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 var request = new RoleRequest | ||||
|                 { | ||||
|                     Name = command.Name, | ||||
|                     Description = command.Description, | ||||
|                     Applications = command.Applications, | ||||
|                     Modules = command.Modules, | ||||
|                     Permissions = command.Permissions | ||||
|  | ||||
|                 }; | ||||
|  | ||||
|                 var result = await _cerberosDALService.CreateRoleAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(UpdateRoleRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 if (!command.IsValid(_updateRoleValidator)) | ||||
|                 { | ||||
|                     _port.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 var request = new RoleAdapter | ||||
|                 { | ||||
|                     Id = command.Id, | ||||
|                     Name = command.Name, | ||||
|                     Description = command.Description, | ||||
|                     Applications = command.Applications, | ||||
|                     Modules = command.Modules, | ||||
|                     Permissions = command.Permissions, | ||||
|                     Status = command.Status | ||||
|                 }; | ||||
|  | ||||
|                 string id = command.Id; | ||||
|  | ||||
|                 var result = await _cerberosDALService.UpdateRoleAsync(request, id, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(AddApplicationToRoleRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 var result = await _cerberosDALService.AddApplicationToRoleAsync(command.RoleId, command.Application, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(RemoveApplicationFromRoleRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 var result = await _cerberosDALService.RemoveApplicationToRoleAsync(command.RoleId, command.Application, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,16 @@ | ||||
| using Core.Cerberos.Application.UseCases.Roles.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Roles.Validator | ||||
| { | ||||
|     public class ChangeRoleStatusValidator : AbstractValidator<ChangeRoleStatusRequest> | ||||
|     { | ||||
|         public ChangeRoleStatusValidator() | ||||
|         { | ||||
|             RuleFor(i => i.Id).NotEmpty().NotNull().OverridePropertyName(x => x.Id).WithName("Role ID").WithMessage("Role ID is Obligatory."); | ||||
|             RuleFor(i => i.Status).NotNull().OverridePropertyName(x => x.Status).WithName("Status").WithMessage("Status is Obligatory."); | ||||
|  | ||||
|         } | ||||
|  | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,16 @@ | ||||
| using Core.Cerberos.Application.UseCases.Roles.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Roles.Validator | ||||
| { | ||||
|     public class CreateRoleValidator : AbstractValidator<CreateRoleRequest> | ||||
|     { | ||||
|         public CreateRoleValidator() | ||||
|         { | ||||
|             RuleFor(i => i.Name).NotEmpty().NotNull().OverridePropertyName(x => x.Name).WithName("Role Name").WithMessage("Role Name is Obligatory."); | ||||
|             RuleFor(i => i.Description).NotEmpty().NotNull().OverridePropertyName(x => x.Description).WithName("Role Description").WithMessage("Role Description is Obligatory."); | ||||
|             RuleFor(i => i.Applications).NotNull().OverridePropertyName(x => x.Applications).WithName("AccesLevel").WithMessage("Role must have at least one application."); | ||||
|             RuleFor(i => i.Permissions).NotEmpty().NotNull().OverridePropertyName(x => x.Applications).WithName("Role permissions").WithMessage("Role Permissions are Obligatory."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,16 @@ | ||||
| using Core.Cerberos.Application.UseCases.Roles.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Roles.Validator | ||||
| { | ||||
|     public class UpdateRoleValidator : AbstractValidator<UpdateRoleRequest> | ||||
|     { | ||||
|         public UpdateRoleValidator() | ||||
|         { | ||||
|             RuleFor(i => i.Name).NotEmpty().NotNull().OverridePropertyName(x => x.Name).WithName("Role Name").WithMessage("Role Name is Obligatory."); | ||||
|             RuleFor(i => i.Description).NotEmpty().NotNull().OverridePropertyName(x => x.Description).WithName("Role Description").WithMessage("Role Description is Obligatory."); | ||||
|             RuleFor(i => i.Applications).NotEmpty().NotNull().OverridePropertyName(x => x.Applications).WithName("Role applications").WithMessage("Role Applications are Obligatory."); | ||||
|             RuleFor(i => i.Permissions).NotEmpty().NotNull().OverridePropertyName(x => x.Applications).WithName("Role permissions").WithMessage("Role Permissions are Obligatory."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										33
									
								
								Core.Cerberos.Application/UseCases/Users/Adapter/UserPort.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								Core.Cerberos.Application/UseCases/Users/Adapter/UserPort.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,33 @@ | ||||
| using Core.Blueprint.Storage.Adapters; | ||||
| using Core.Cerberos.Adapters; | ||||
| using Core.Cerberos.Application.UseCases.Users.Ports; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Users.Adapter | ||||
| { | ||||
|     public class UserPort : BasePresenter, IUserPort | ||||
|     { | ||||
|         public void Success(UserAdapter output) | ||||
|         { | ||||
|             ViewModel = new OkObjectResult(output); | ||||
|         } | ||||
|         public void Success(List<UserAdapter> output) | ||||
|         { | ||||
|             ViewModel = new OkObjectResult(output); | ||||
|         } | ||||
|  | ||||
|         public void Success(UserExistenceAdapter output) | ||||
|         { | ||||
|             ViewModel = new OkObjectResult(output); | ||||
|         } | ||||
|         public void Success(TokenAdapter output) | ||||
|         { | ||||
|             ViewModel = new OkObjectResult(output); | ||||
|         } | ||||
|         public void Success(BlobDownloadUriAdapter output) | ||||
|         { | ||||
|             ViewModel = new OkObjectResult(output); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,12 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Users.Input | ||||
| { | ||||
|     public class AcceptUserConsentFormRequest : ICommand | ||||
|     { | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return true; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,14 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Users.Input | ||||
| { | ||||
|     public class AddCompanyToUserRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string UserId { get; set; } | ||||
|         public string CompanyId { get; set; } | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return true; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,14 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Users.Input | ||||
| { | ||||
|     public class AddProjectToUserRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string UserId { get; set; } | ||||
|         public string ProjectId { get; set; } | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return true; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,16 @@ | ||||
| using Core.Cerberos.Adapters.Common.Enums; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Users.Input | ||||
| { | ||||
|     public class ChangeUserStatusRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Id { get; set; } | ||||
|         public StatusEnum Status { get; set; } | ||||
|  | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return Id != null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,21 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Users.Input | ||||
| { | ||||
|     public class CreateUserRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Email { get; set; } = null!; | ||||
|         public string Name { get; set; } = null!; | ||||
|         public string MiddleName { get; set; } = null!; | ||||
|         public string LastName { get; set; } = null!; | ||||
|         public string RoleId { get; set; } = null!; | ||||
|         public string[] Companies { get; set; } = null!; | ||||
|         public string[]? Projects { get; set; } | ||||
|         public bool SendInvitation { get; set; } | ||||
|  | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return Name != null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,12 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Users.Input | ||||
| { | ||||
|     public class GetAllUsersRequest : ICommand | ||||
|     { | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return true; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,12 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Users.Input | ||||
| { | ||||
|     public class GetConsentFormPDFRequest : ICommand | ||||
|     { | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return true; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,13 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Users.Input | ||||
| { | ||||
|     public class GetTokenAdapterRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Email { get; set; } | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return Email != null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,13 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Users.Input | ||||
| { | ||||
|     public class GetUserByEmailRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Email { get; set; } | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return Email != null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,13 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Users.Input | ||||
| { | ||||
|     public class GetUserRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Id { get; set; } | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return Id != null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,13 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Users.Input | ||||
| { | ||||
|     public class LoginUserRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Email { get; set; } | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return Email != null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,13 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Users.Input | ||||
| { | ||||
|     public class LogoutUserRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Email { get; set; } | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return Email != null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,14 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Users.Input | ||||
| { | ||||
|     public class RemoveCompanyFromUserRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string UserId { get; set; } | ||||
|         public string CompanyId { get; set; } | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return true; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,14 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Users.Input | ||||
| { | ||||
|     public class RemoveProjectFromUserRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string UserId { get; set; } | ||||
|         public string ProjectId { get; set; } | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return true; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,20 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Users.Input | ||||
| { | ||||
|     public class UpdateUserRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Id { get; set; } = null!; | ||||
|         public string Email { get; set; } = null!; | ||||
|         public string Name { get; set; } = null!; | ||||
|         public string? MiddleName { get; set; } | ||||
|         public string LastName { get; set; } = null!; | ||||
|         public string RoleId { get; set; } = null!; | ||||
|         public string[] Companies { get; set; } = null!; | ||||
|         public string[]? Projects { get; set; } | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return Email != null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,13 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Users.Input | ||||
| { | ||||
|     public class ValidateUserExistenceRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Email { get; set; } | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return Email != null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										17
									
								
								Core.Cerberos.Application/UseCases/Users/Ports/IUserPort.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								Core.Cerberos.Application/UseCases/Users/Ports/IUserPort.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,17 @@ | ||||
| using Core.Blueprint.Storage.Adapters; | ||||
| using Core.Cerberos.Adapters; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Users.Ports | ||||
| { | ||||
|     public interface IUserPort : IBasePort, | ||||
|         ICommandSuccessPort<UserAdapter>, | ||||
|         ICommandSuccessPort<UserExistenceAdapter>, | ||||
|         ICommandSuccessPort<List<UserAdapter>>, | ||||
|         ICommandSuccessPort<TokenAdapter>, | ||||
|         ICommandSuccessPort<BlobDownloadUriAdapter>, | ||||
|         INoContentPort, IBusinessErrorPort, ITimeoutPort, IValidationErrorPort, | ||||
|         INotFoundPort, IForbiddenPort, IUnauthorizedPort, IInternalServerErrorPort | ||||
|     { | ||||
|     } | ||||
| } | ||||
							
								
								
									
										439
									
								
								Core.Cerberos.Application/UseCases/Users/UserHandler.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										439
									
								
								Core.Cerberos.Application/UseCases/Users/UserHandler.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,439 @@ | ||||
| using Core.Cerberos.Adapters; | ||||
| using Core.Cerberos.Application.UseCases.Users.Input; | ||||
| using Core.Cerberos.Application.UseCases.Users.Ports; | ||||
| using Core.Cerberos.External.Clients; | ||||
| using Core.Cerberos.External.Clients.Requests; | ||||
| using FluentValidation; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Lib.Architecture.BuildingBlocks.Helpers; | ||||
| namespace Core.Cerberos.Application.UseCases.Users | ||||
| { | ||||
|     public class UserHandler : | ||||
|         IComponentHandler<ChangeUserStatusRequest>, | ||||
|         IComponentHandler<GetAllUsersRequest>, | ||||
|         IComponentHandler<UpdateUserRequest>, | ||||
|         IComponentHandler<GetUserRequest>, | ||||
|         IComponentHandler<GetUserByEmailRequest>, | ||||
|         IComponentHandler<CreateUserRequest>, | ||||
|         IComponentHandler<AddProjectToUserRequest>, | ||||
|         IComponentHandler<RemoveProjectFromUserRequest>, | ||||
|         IComponentHandler<AddCompanyToUserRequest>, | ||||
|         IComponentHandler<RemoveCompanyFromUserRequest>, | ||||
|         IComponentHandler<LoginUserRequest>, | ||||
|         IComponentHandler<LogoutUserRequest>, | ||||
|         IComponentHandler<ValidateUserExistenceRequest>, | ||||
|         IComponentHandler<GetTokenAdapterRequest>, | ||||
|         IComponentHandler<GetConsentFormPDFRequest>, | ||||
|         IComponentHandler<AcceptUserConsentFormRequest> | ||||
|     { | ||||
|         private readonly IUserPort _port; | ||||
|         private readonly IValidator<ChangeUserStatusRequest> _changeUserStatusValidator; | ||||
|         private readonly IValidator<CreateUserRequest> _registerUserValidator; | ||||
|         private readonly IValidator<UpdateUserRequest> _updateUserValidator; | ||||
|         private readonly ICerberosServiceClient _cerberosDALService; | ||||
|  | ||||
|         public UserHandler( | ||||
|             IUserPort port, | ||||
|             IValidator<ChangeUserStatusRequest> changeUserStatusValidator, | ||||
|             IValidator<CreateUserRequest> registerUserValidator, | ||||
|             IValidator<UpdateUserRequest> updateUserValidator, | ||||
|             ICerberosServiceClient cerberosDALService) | ||||
|         { | ||||
|             _port = port ?? throw new ArgumentNullException(nameof(port)); | ||||
|             _changeUserStatusValidator = changeUserStatusValidator ?? throw new ArgumentNullException(nameof(changeUserStatusValidator)); | ||||
|             _registerUserValidator = registerUserValidator ?? throw new ArgumentNullException(nameof(registerUserValidator)); | ||||
|             _updateUserValidator = updateUserValidator ?? throw new ArgumentNullException(nameof(updateUserValidator)); | ||||
|             _cerberosDALService = cerberosDALService ?? throw new ArgumentNullException(nameof(cerberosDALService)); | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(GetUserRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 var result = await _cerberosDALService.GetUserByIdAsync(command.Id, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(GetUserByEmailRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 var result = await _cerberosDALService.GetUserByEmailAsync(command.Email, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(ValidateUserExistenceRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 var result = await _cerberosDALService.ValidateUserExistence(command.Email, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(GetAllUsersRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 var _result = await _cerberosDALService.GetAllUsersAsync().ConfigureAwait(false); | ||||
|                 if (!_result.Any()) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|                 _port.Success(_result.ToList()); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(ChangeUserStatusRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 if (!command.IsValid(_changeUserStatusValidator)) | ||||
|                 { | ||||
|                     _port.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 var result = await _cerberosDALService.ChangeUserStatusAsync(command.Id, command.Status, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(CreateUserRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 if (!command.IsValid(_registerUserValidator)) | ||||
|                 { | ||||
|                     _port.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 var request = new UserRequest | ||||
|                 { | ||||
|                     Email = command.Email, | ||||
|                     Name = command.Name, | ||||
|                     MiddleName = command.MiddleName, | ||||
|                     LastName = command.LastName, | ||||
|                     RoleId = command.RoleId, | ||||
|                     Companies = command.Companies, | ||||
|                     Projects = command.Projects, | ||||
|                 }; | ||||
|  | ||||
|                 var result = await _cerberosDALService.CreateUserAsync(request, command.SendInvitation, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(UpdateUserRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 if (!command.IsValid(_updateUserValidator)) | ||||
|                 { | ||||
|                     _port.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 var request = new UserAdapter | ||||
|                 { | ||||
|                     Id = command.Id, | ||||
|                     Email = command.Email, | ||||
|                     Name = command.Name, | ||||
|                     MiddleName = command.MiddleName, | ||||
|                     LastName = command.LastName, | ||||
|                     RoleId = command.RoleId, | ||||
|                     Companies = command.Companies, | ||||
|                     Projects = command.Projects | ||||
|                 }; | ||||
|  | ||||
|                 var result = await _cerberosDALService.UpdateUserAsync(request, request.Id, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(LoginUserRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 var result = await _cerberosDALService.LoginUserAsync(command.Email, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(LogoutUserRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 var result = await _cerberosDALService.LogoutUserAsync(command.Email, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(AddCompanyToUserRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 var result = await _cerberosDALService.AddCompanyToUserAsync(command.UserId, command.CompanyId, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(RemoveCompanyFromUserRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 var result = await _cerberosDALService.RemoveCompanyToUserAsync(command.UserId, command.CompanyId, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(AddProjectToUserRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 var result = await _cerberosDALService.AddProjectToUserAsync(command.UserId, command.ProjectId, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(RemoveProjectFromUserRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 var result = await _cerberosDALService.RemoveProjectToUserAsync(command.UserId, command.ProjectId, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(GetTokenAdapterRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 var result = await _cerberosDALService.GetTokenAdapter(command.Email, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(GetConsentFormPDFRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 var _result = await _cerberosDALService.GetConsentFormPDFAsync(cancellationToken).ConfigureAwait(false); | ||||
|                 if (_result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|                 _port.Success(_result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(AcceptUserConsentFormRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 var result = await _cerberosDALService.AcceptUserConsentFormAsync(cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,15 @@ | ||||
| using Core.Cerberos.Application.UseCases.Users.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Users.Validator | ||||
| { | ||||
|     public class ChangeUserStatusValidator : AbstractValidator<ChangeUserStatusRequest> | ||||
|     { | ||||
|         public ChangeUserStatusValidator() | ||||
|         { | ||||
|             RuleFor(i => i.Id).NotEmpty().NotNull().OverridePropertyName(x => x.Id).WithName("User ID").WithMessage("User ID is Obligatory."); | ||||
|             RuleFor(i => i.Status).NotNull().NotNull().OverridePropertyName(x => x.Status).WithName("Status").WithMessage("Status is Obligatory."); | ||||
|         } | ||||
|  | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,17 @@ | ||||
| using Core.Cerberos.Application.UseCases.Users.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Users.Validator | ||||
| { | ||||
|     public class CreateUserValidator : AbstractValidator<CreateUserRequest> | ||||
|     { | ||||
|         public CreateUserValidator() | ||||
|         { | ||||
|             RuleFor(i => i.Email).NotEmpty().NotNull().OverridePropertyName(x => x.Email).WithName("User Email").WithMessage("Email is Obligatory."); | ||||
|             RuleFor(i => i.Name).NotEmpty().NotNull().OverridePropertyName(x => x.Name).WithName("User Name").WithMessage("User Name is Obligatory."); | ||||
|             RuleFor(i => i.LastName).NotEmpty().NotNull().OverridePropertyName(x => x.LastName).WithName("User LastName").WithMessage("User LastName is Obligatory."); | ||||
|             RuleFor(i => i.RoleId).NotEmpty().NotNull().OverridePropertyName(x => x.RoleId).WithName("Role Id").WithMessage("Role Id is Obligatory."); | ||||
|             RuleFor(i => i.Companies).NotEmpty().NotNull().OverridePropertyName(x => x.Companies).WithName("Companies").WithMessage("Companies is Obligatory."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,17 @@ | ||||
| using Core.Cerberos.Application.UseCases.Users.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Cerberos.Application.UseCases.Users.Validator | ||||
| { | ||||
|     public class UpdateUserValidator : AbstractValidator<UpdateUserRequest> | ||||
|     { | ||||
|         public UpdateUserValidator() | ||||
|         { | ||||
|             RuleFor(i => i.Email).NotEmpty().NotNull().OverridePropertyName(x => x.Email).WithName("User Email").WithMessage("Email is Obligatory."); | ||||
|             RuleFor(i => i.Name).NotEmpty().NotNull().OverridePropertyName(x => x.Name).WithName("User Name").WithMessage("User Name is Obligatory."); | ||||
|             RuleFor(i => i.LastName).NotEmpty().NotNull().OverridePropertyName(x => x.LastName).WithName("User LastName").WithMessage("User LastName is Obligatory."); | ||||
|             RuleFor(i => i.RoleId).NotEmpty().NotNull().OverridePropertyName(x => x.RoleId).WithName("Role Id").WithMessage("Role Id is Obligatory."); | ||||
|             RuleFor(i => i.Companies).NotEmpty().NotNull().OverridePropertyName(x => x.Companies).WithName("Companies").WithMessage("Companies is Obligatory."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Sergio Matias Urquin
					Sergio Matias Urquin