Add project files.

This commit is contained in:
Sergio Matias Urquin
2025-04-29 18:56:29 -06:00
parent ad652bc070
commit 7d760b589e
91 changed files with 4366 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
using Core.Cerberos.Adapters;
using Core.Cerberos.Application.UseCases.Modules.Ports;
using Lib.Architecture.BuildingBlocks;
using Microsoft.AspNetCore.Mvc;
namespace Core.Cerberos.Application.UseCases.Modules.Adapter
{
public class ModulePort : BasePresenter, IModulePort
{
public void Success(ModuleAdapter output)
{
ViewModel = new OkObjectResult(output);
}
public void Success(List<ModuleAdapter> output)
{
ViewModel = new OkObjectResult(output);
}
}
}

View File

@@ -0,0 +1,16 @@
using Core.Cerberos.Adapters.Common.Enums;
using Lib.Architecture.BuildingBlocks;
namespace Core.Cerberos.Application.UseCases.Modules.Input
{
public class ChangeModuleStatusRequest : Notificator, ICommand
{
public string Id { get; set; }
public StatusEnum Status { get; set; }
public bool Validate()
{
return Id != null;
}
}
}

View File

@@ -0,0 +1,20 @@
using Core.Cerberos.Adapters.Common.Enums;
using Lib.Architecture.BuildingBlocks;
namespace Core.Cerberos.Application.UseCases.Modules.Input
{
public class CreateModuleRequest : Notificator, ICommand
{
public string Name { get; set; } = null!;
public string? Description { get; set; }
public string? Icon { get; set; }
public string? Route { get; set; }
public int? Order { get; set; }
public ApplicationsEnum? Application { get; set; } = null!;
public bool Validate()
{
return Name != null;
}
}
}

View File

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

View File

@@ -0,0 +1,12 @@
using Lib.Architecture.BuildingBlocks;
namespace Core.Cerberos.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.Cerberos.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.Cerberos.Adapters.Common.Enums;
using Lib.Architecture.BuildingBlocks;
namespace Core.Cerberos.Application.UseCases.Modules.Input
{
public class UpdateModuleRequest : Notificator, ICommand
{
public string Id { get; set; } = null!;
public string Name { get; set; } = null!;
public string? Description { get; set; }
public string? Icon { get; set; }
public string Route { get; set; } = null!;
public int? Order { get; set; }
public ApplicationsEnum? Application { get; set; } = null!;
public StatusEnum Status { get; set; }
public bool Validate()
{
return Id != null;
}
}
}

View File

