remove cerberos by thalos
This commit is contained in:
		
							
								
								
									
										19
									
								
								Core.Thalos.Application/UseCases/Roles/Adapter/RolePort.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								Core.Thalos.Application/UseCases/Roles/Adapter/RolePort.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,19 @@ | ||||
| using Core.Thalos.Adapters; | ||||
| using Core.Thalos.Application.UseCases.Roles.Ports; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
|  | ||||
| namespace Core.Thalos.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.Thalos.Adapters.Common.Enums; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Thalos.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.Thalos.Adapters.Common.Enums; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Thalos.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.Thalos.Adapters.Common.Enums; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using System.Text.Json.Serialization; | ||||
|  | ||||
| namespace Core.Thalos.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.Thalos.Application.UseCases.Roles.Input | ||||
| { | ||||
|     public class GetAllRolesRequest : ICommand | ||||
|     { | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return true; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,13 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Thalos.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.Thalos.Adapters.Common.Enums; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Thalos.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.Thalos.Adapters.Common.Enums; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using System.Text.Json.Serialization; | ||||
|  | ||||
| namespace Core.Thalos.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; | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										13
									
								
								Core.Thalos.Application/UseCases/Roles/Ports/IRolePort.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								Core.Thalos.Application/UseCases/Roles/Ports/IRolePort.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | ||||
| using Core.Thalos.Adapters; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Thalos.Application.UseCases.Roles.Ports | ||||
| { | ||||
|     public interface IRolePort : IBasePort, | ||||
|         ICommandSuccessPort<RoleAdapter>, ICommandSuccessPort<List<RoleAdapter>>, | ||||
|         INoContentPort, IBusinessErrorPort, ITimeoutPort, IValidationErrorPort, | ||||
|         INotFoundPort, IForbiddenPort, IUnauthorizedPort, IInternalServerErrorPort, | ||||
|         IBadRequestPort | ||||
|     { | ||||
|     } | ||||
| } | ||||
							
								
								
									
										235
									
								
								Core.Thalos.Application/UseCases/Roles/RoleHandler.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										235
									
								
								Core.Thalos.Application/UseCases/Roles/RoleHandler.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,235 @@ | ||||
| using Core.Thalos.Adapters; | ||||
| using Core.Thalos.Application.UseCases.Roles.Input; | ||||
| using Core.Thalos.Application.UseCases.Roles.Ports; | ||||
| using Core.Thalos.External.Clients; | ||||
| using Core.Thalos.External.Clients.Requests; | ||||
| using FluentValidation; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Lib.Architecture.BuildingBlocks.Helpers; | ||||
|  | ||||
| namespace Core.Thalos.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 IThalosServiceClient _thalosDALService; | ||||
|  | ||||
|         public RoleHandler( | ||||
|             IRolePort port, | ||||
|             IValidator<ChangeRoleStatusRequest> changeRoleStatusValidator, | ||||
|             IValidator<CreateRoleRequest> registerRoleValidator, | ||||
|             IValidator<UpdateRoleRequest> updateRoleValidator, | ||||
|             IThalosServiceClient thalosDALService) | ||||
|         { | ||||
|             _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)); | ||||
|             _thalosDALService = thalosDALService ?? throw new ArgumentNullException(nameof(thalosDALService)); | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(GetRoleRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 var result = await _thalosDALService.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 _thalosDALService.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 _thalosDALService.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 _thalosDALService.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 _thalosDALService.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 _thalosDALService.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 _thalosDALService.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.Thalos.Application.UseCases.Roles.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Thalos.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.Thalos.Application.UseCases.Roles.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Thalos.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.Thalos.Application.UseCases.Roles.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Thalos.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."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Sergio Matias Urquin
					Sergio Matias Urquin