Add tenant services, change id by _id and include delete endpoint for all entities

This commit is contained in:
Sergio Matias Urquin
2025-08-07 18:27:06 -06:00
parent f3d63ca0e3
commit 296aff13fe
47 changed files with 1183 additions and 118 deletions

View File

@@ -5,12 +5,12 @@ namespace Core.Thalos.Application.UseCases.Modules.Input
{
public class ChangeModuleStatusRequest : Notificator, ICommand
{
public string Id { get; set; }
public string _Id { get; set; }
public StatusEnum Status { get; set; }
public bool Validate()
{
return Id != null;
return _Id != null;
}
}
}

View File

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

View File

@@ -4,10 +4,10 @@ namespace Core.Thalos.Application.UseCases.Modules.Input
{
public class GetModuleRequest : Notificator, ICommand
{
public string Id { get; set; }
public string _Id { get; set; }
public bool Validate()
{
return Id != null;
return _Id != null;
}
}
}

View File

@@ -5,7 +5,7 @@ namespace Core.Thalos.Application.UseCases.Modules.Input
{
public class UpdateModuleRequest : Notificator, ICommand
{
public string Id { get; set; } = null!;
public string _Id { get; set; } = null!;
public string Name { get; set; } = null!;
public string? Description { get; set; }
public string? Icon { get; set; }
@@ -14,7 +14,7 @@ namespace Core.Thalos.Application.UseCases.Modules.Input
public ApplicationsEnum? Application { get; set; } = null!;
public bool Validate()
{
return Id != null;
return _Id != null;
}
}
}

View File