@@ -0,0 +1,219 @@
using Core.Cerberos.Adapters;
using Core.Cerberos.Application.UseCases.Modules.Input;
using Core.Cerberos.Application.UseCases.Modules.Ports;
using Core.Cerberos.External.Clients;
using Core.Cerberos.External.Clients.Requests;
using FluentValidation;
using Lib.Architecture.BuildingBlocks;
using Lib.Architecture.BuildingBlocks.Helpers;
namespace Core.Cerberos.Application.UseCases.Modules
{
public class ModuleHandler :
IComponentHandler<ChangeModuleStatusRequest>,
IComponentHandler<GetAllModulesRequest>,
IComponentHandler<GetAllModulesByListRequest>,
IComponentHandler<UpdateModuleRequest>,
IComponentHandler<GetModuleRequest>,
IComponentHandler<CreateModuleRequest>
{
private readonly IModulePort _port;
private readonly IValidator<ChangeModuleStatusRequest> _changeModuleStatusValidator;
private readonly IValidator<CreateModuleRequest> _registerModuleValidator;
private readonly IValidator<UpdateModuleRequest> _updateModuleValidator;
private readonly IValidator<GetAllModulesByListRequest> _modulesByListValidator;
private readonly ICerberosServiceClient _cerberosDALService;
public ModuleHandler(
IModulePort port,
IValidator<ChangeModuleStatusRequest> changeModuleStatusValidator,
IValidator<CreateModuleRequest> registerModuleValidator,
IValidator<UpdateModuleRequest> updateModuleValidator,
IValidator<GetAllModulesByListRequest> modulesByListValidator,
ICerberosServiceClient cerberosDALService)
{
_port = port ?? throw new ArgumentNullException(nameof(port));
_changeModuleStatusValidator = changeModuleStatusValidator ?? throw new ArgumentNullException(nameof(changeModuleStatusValidator));
_registerModuleValidator = registerModuleValidator ?? throw new ArgumentNullException(nameof(registerModuleValidator));
_updateModuleValidator = updateModuleValidator ?? throw new ArgumentNullException(nameof(updateModuleValidator));
_cerberosDALService = cerberosDALService ?? throw new ArgumentNullException(nameof(cerberosDALService));
_modulesByListValidator = modulesByListValidator ?? throw new ArgumentNullException(nameof(modulesByListValidator));
}
public async ValueTask ExecuteAsync(GetModuleRequest command, CancellationToken cancellationToken = default)
{
try
{
ArgumentNullException.ThrowIfNull(command);
var result = await _cerberosDALService.GetModuleByIdAsync(command.Id, cancellationToken).ConfigureAwait(false);
if (result == null)
{
_port.NoContentSuccess();
return;
}
_port.Success(result);
}
catch (Exception ex)
{
ApiResponseHelper.EvaluatePort(ex, _port);
}
}
public async ValueTask ExecuteAsync(GetAllModulesRequest command, CancellationToken cancellationToken = default)
{
try
{
ArgumentNullException.ThrowIfNull(command);
var _result = await _cerberosDALService.GetAllModulesAsync().ConfigureAwait(false);
if (!_result.Any())
{
_port.NoContentSuccess();
return;
}
_port.Success(_result.ToList());
}
catch (Exception ex)
{
ApiResponseHelper.EvaluatePort(ex, _port);
}
}
public async ValueTask ExecuteAsync(GetAllModulesByListRequest command, CancellationToken cancellationToken = default)
{
try
{
ArgumentNullException.ThrowIfNull(command);
if (!command.IsValid(_modulesByListValidator))
{
_port.ValidationErrors(command.Notifications);
return;
}
var _result = await _cerberosDALService.GetAllModulesByListAsync(command.Modules, cancellationToken).ConfigureAwait(false);
if (!_result.Any())
{
_port.NoContentSuccess();
return;
}
_port.Success(_result.ToList());
}
catch (Exception ex)
{
ApiResponseHelper.EvaluatePort(ex, _port);
}
}
public async ValueTask ExecuteAsync(ChangeModuleStatusRequest command, CancellationToken cancellationToken = default)
{
try
{
ArgumentNullException.ThrowIfNull(command);
if (!command.IsValid(_changeModuleStatusValidator))
{
_port.ValidationErrors(command.Notifications);
return;
}
var result = await _cerberosDALService.ChangeStatusModuleAsync(command.Id, command.Status, cancellationToken).ConfigureAwait(false);
if (result == null)
{
_port.NoContentSuccess();
return;
}
_port.Success(result);
}
catch (Exception ex)
{
ApiResponseHelper.EvaluatePort(ex, _port);
}
}
public async ValueTask ExecuteAsync(CreateModuleRequest command, CancellationToken cancellationToken = default)
{
try
{
ArgumentNullException.ThrowIfNull(command);
if (!command.IsValid(_registerModuleValidator))
{
_port.ValidationErrors(command.Notifications);
return;
}
var request = new ModuleRequest
{
Name = command.Name,
Description = command.Description,
Icon = command.Icon,
Route = command.Route,
Order = command.Order,
Application = command.Application,
};
var result = await _cerberosDALService.CreateModuleAsync(request, cancellationToken).ConfigureAwait(false);
if (result == null)
{
_port.NoContentSuccess();
return;
}
_port.Success(result);
}
catch (Exception ex)
{
ApiResponseHelper.EvaluatePort(ex, _port);
}
}
public async ValueTask ExecuteAsync(UpdateModuleRequest command, CancellationToken cancellationToken = default)
{
try
{
ArgumentNullException.ThrowIfNull(command);
if (!command.IsValid(_updateModuleValidator))
{
_port.ValidationErrors(command.Notifications);
return;
}
var request = new ModuleAdapter
{
Id = command.Id,
Name = command.Name,
Description = command.Description,
Application = command.Application,
Route = command.Route,
Order = command.Order,
Icon = command.Icon,
Status = command.Status
};
string id = command.Id;
var result = await _cerberosDALService.UpdateModuleAsync(request, id, cancellationToken).ConfigureAwait(false);
if (result == null)
{
_port.NoContentSuccess();
return;
}
_port.Success(result);
}
catch (Exception ex)
{
ApiResponseHelper.EvaluatePort(ex, _port);
}
}
}
}

