remove cerberos by thalos

This commit is contained in:
Sergio Matias Urquin
2025-05-18 19:23:42 -06:00
parent 46ebccf797
commit 82ebe4408b
88 changed files with 301 additions and 301 deletions

View File

@@ -0,0 +1,19 @@
using Core.Thalos.Adapters;
using Core.Thalos.Application.UseCases.Modules.Ports;
using Lib.Architecture.BuildingBlocks;
using Microsoft.AspNetCore.Mvc;
namespace Core.Thalos.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);
}
}
}

View File

@@ -0,0 +1,16 @@
using Core.Thalos.Adapters.Common.Enums;
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.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;
}
}
}

View File

@@ -0,0 +1,20 @@
using Core.Thalos.Adapters.Common.Enums;
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.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;
}
}
}

View File

@@ -0,0 +1,14 @@
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.Application.UseCases.Modules.Input
{
public class GetAllModulesByListRequest : Notificator, ICommand
{
public string[] Modules { get; set; }
public bool Validate()
{
return Modules != null;
}
}
}

View File

@@ -0,0 +1,12 @@
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.Application.UseCases.Modules.Input
{
public class GetAllModulesRequest : ICommand
{
public bool Validate()
{
return true;
}
}
}

View File

@@ -0,0 +1,13 @@
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.Application.UseCases.Modules.Input
{
public class GetModuleRequest : Notificator, ICommand
{
public string Id { get; set; }
public bool Validate()
{
return Id != null;
}
}
}

View File

@@ -0,0 +1,21 @@
using Core.Thalos.Adapters.Common.Enums;
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.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;
}
}
}

View File

@@ -0,0 +1,219 @@
using Core.Thalos.Adapters;
using Core.Thalos.Application.UseCases.Modules.Input;
using Core.Thalos.Application.UseCases.Modules.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.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 IThalosServiceClient _thalosDALService;
public ModuleHandler(
IModulePort port,
IValidator<ChangeModuleStatusRequest> changeModuleStatusValidator,
IValidator<CreateModuleRequest> registerModuleValidator,
IValidator<UpdateModuleRequest> updateModuleValidator,
IValidator<GetAllModulesByListRequest> modulesByListValidator,
IThalosServiceClient thalosDALService)
{
_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));
_thalosDALService = thalosDALService ?? throw new ArgumentNullException(nameof(thalosDALService));
_modulesByListValidator = modulesByListValidator ?? throw new ArgumentNullException(nameof(modulesByListValidator));
}
public async ValueTask ExecuteAsync(GetModuleRequest command, CancellationToken cancellationToken = default)
{
try
{
ArgumentNullException.ThrowIfNull(command);
var result = await _thalosDALService.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 _thalosDALService.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 _thalosDALService.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 _thalosDALService.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 _thalosDALService.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 _thalosDALService.UpdateModuleAsync(request, id, cancellationToken).ConfigureAwait(false);
if (result == null)
{
_port.NoContentSuccess();
return;
}
_port.Success(result);
}
catch (Exception ex)
{
ApiResponseHelper.EvaluatePort(ex, _port);
}
}
}
}

View File

@@ -0,0 +1,14 @@
using Core.Thalos.Adapters;
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.Application.UseCases.Modules.Ports
{
public interface IModulePort : IBasePort,
ICommandSuccessPort<ModuleAdapter>,
ICommandSuccessPort<List<ModuleAdapter>>,
INoContentPort, IBusinessErrorPort, ITimeoutPort, IValidationErrorPort,
INotFoundPort, IForbiddenPort, IUnauthorizedPort, IInternalServerErrorPort,
IBadRequestPort
{
}
}

View File

@@ -0,0 +1,14 @@
using Core.Thalos.Application.UseCases.Modules.Input;
using FluentValidation;
namespace Core.Thalos.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.");
}
}
}

View File

@@ -0,0 +1,15 @@
using Core.Thalos.Application.UseCases.Modules.Input;
using FluentValidation;
namespace Core.Thalos.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.");
}
}
}

View File

@@ -0,0 +1,14 @@
using Core.Thalos.Application.UseCases.Modules.Input;
using FluentValidation;
namespace Core.Thalos.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.");
}
}
}

View File

@@ -0,0 +1,15 @@
using Core.Thalos.Application.UseCases.Modules.Input;
using FluentValidation;
namespace Core.Thalos.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.");
}
}
}

View File

@@ -0,0 +1,19 @@
using Core.Thalos.Adapters;
using Core.Thalos.Application.UseCases.Permissions.Ports;
using Lib.Architecture.BuildingBlocks;
using Microsoft.AspNetCore.Mvc;
namespace Core.Thalos.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);
}
}
}

View File

@@ -0,0 +1,16 @@
using Core.Thalos.Adapters.Common.Enums;
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.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;
}
}
}

View File

@@ -0,0 +1,17 @@
using Core.Thalos.Adapters.Common.Constants;
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.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;
}
}
}

View File

