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