View File

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

View File

@@ -0,0 +1,14 @@
using Core.Cerberos.Application.UseCases.Modules.Input;
using FluentValidation;
namespace Core.Cerberos.Application.UseCases.Modules.Validator
{
public class ChangeModuleStatusValidator : AbstractValidator<ChangeModuleStatusRequest>
{
public ChangeModuleStatusValidator()
{
RuleFor(i => i.Id).NotEmpty().NotNull().OverridePropertyName(x => x.Id).WithName("Module ID").WithMessage("Module ID is Obligatory.");
RuleFor(i => i.Status).NotNull().OverridePropertyName(x => x.Status).WithName("Status").WithMessage("Status is Obligatory.");
}
}
}

View File

@@ -0,0 +1,15 @@
using Core.Cerberos.Application.UseCases.Modules.Input;
using FluentValidation;
namespace Core.Cerberos.Application.UseCases.Modules.Validator
{
public class CreateModuleValidator : AbstractValidator<CreateModuleRequest>
{
public CreateModuleValidator()
{
RuleFor(i => i.Name).NotEmpty().NotNull().OverridePropertyName(x => x.Name).WithName("Module Name").WithMessage("Module Name is Obligatory.");
RuleFor(i => i.Route).NotEmpty().NotNull().OverridePropertyName(x => x.Route).WithName("Module Route").WithMessage("Module Route is Obligatory.");
RuleFor(i => i.Application).NotEmpty().NotNull().OverridePropertyName(x => x.Application).WithName("Application").WithMessage("Application is Obligatory.");
}
}
}

View File

@@ -0,0 +1,14 @@
using Core.Cerberos.Application.UseCases.Modules.Input;
using FluentValidation;
namespace Core.Cerberos.Application.UseCases.Modules.Validator
{
public class GetAllModulesByListValidator : AbstractValidator<GetAllModulesByListRequest>
{
public GetAllModulesByListValidator()
{
RuleFor(i => i.Modules).NotEmpty().NotNull().OverridePropertyName(x => x.Modules).WithName("Modules").WithMessage("Modules are Obligatory.");
}
}
}

View File

@@ -0,0 +1,15 @@
using Core.Cerberos.Application.UseCases.Modules.Input;
using FluentValidation;
namespace Core.Cerberos.Application.UseCases.Modules.Validator
{
public class UpdateModuleValidator : AbstractValidator<UpdateModuleRequest>
{
public UpdateModuleValidator()
{
RuleFor(i => i.Name).NotEmpty().NotNull().OverridePropertyName(x => x.Name).WithName("Module Name").WithMessage("Module Name is Obligatory.");
RuleFor(i => i.Application).NotEmpty().NotNull().OverridePropertyName(x => x.Application).WithName("Application").WithMessage("Application is Obligatory.");
RuleFor(i => i.Route).NotEmpty().NotNull().OverridePropertyName(x => x.Route).WithName("Module Route").WithMessage("Module Route is Obligatory.");
}
}
}