@@ -0,0 +1,14 @@
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.Application.UseCases.Permissions.Input
{
public class GetAllPermissionsByListRequest : ICommand
{
public string[]? Permissions { get; set; }
public bool Validate()
{
return Permissions != null;
}
}
}

View File

@@ -0,0 +1,12 @@
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.Application.UseCases.Permissions.Input
{
public class GetAllPermissionsRequest : ICommand
{
public bool Validate()
{
return true;
}
}
}

View File

@@ -0,0 +1,13 @@
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.Application.UseCases.Permissions.Input
{
public class GetPermissionRequest : Notificator, ICommand
{
public string Id { get; set; }
public bool Validate()
{
return Id != null;
}
}
}

View File

@@ -0,0 +1,19 @@
using Core.Thalos.Adapters.Common.Constants;
using Core.Thalos.Adapters.Common.Enums;
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.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;
}
}
}

View File

@@ -0,0 +1,204 @@
using Core.Thalos.Adapters;
using Core.Thalos.Application.UseCases.Permissions.Input;
using Core.Thalos.Application.UseCases.Permissions.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.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 IThalosServiceClient _thalosDALService;
public PermissionHandler(
IPermissionPort port,
IValidator<ChangePermissionStatusRequest> changePermissionStatusValidator,
IValidator<CreatePermissionRequest> registerPermissionValidator,
IValidator<UpdatePermissionRequest> updatePermissionValidator,
IThalosServiceClient thalosDALService)
{
_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));
_thalosDALService = thalosDALService ?? throw new ArgumentNullException(nameof(thalosDALService));
}
public async ValueTask ExecuteAsync(GetPermissionRequest command, CancellationToken cancellationToken = default)
{
try
{
ArgumentNullException.ThrowIfNull(command);
var result = await _thalosDALService.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 _thalosDALService.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 _thalosDALService.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 _thalosDALService.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 _thalosDALService.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 _thalosDALService.UpdatePermissionAsync(request, id, cancellationToken).ConfigureAwait(false);
if (result == null)
{
_port.NoContentSuccess();
return;
}
_port.Success(result);
}
catch (Exception ex)
{
ApiResponseHelper.EvaluatePort(ex, _port);
}
}
}
}

View File

@@ -0,0 +1,14 @@
using Core.Thalos.Adapters;
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.Application.UseCases.Permissions.Ports
{
public interface IPermissionPort : IBasePort,
ICommandSuccessPort<PermissionAdapter>,
ICommandSuccessPort<List<PermissionAdapter>>,
INoContentPort, IBusinessErrorPort, ITimeoutPort, IValidationErrorPort,
INotFoundPort, IForbiddenPort, IUnauthorizedPort, IInternalServerErrorPort,
IBadRequestPort
{
}
}

View File

@@ -0,0 +1,15 @@
using Core.Thalos.Application.UseCases.Permissions.Input;
using FluentValidation;
namespace Core.Thalos.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.");
}
}
}

View File

@@ -0,0 +1,15 @@
using Core.Thalos.Application.UseCases.Permissions.Input;
using FluentValidation;
namespace Core.Thalos.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.");
}
}
}

View File

@@ -0,0 +1,14 @@
using Core.Thalos.Application.UseCases.Permissions.Input;
using FluentValidation;
namespace Core.Thalos.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.");
}
}
}

View 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);
}
}
}

View File

@@ -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;
}
}
}

View File

@@ -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;
}
}
}

View File

@@ -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;
}
}
}

View File

@@ -0,0 +1,12 @@
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.Application.UseCases.Roles.Input
{
public class GetAllRolesRequest : ICommand
{
public bool Validate()
{
return true;
}
}
}

View File

@@ -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;
}
}
}

View File

@@ -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;
}
}
}

View File

@@ -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;
}
}
}

View 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
{
}
}

View 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);
}
}
}
}

View File

@@ -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.");
}
}
}

View File

@@ -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.");
}
}
}

View File

@@ -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.");
}
}
}

View File

@@ -0,0 +1,33 @@
using Core.Blueprint.Storage.Adapters;
using Core.Thalos.Adapters;
using Core.Thalos.Application.UseCases.Users.Ports;
using Lib.Architecture.BuildingBlocks;
using Microsoft.AspNetCore.Mvc;
namespace Core.Thalos.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);
}
}
}

View File

@@ -0,0 +1,12 @@
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.Application.UseCases.Users.Input
{
public class AcceptUserConsentFormRequest : ICommand
{
public bool Validate()
{
return true;
}
}
}

View File

@@ -0,0 +1,14 @@
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.Application.UseCases.Users.Input
{
public class AddCompanyToUserRequest : Notificator, ICommand
{
public string UserId { get; set; }
public string CompanyId { get; set; }
public bool Validate()
{
return true;
}
}
}

View File

@@ -0,0 +1,14 @@
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.Application.UseCases.Users.Input
{
public class AddProjectToUserRequest : Notificator, ICommand
{
public string UserId { get; set; }
public string ProjectId { get; set; }
public bool Validate()
{
return true;
}
}
}

View File

@@ -0,0 +1,16 @@
using Core.Thalos.Adapters.Common.Enums;
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.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;
}
}
}