@@ -15,6 +15,7 @@ namespace Core.Thalos.Application.UseCases.Modules
IComponentHandler<GetAllModulesByListRequest>,
IComponentHandler<UpdateModuleRequest>,
IComponentHandler<GetModuleRequest>,
IComponentHandler<DeleteModuleRequest>,
IComponentHandler<CreateModuleRequest>
{
private readonly IModulePort _port;
@@ -46,7 +47,29 @@ namespace Core.Thalos.Application.UseCases.Modules
{
ArgumentNullException.ThrowIfNull(command);
var result = await _thalosDALService.GetModuleByIdAsync(command.Id, cancellationToken).ConfigureAwait(false);
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(DeleteModuleRequest command, CancellationToken cancellationToken = default)
{
try
{
ArgumentNullException.ThrowIfNull(command);
var result = await _thalosDALService.DeleteModuleAsync(command._Id, cancellationToken).ConfigureAwait(false);
if (result == null)
{
@@ -120,7 +143,7 @@ namespace Core.Thalos.Application.UseCases.Modules
return;
}
var result = await _thalosDALService.ChangeStatusModuleAsync(command.Id, command.Status, cancellationToken).ConfigureAwait(false);
var result = await _thalosDALService.ChangeStatusModuleAsync(command._Id, command.Status, cancellationToken).ConfigureAwait(false);
if (result == null)
{
@@ -188,7 +211,7 @@ namespace Core.Thalos.Application.UseCases.Modules
var request = new ModuleAdapter
{
Id = command.Id,
_Id = command._Id,
Name = command.Name,
Description = command.Description,
Application = command.Application,
@@ -197,7 +220,7 @@ namespace Core.Thalos.Application.UseCases.Modules
Icon = command.Icon
};
string id = command.Id;
string id = command._Id;
var result = await _thalosDALService.UpdateModuleAsync(request, id, cancellationToken).ConfigureAwait(false);

View File

@@ -7,7 +7,7 @@ namespace Core.Thalos.Application.UseCases.Modules.Validator
{
public ChangeModuleStatusValidator()
{
RuleFor(i => i.Id).NotEmpty().NotNull().OverridePropertyName(x => x.Id).WithName("Module ID").WithMessage("Module ID is Obligatory.");
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

@@ -5,12 +5,12 @@ namespace Core.Thalos.Application.UseCases.Permissions.Input
{
public class ChangePermissionStatusRequest : Notificator, ICommand
{
public string Id { get; set; }
public string _Id { get; set; }
public StatusEnum Status { get; set; }
public bool Validate()
{
return Id != null;
return _Id != null;
}
}
}

View File

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

View File

@@ -4,10 +4,10 @@ namespace Core.Thalos.Application.UseCases.Permissions.Input
{
public class GetPermissionRequest : Notificator, ICommand
{
public string Id { get; set; }
public string _Id { get; set; }
public bool Validate()
{
return Id != null;
return _Id != null;
}
}
}

View File

@@ -5,14 +5,14 @@ namespace Core.Thalos.Application.UseCases.Permissions.Input
{
public class UpdatePermissionRequest : Notificator, ICommand
{
public string Id { get; set; } = null!;
public string _Id { get; set; } = null!;
public string Name { get; set; } = null!;
public string? Description { get; set; }
public AccessLevelEnum? AccessLevel { get; set; } = null!;
public Blueprint.Mongo.StatusEnum Status { get; set; }
public bool Validate()
{
return Id != null;
return _Id != null;
}
}
}

View File

@@ -15,6 +15,7 @@ namespace Core.Thalos.Application.UseCases.Permissions
IComponentHandler<GetAllPermissionsByListRequest>,
IComponentHandler<UpdatePermissionRequest>,
IComponentHandler<GetPermissionRequest>,
IComponentHandler<DeletePermissionRequest>,
IComponentHandler<CreatePermissionRequest>
{
private readonly IPermissionPort _port;
@@ -43,7 +44,29 @@ namespace Core.Thalos.Application.UseCases.Permissions
{
ArgumentNullException.ThrowIfNull(command);
var result = await _thalosDALService.GetPermissionByIdAsync(command.Id, cancellationToken).ConfigureAwait(false);
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(DeletePermissionRequest command, CancellationToken cancellationToken = default)
{
try
{
ArgumentNullException.ThrowIfNull(command);
var result = await _thalosDALService.DeletePermissionAsync(command._Id, cancellationToken).ConfigureAwait(false);
if (result == null)
{
@@ -111,7 +134,7 @@ namespace Core.Thalos.Application.UseCases.Permissions
return;
}
var result = await _thalosDALService.ChangeStatusPermissionAsync(command.Id, command.Status, cancellationToken).ConfigureAwait(false);
var result = await _thalosDALService.ChangeStatusPermissionAsync(command._Id, command.Status, cancellationToken).ConfigureAwait(false);
if (result == null)
{
@@ -176,13 +199,13 @@ namespace Core.Thalos.Application.UseCases.Permissions
var request = new PermissionAdapter
{
Id = command.Id,
_Id = command._Id,
Name = command.Name,
Description = command.Description,
AccessLevel = command.AccessLevel
};
string id = command.Id;
string id = command._Id;
var result = await _thalosDALService.UpdatePermissionAsync(request, id, cancellationToken).ConfigureAwait(false);

View File

@@ -7,7 +7,7 @@ namespace Core.Thalos.Application.UseCases.Permissions.Validator
{
public ChangePermissionStatusValidator()
{
RuleFor(i => i.Id).NotEmpty().NotNull().OverridePropertyName(x => x.Id).WithName("Permission ID").WithMessage("Permission ID is Obligatory.");
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

@@ -5,11 +5,11 @@ namespace Core.Thalos.Application.UseCases.Roles.Input
{
public class ChangeRoleStatusRequest : Notificator, ICommand
{
public string Id { get; set; }
public string _Id { get; set; }
public StatusEnum Status { get; set; }
public bool Validate()
{
return Id != null;
return _Id != null;
}
}
}

View File

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

View File

@@ -4,10 +4,10 @@ namespace Core.Thalos.Application.UseCases.Roles.Input
{
public class GetRoleRequest : Notificator, ICommand
{
public string Id { get; set; }
public string _Id { get; set; }
public bool Validate()
{
return Id != null;
return _Id != null;
}
}
}

View File

@@ -6,7 +6,7 @@ namespace Core.Thalos.Application.UseCases.Roles.Input
{
public class UpdateRoleRequest : Notificator, ICommand
{
public string Id { get; set; } = null!;
public string _Id { get; set; } = null!;
public string Name { get; set; } = null!;
public string? Description { get; set; }
@@ -18,7 +18,7 @@ namespace Core.Thalos.Application.UseCases.Roles.Input
public bool Validate()
{
return Id != null;
return _Id != null;
}
}
}

View File

@@ -15,6 +15,7 @@ namespace Core.Thalos.Application.UseCases.Role
IComponentHandler<UpdateRoleRequest>,
IComponentHandler<CreateRoleRequest>,
IComponentHandler<GetRoleRequest>,
IComponentHandler<DeleteRoleRequest>,
IComponentHandler<AddApplicationToRoleRequest>,
IComponentHandler<RemoveApplicationFromRoleRequest>
@@ -45,7 +46,29 @@ namespace Core.Thalos.Application.UseCases.Role
{
ArgumentNullException.ThrowIfNull(command);
var result = await _thalosDALService.GetRoleByIdAsync(command.Id, cancellationToken).ConfigureAwait(false);
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(DeleteRoleRequest command, CancellationToken cancellationToken = default)
{
try
{
ArgumentNullException.ThrowIfNull(command);
var result = await _thalosDALService.DeleteRoleAsync(command._Id, cancellationToken).ConfigureAwait(false);
if (result == null)
{
@@ -93,7 +116,7 @@ namespace Core.Thalos.Application.UseCases.Role
return;
}
var result = await _thalosDALService.ChangeRoleStatusAsync(command.Id, command.Status, cancellationToken).ConfigureAwait(false);
var result = await _thalosDALService.ChangeRoleStatusAsync(command._Id, command.Status, cancellationToken).ConfigureAwait(false);
if (result == null)
{
@@ -161,7 +184,7 @@ namespace Core.Thalos.Application.UseCases.Role
var request = new RoleAdapter
{
Id = command.Id,
_Id = command._Id,
Name = command.Name,
Description = command.Description,
Applications = command.Applications,
@@ -169,7 +192,7 @@ namespace Core.Thalos.Application.UseCases.Role
Permissions = command.Permissions
};
string id = command.Id;
string id = command._Id;
var result = await _thalosDALService.UpdateRoleAsync(request, id, cancellationToken).ConfigureAwait(false);

View File

@@ -7,7 +7,7 @@ namespace Core.Thalos.Application.UseCases.Roles.Validator
{
public ChangeRoleStatusValidator()
{
RuleFor(i => i.Id).NotEmpty().NotNull().OverridePropertyName(x => x.Id).WithName("Role ID").WithMessage("Role ID is Obligatory.");
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,19 @@
using Core.Thalos.Application.UseCases.Tenants.Ports;
using Core.Thalos.BuildingBlocks;
using Lib.Architecture.BuildingBlocks;
using Microsoft.AspNetCore.Mvc;
namespace Core.Thalos.Application.UseCases.Tenants.Adapter
{
public class TenantPort : BasePresenter, ITenantPort
{
public void Success(TenantAdapter output)
{
ViewModel = new OkObjectResult(output);
}
public void Success(List<TenantAdapter> output)
{
ViewModel = new OkObjectResult(output);
}
}
}

View File

@@ -0,0 +1,16 @@
using Core.Blueprint.Mongo;
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.Application.UseCases.Tenants.Input
{
public class ChangeTenantStatusRequest : Notificator, ICommand
{
public string _Id { get; set; }
public StatusEnum Status { get; set; }
public bool Validate()
{
return _Id != null;
}
}
}

View File

@@ -0,0 +1,38 @@
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.Application.UseCases.Tenants.Input
{
public class CreateTenantRequest : Notificator, ICommand
{
public string Name { get; set; } = null!;
public string TaxIdentifier { get; set; } = null!;
public string AddressLine1 { get; set; } = null!;
public string? AddressLine2 { get; set; }
public string City { get; set; } = null!;
public string State { get; set; } = null!;
public string Country { get; set; } = null!;
public string PostalCode { get; set; } = null!;
public string ContactEmail { get; set; } = null!;
public string ContactPhone { get; set; } = null!;
public string? Website { get; set; }
public string? ConnectionString { get; set; }
public bool Isolated { get; set; }
public bool Validate()
{
return Name != null;
}
}
}

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,45 @@
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.Application.UseCases.Tenants.Input
{
public class UpdateTenantRequest : Notificator, ICommand
{
public string Name { get; set; } = null!;
public string TaxIdentifier { get; set; } = null!;
public string AddressLine1 { get; set; } = null!;
public string? AddressLine2 { get; set; }
public string City { get; set; } = null!;
public string State { get; set; } = null!;
public string Country { get; set; } = null!;
public string PostalCode { get; set; } = null!;
public string ContactEmail { get; set; } = null!;
public string ContactPhone { get; set; } = null!;
public string? Website { get; set; }
public string? ConnectionString { get; set; }
public bool Isolated { get; set; }
public string _Id { get; set; } = null!;
public string Id { get; init; } = null!;
public DateTime CreatedAt { get; set; }
public string? CreatedBy { get; set; }
public DateTime? UpdatedAt { get; set; }
public string? UpdatedBy { get; set; }
public Blueprint.Mongo.StatusEnum Status { get; set; }
public bool Validate()
{
return _Id != null;
}
}
}

View File

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

View File

@@ -0,0 +1,223 @@
using Core.Thalos.Application.UseCases.Tenants.Input;
using Core.Thalos.Application.UseCases.Tenants.Ports;
using Core.Thalos.BuildingBlocks;
using Core.Thalos.External.Clients;
using FluentValidation;
using Lib.Architecture.BuildingBlocks;
using Lib.Architecture.BuildingBlocks.Helpers;
namespace Core.Thalos.Application.UseCases.Tenants
{
public class TenantHandler :
IComponentHandler<ChangeTenantStatusRequest>,
IComponentHandler<GetAllTenantsRequest>,
IComponentHandler<UpdateTenantRequest>,
IComponentHandler<GetTenantRequest>,
IComponentHandler<DeleteTenantRequest>,
IComponentHandler<CreateTenantRequest>
{
private readonly ITenantPort _port;
private readonly IValidator<ChangeTenantStatusRequest> _changeTenantStatusValidator;
private readonly IValidator<CreateTenantRequest> _registerTenantValidator;
private readonly IValidator<UpdateTenantRequest> _updateTenantValidator;
private readonly IThalosServiceClient _thalosDALService;
public TenantHandler(
ITenantPort port,
IValidator<ChangeTenantStatusRequest> changeTenantStatusValidator,
IValidator<CreateTenantRequest> registerTenantValidator,
IValidator<UpdateTenantRequest> updateTenantValidator,
IThalosServiceClient thalosDALService)
{
_port = port ?? throw new ArgumentNullException(nameof(port));
_changeTenantStatusValidator = changeTenantStatusValidator ?? throw new ArgumentNullException(nameof(changeTenantStatusValidator));
_registerTenantValidator = registerTenantValidator ?? throw new ArgumentNullException(nameof(registerTenantValidator));
_updateTenantValidator = updateTenantValidator ?? throw new ArgumentNullException(nameof(updateTenantValidator));
_thalosDALService = thalosDALService ?? throw new ArgumentNullException(nameof(thalosDALService));
}
public async ValueTask ExecuteAsync(GetTenantRequest command, CancellationToken cancellationToken = default)
{
try
{
ArgumentNullException.ThrowIfNull(command);
var result = await _thalosDALService.GetTenantByIdAsync(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(DeleteTenantRequest command, CancellationToken cancellationToken = default)
{
try
{
ArgumentNullException.ThrowIfNull(command);
var result = await _thalosDALService.DeleteTenantAsync(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(GetAllTenantsRequest command, CancellationToken cancellationToken = default)
{
try
{
ArgumentNullException.ThrowIfNull(command);
var _result = await _thalosDALService.GetAllTenantsAsync().ConfigureAwait(false);
if (!_result.Any())
{
_port.NoContentSuccess();
return;
}
_port.Success(_result.ToList());
}
catch (Exception ex)
{
ApiResponseHelper.EvaluatePort(ex, _port);
}
}
public async ValueTask ExecuteAsync(ChangeTenantStatusRequest command, CancellationToken cancellationToken = default)
{
try
{
ArgumentNullException.ThrowIfNull(command);
if (!command.IsValid(_changeTenantStatusValidator))
{
_port.ValidationErrors(command.Notifications);
return;
}
var result = await _thalosDALService.ChangeStatusTenantAsync(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(CreateTenantRequest command, CancellationToken cancellationToken = default)
{
try
{
ArgumentNullException.ThrowIfNull(command);
if (!command.IsValid(_registerTenantValidator))
{
_port.ValidationErrors(command.Notifications);
return;
}
var request = new TenantRequest
{
Name = command.Name,
AddressLine1 = command.AddressLine1,
AddressLine2 = command.AddressLine2,
TaxIdentifier = command.TaxIdentifier,
City = command.City,
State = command.State,
Country = command.Country,
PostalCode = command.PostalCode,
ContactEmail = command.ContactEmail,
ContactPhone = command.ContactPhone,
Website = command.Website,
ConnectionString = command.ConnectionString,
Isolated = command.Isolated
};
var result = await _thalosDALService.CreateTenantAsync(request, cancellationToken).ConfigureAwait(false);
if (result == null)
{
_port.NoContentSuccess();
return;
}
_port.Success(result);
}
catch (Exception ex)
{
ApiResponseHelper.EvaluatePort(ex, _port);
}
}
public async ValueTask ExecuteAsync(UpdateTenantRequest command, CancellationToken cancellationToken = default)
{
try
{
ArgumentNullException.ThrowIfNull(command);
if (!command.IsValid(_updateTenantValidator))
{
_port.ValidationErrors(command.Notifications);
return;
}
var request = new TenantAdapter
{
_Id = command._Id,
Name = command.Name,
AddressLine1 = command.AddressLine1,
AddressLine2 = command.AddressLine2,
TaxIdentifier = command.TaxIdentifier,
City = command.City,
State = command.State,
Country = command.Country,
PostalCode = command.PostalCode,
ContactEmail = command.ContactEmail,
ContactPhone = command.ContactPhone,
Website = command.Website,
ConnectionString = command.ConnectionString,
Isolated = command.Isolated
};
string id = command._Id;
var result = await _thalosDALService.UpdateTenantAsync(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,15 @@
using Core.Thalos.Application.UseCases.Tenants.Input;
using FluentValidation;
namespace Core.Thalos.Application.UseCases.Tenants.Validator
{
public class ChangeTenantStatusValidator : AbstractValidator<ChangeTenantStatusRequest>
{
public ChangeTenantStatusValidator()
{
RuleFor(i => i._Id).NotEmpty().NotNull().OverridePropertyName(x => x._Id).WithName("Tenant ID").WithMessage("Tenant ID is Obligatory.");
RuleFor(i => i.Status).NotNull().OverridePropertyName(x => x.Status).WithName("Status").WithMessage("Status is Obligatory.");
}
}
}

View File

@@ -0,0 +1,74 @@
using Core.Thalos.Application.UseCases.Tenants.Input;
using FluentValidation;
namespace Core.Thalos.Application.UseCases.Tenants.Validator
{
public class CreateTenantValidator : AbstractValidator<CreateTenantRequest>
{
public CreateTenantValidator()
{
RuleFor(i => i.Name)
.NotEmpty()
.NotNull()
.OverridePropertyName(x => x.Name)
.WithName("Tenant Name")
.WithMessage("Tenant Name is obligatory.");
RuleFor(i => i.TaxIdentifier)
.NotEmpty()
.NotNull()
.OverridePropertyName(x => x.TaxIdentifier)
.WithName("Tax Identifier")
.WithMessage("Tax Identifier is obligatory.");
RuleFor(i => i.AddressLine1)
.NotEmpty()
.NotNull()
.OverridePropertyName(x => x.AddressLine1)
.WithName("Address Line 1")
.WithMessage("Address Line 1 is obligatory.");
RuleFor(i => i.City)
.NotEmpty()
.NotNull()
.OverridePropertyName(x => x.City)
.WithName("City")
.WithMessage("City is obligatory.");
RuleFor(i => i.State)
.NotEmpty()
.NotNull()
.OverridePropertyName(x => x.State)
.WithName("State")
.WithMessage("State is obligatory.");
RuleFor(i => i.Country)
.NotEmpty()
.NotNull()
.OverridePropertyName(x => x.Country)
.WithName("Country")
.WithMessage("Country is obligatory.");
RuleFor(i => i.PostalCode)
.NotEmpty()
.NotNull()
.OverridePropertyName(x => x.PostalCode)
.WithName("Postal Code")
.WithMessage("Postal Code is obligatory.");
RuleFor(i => i.ContactEmail)
.NotEmpty()
.NotNull()
.OverridePropertyName(x => x.ContactEmail)
.WithName("Contact Email")
.WithMessage("Contact Email is obligatory.");
RuleFor(i => i.ContactPhone)
.NotEmpty()
.NotNull()
.OverridePropertyName(x => x.ContactPhone)
.WithName("Contact Phone")
.WithMessage("Contact Phone is obligatory.");
}
}
}

View File

@@ -0,0 +1,66 @@
using Core.Thalos.Application.UseCases.Tenants.Input;
using FluentValidation;
namespace Core.Thalos.Application.UseCases.Tenants.Validator
{
public class UpdateTenantValidator : AbstractValidator<UpdateTenantRequest>
{
public UpdateTenantValidator()
{
RuleFor(i => i.Name)
.NotEmpty().NotNull()
.WithName("Tenant Name")
.WithMessage("Tenant Name is obligatory.");
RuleFor(i => i.TaxIdentifier)
.NotEmpty().NotNull()
.WithName("Tax Identifier")
.WithMessage("Tax Identifier is obligatory.");
RuleFor(i => i.AddressLine1)
.NotEmpty().NotNull()
.WithName("Address Line 1")
.WithMessage("Address Line 1 is obligatory.");
RuleFor(i => i.City)
.NotEmpty().NotNull()
.WithName("City")
.WithMessage("City is obligatory.");
RuleFor(i => i.State)
.NotEmpty().NotNull()
.WithName("State")
.WithMessage("State is obligatory.");
RuleFor(i => i.Country)
.NotEmpty().NotNull()
.WithName("Country")
.WithMessage("Country is obligatory.");
RuleFor(i => i.PostalCode)
.NotEmpty().NotNull()
.WithName("Postal Code")
.WithMessage("Postal Code is obligatory.");
RuleFor(i => i.ContactEmail)
.NotEmpty().NotNull()
.WithName("Contact Email")
.WithMessage("Contact Email is obligatory.");
RuleFor(i => i.ContactPhone)
.NotEmpty().NotNull()
.WithName("Contact Phone")
.WithMessage("Contact Phone is obligatory.");
RuleFor(i => i._Id)
.NotEmpty().NotNull()
.WithName("Internal ID")
.WithMessage("Internal ID is obligatory.");
RuleFor(i => i.Id)
.NotEmpty().NotNull()
.WithName("Tenant ID")
.WithMessage("Tenant ID is obligatory.");
}
}
}

View File

@@ -5,12 +5,12 @@ namespace Core.Thalos.Application.UseCases.Users.Input
{
public class ChangeUserStatusRequest : Notificator, ICommand
{
public string Id { get; set; }
public string _Id { get; set; }
public StatusEnum Status { get; set; }
public bool Validate()
{
return Id != null;
return _Id != null;
}
}
}

View File

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

View File

@@ -4,10 +4,10 @@ namespace Core.Thalos.Application.UseCases.Users.Input
{
public class GetUserRequest : Notificator, ICommand
{
public string Id { get; set; }
public string _Id { get; set; }
public bool Validate()
{
return Id != null;
return _Id != null;
}
}
}

View File

@@ -4,7 +4,7 @@ namespace Core.Thalos.Application.UseCases.Users.Input
{
public class UpdateUserRequest : Notificator, ICommand
{
public string Id { get; set; } = null!;
public string _Id { get; set; } = null!;
public string Email { get; set; } = null!;
public string Name { get; set; } = null!;
public string? MiddleName { get; set; }

View File

@@ -12,6 +12,7 @@ namespace Core.Thalos.Application.UseCases.Users
IComponentHandler<ChangeUserStatusRequest>,
IComponentHandler<GetAllUsersRequest>,
IComponentHandler<UpdateUserRequest>,
IComponentHandler<DeleteUserRequest>,
IComponentHandler<GetUserRequest>,
IComponentHandler<GetUserByEmailRequest>,
IComponentHandler<CreateUserRequest>,
@@ -46,7 +47,29 @@ namespace Core.Thalos.Application.UseCases.Users
{
ArgumentNullException.ThrowIfNull(command);
var result = await _thalosDALService.GetUserByIdAsync(command.Id, cancellationToken).ConfigureAwait(false);
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(DeleteUserRequest command, CancellationToken cancellationToken = default)
{
try
{
ArgumentNullException.ThrowIfNull(command);
var result = await _thalosDALService.DeleteUserAsync(command._Id, cancellationToken).ConfigureAwait(false);
if (result == null)
{
@@ -138,7 +161,7 @@ namespace Core.Thalos.Application.UseCases.Users
return;
}
var result = await _thalosDALService.ChangeUserStatusAsync(command.Id, command.Status, cancellationToken).ConfigureAwait(false);
var result = await _thalosDALService.ChangeUserStatusAsync(command._Id, command.Status, cancellationToken).ConfigureAwait(false);
if (result == null)
{
@@ -205,7 +228,7 @@ namespace Core.Thalos.Application.UseCases.Users
var request = new UserAdapter
{
Id = command.Id,
_Id = command._Id,
Email = command.Email,
Name = command.Name,
MiddleName = command.MiddleName,
@@ -213,7 +236,7 @@ namespace Core.Thalos.Application.UseCases.Users
RoleId = command.RoleId,
};
var result = await _thalosDALService.UpdateUserAsync(request, request.Id, cancellationToken).ConfigureAwait(false);
var result = await _thalosDALService.UpdateUserAsync(request, request._Id, cancellationToken).ConfigureAwait(false);
if (result == null)
{

View File

@@ -7,7 +7,7 @@ namespace Core.Thalos.Application.UseCases.Users.Validator
{
public ChangeUserStatusValidator()
{
RuleFor(i => i.Id).NotEmpty().NotNull().OverridePropertyName(x => x.Id).WithName("User ID").WithMessage("User ID is Obligatory.");
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

@@ -10,7 +10,7 @@ namespace Core.Thalos.Application.UseCases.Users.Validator
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.RoleId).NotEmpty().NotNull().OverridePropertyName(x => x.RoleId).WithName("RoleId").WithMessage("RoleId is Obligatory.");
RuleFor(i => i.Companies).NotEmpty().NotNull().OverridePropertyName(x => x.Companies).WithName("Companies").WithMessage("Companies is Obligatory.");
}
}

View File

@@ -7,10 +7,10 @@ namespace Core.Thalos.Application.UseCases.Users.Validator
{
public UpdateUserValidator()
{
RuleFor(i => i.Email).NotEmpty().NotNull().OverridePropertyName(x => x.Email).WithName("User Email").WithMessage("Email is Obligatory.");
RuleFor(i => i.Email).NotEmpty().NotNull().OverridePropertyName(x => x.Email).WithName("User Email").WithMessage("User 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.RoleId).NotEmpty().NotNull().OverridePropertyName(x => x.RoleId).WithName("RoleId").WithMessage("RoleId is Obligatory.");
RuleFor(i => i.Companies).NotEmpty().NotNull().OverridePropertyName(x => x.Companies).WithName("Companies").WithMessage("Companies is Obligatory.");
}
}