Add project files.
This commit is contained in:
		
							
								
								
									
										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