View File

@@ -0,0 +1,21 @@
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.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;
}
}
}

View File

@@ -0,0 +1,12 @@
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.Application.UseCases.Users.Input
{
public class GetAllUsersRequest : ICommand
{
public bool Validate()
{
return true;
}
}
}

View File

@@ -0,0 +1,12 @@
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.Application.UseCases.Users.Input
{
public class GetConsentFormPDFRequest : ICommand
{
public bool Validate()
{
return true;
}
}
}

View File

@@ -0,0 +1,13 @@
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.Application.UseCases.Users.Input
{
public class GetTokenAdapterRequest : Notificator, ICommand
{
public string Email { get; set; }
public bool Validate()
{
return Email != null;
}
}
}

View File

@@ -0,0 +1,13 @@
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.Application.UseCases.Users.Input
{
public class GetUserByEmailRequest : Notificator, ICommand
{
public string Email { get; set; }
public bool Validate()
{
return Email != null;
}
}
}

View File

@@ -0,0 +1,13 @@
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.Application.UseCases.Users.Input
{
public class GetUserRequest : Notificator, ICommand
{
public string Id { get; set; }
public bool Validate()
{
return Id != null;
}
}
}

View File

@@ -0,0 +1,13 @@
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.Application.UseCases.Users.Input
{
public class LoginUserRequest : Notificator, ICommand
{
public string Email { get; set; }
public bool Validate()
{
return Email != null;
}
}
}

View File

@@ -0,0 +1,13 @@
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.Application.UseCases.Users.Input
{
public class LogoutUserRequest : Notificator, ICommand
{
public string Email { get; set; }
public bool Validate()
{
return Email != null;
}
}
}

View File

@@ -0,0 +1,14 @@
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.Application.UseCases.Users.Input
{
public class RemoveCompanyFromUserRequest : Notificator, ICommand
{
public string UserId { get; set; }
public string CompanyId { get; set; }
public bool Validate()
{
return true;
}
}
}

View File

@@ -0,0 +1,14 @@
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.Application.UseCases.Users.Input
{
public class RemoveProjectFromUserRequest : Notificator, ICommand
{
public string UserId { get; set; }
public string ProjectId { get; set; }
public bool Validate()
{
return true;
}
}
}

View File

@@ -0,0 +1,20 @@
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.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;
}
}
}

View File

@@ -0,0 +1,13 @@
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.Application.UseCases.Users.Input
{
public class ValidateUserExistenceRequest : Notificator, ICommand
{
public string Email { get; set; }
public bool Validate()
{
return Email != null;
}
}
}

View File

@@ -0,0 +1,18 @@
using Core.Blueprint.Storage.Adapters;
using Core.Thalos.Adapters;
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.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,
IBadRequestPort
{
}
}

View File

@@ -0,0 +1,395 @@
using Core.Thalos.Adapters;
using Core.Thalos.Application.UseCases.Users.Input;
using Core.Thalos.Application.UseCases.Users.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.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>
{
private readonly IUserPort _port;
private readonly IValidator<ChangeUserStatusRequest> _changeUserStatusValidator;
private readonly IValidator<CreateUserRequest> _registerUserValidator;
private readonly IValidator<UpdateUserRequest> _updateUserValidator;
private readonly IThalosServiceClient _thalosDALService;
public UserHandler(
IUserPort port,
IValidator<ChangeUserStatusRequest> changeUserStatusValidator,
IValidator<CreateUserRequest> registerUserValidator,
IValidator<UpdateUserRequest> updateUserValidator,
IThalosServiceClient thalosDALService)
{
_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));
_thalosDALService = thalosDALService ?? throw new ArgumentNullException(nameof(thalosDALService));
}
public async ValueTask ExecuteAsync(GetUserRequest command, CancellationToken cancellationToken = default)
{
try
{
ArgumentNullException.ThrowIfNull(command);
var result = await _thalosDALService.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 _thalosDALService.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 _thalosDALService.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 _thalosDALService.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 _thalosDALService.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 _thalosDALService.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 _thalosDALService.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 _thalosDALService.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 _thalosDALService.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 _thalosDALService.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 _thalosDALService.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 _thalosDALService.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 _thalosDALService.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 _thalosDALService.GetTokenAdapter(command.Email, cancellationToken).ConfigureAwait(false);
if (result == null)
{
_port.NoContentSuccess();
return;
}
_port.Success(result);
}
catch (Exception ex)
{
ApiResponseHelper.EvaluatePort(ex, _port);
}
}
}
}

View File

@@ -0,0 +1,15 @@
using Core.Thalos.Application.UseCases.Users.Input;
using FluentValidation;
namespace Core.Thalos.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.");
}
}
}

View File

@@ -0,0 +1,17 @@
using Core.Thalos.Application.UseCases.Users.Input;
using FluentValidation;
namespace Core.Thalos.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.");
}
}
}

View File

@@ -0,0 +1,17 @@
using Core.Thalos.Application.UseCases.Users.Input;
using FluentValidation;
namespace Core.Thalos.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.");
}
}
}