diff --git a/Core.Thalos.Application/UseCases/Modules/Input/ChangeModuleStatusRequest.cs b/Core.Thalos.Application/UseCases/Modules/Input/ChangeModuleStatusRequest.cs index b89444d..391f5e3 100644 --- a/Core.Thalos.Application/UseCases/Modules/Input/ChangeModuleStatusRequest.cs +++ b/Core.Thalos.Application/UseCases/Modules/Input/ChangeModuleStatusRequest.cs @@ -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; } } } diff --git a/Core.Thalos.Application/UseCases/Modules/Input/DeleteModuleRequest.cs b/Core.Thalos.Application/UseCases/Modules/Input/DeleteModuleRequest.cs new file mode 100644 index 0000000..52270df --- /dev/null +++ b/Core.Thalos.Application/UseCases/Modules/Input/DeleteModuleRequest.cs @@ -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; + } + } +} diff --git a/Core.Thalos.Application/UseCases/Modules/Input/GetModuleRequest.cs b/Core.Thalos.Application/UseCases/Modules/Input/GetModuleRequest.cs index 46428fa..9836476 100644 --- a/Core.Thalos.Application/UseCases/Modules/Input/GetModuleRequest.cs +++ b/Core.Thalos.Application/UseCases/Modules/Input/GetModuleRequest.cs @@ -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; } } } diff --git a/Core.Thalos.Application/UseCases/Modules/Input/UpdateModuleRequest.cs b/Core.Thalos.Application/UseCases/Modules/Input/UpdateModuleRequest.cs index 27dad01..37466a6 100644 --- a/Core.Thalos.Application/UseCases/Modules/Input/UpdateModuleRequest.cs +++ b/Core.Thalos.Application/UseCases/Modules/Input/UpdateModuleRequest.cs @@ -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; } } } diff --git a/Core.Thalos.Application/UseCases/Modules/ModuleHandler.cs b/Core.Thalos.Application/UseCases/Modules/ModuleHandler.cs index 7d18202..9a091fe 100644 --- a/Core.Thalos.Application/UseCases/Modules/ModuleHandler.cs +++ b/Core.Thalos.Application/UseCases/Modules/ModuleHandler.cs @@ -15,6 +15,7 @@ namespace Core.Thalos.Application.UseCases.Modules IComponentHandler, IComponentHandler, IComponentHandler, + IComponentHandler, IComponentHandler { 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); diff --git a/Core.Thalos.Application/UseCases/Modules/Validator/ChangeModuleStatusValidator.cs b/Core.Thalos.Application/UseCases/Modules/Validator/ChangeModuleStatusValidator.cs index d56a632..5a43155 100644 --- a/Core.Thalos.Application/UseCases/Modules/Validator/ChangeModuleStatusValidator.cs +++ b/Core.Thalos.Application/UseCases/Modules/Validator/ChangeModuleStatusValidator.cs @@ -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."); } } diff --git a/Core.Thalos.Application/UseCases/Permissions/Input/ChangePermissionStatusRequest.cs b/Core.Thalos.Application/UseCases/Permissions/Input/ChangePermissionStatusRequest.cs index c31a542..b7caa79 100644 --- a/Core.Thalos.Application/UseCases/Permissions/Input/ChangePermissionStatusRequest.cs +++ b/Core.Thalos.Application/UseCases/Permissions/Input/ChangePermissionStatusRequest.cs @@ -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; } } } diff --git a/Core.Thalos.Application/UseCases/Permissions/Input/DeletePermissionRequest.cs b/Core.Thalos.Application/UseCases/Permissions/Input/DeletePermissionRequest.cs new file mode 100644 index 0000000..5c1aacc --- /dev/null +++ b/Core.Thalos.Application/UseCases/Permissions/Input/DeletePermissionRequest.cs @@ -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; + } + } +} diff --git a/Core.Thalos.Application/UseCases/Permissions/Input/GetPermissionRequest.cs b/Core.Thalos.Application/UseCases/Permissions/Input/GetPermissionRequest.cs index b92bf62..c9869ae 100644 --- a/Core.Thalos.Application/UseCases/Permissions/Input/GetPermissionRequest.cs +++ b/Core.Thalos.Application/UseCases/Permissions/Input/GetPermissionRequest.cs @@ -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; } } } diff --git a/Core.Thalos.Application/UseCases/Permissions/Input/UpdatePermissionRequest.cs b/Core.Thalos.Application/UseCases/Permissions/Input/UpdatePermissionRequest.cs index b491a99..517385d 100644 --- a/Core.Thalos.Application/UseCases/Permissions/Input/UpdatePermissionRequest.cs +++ b/Core.Thalos.Application/UseCases/Permissions/Input/UpdatePermissionRequest.cs @@ -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; } } } diff --git a/Core.Thalos.Application/UseCases/Permissions/PermissionHandler.cs b/Core.Thalos.Application/UseCases/Permissions/PermissionHandler.cs index e1f34a9..634ba46 100644 --- a/Core.Thalos.Application/UseCases/Permissions/PermissionHandler.cs +++ b/Core.Thalos.Application/UseCases/Permissions/PermissionHandler.cs @@ -15,6 +15,7 @@ namespace Core.Thalos.Application.UseCases.Permissions IComponentHandler, IComponentHandler, IComponentHandler, + IComponentHandler, IComponentHandler { 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); diff --git a/Core.Thalos.Application/UseCases/Permissions/Validator/ChangePermissionStatusValidator.cs b/Core.Thalos.Application/UseCases/Permissions/Validator/ChangePermissionStatusValidator.cs index 0271893..9a9aa8e 100644 --- a/Core.Thalos.Application/UseCases/Permissions/Validator/ChangePermissionStatusValidator.cs +++ b/Core.Thalos.Application/UseCases/Permissions/Validator/ChangePermissionStatusValidator.cs @@ -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."); } diff --git a/Core.Thalos.Application/UseCases/Roles/Input/ChangeRoleStatusRequest.cs b/Core.Thalos.Application/UseCases/Roles/Input/ChangeRoleStatusRequest.cs index ea76650..6f504f7 100644 --- a/Core.Thalos.Application/UseCases/Roles/Input/ChangeRoleStatusRequest.cs +++ b/Core.Thalos.Application/UseCases/Roles/Input/ChangeRoleStatusRequest.cs @@ -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; } } } diff --git a/Core.Thalos.Application/UseCases/Roles/Input/DeleteRoleRequest.cs b/Core.Thalos.Application/UseCases/Roles/Input/DeleteRoleRequest.cs new file mode 100644 index 0000000..81f07f2 --- /dev/null +++ b/Core.Thalos.Application/UseCases/Roles/Input/DeleteRoleRequest.cs @@ -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; + } + } +} diff --git a/Core.Thalos.Application/UseCases/Roles/Input/GetRoleRequest.cs b/Core.Thalos.Application/UseCases/Roles/Input/GetRoleRequest.cs index 385be8f..02a0ba4 100644 --- a/Core.Thalos.Application/UseCases/Roles/Input/GetRoleRequest.cs +++ b/Core.Thalos.Application/UseCases/Roles/Input/GetRoleRequest.cs @@ -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; } } } diff --git a/Core.Thalos.Application/UseCases/Roles/Input/UpdateRoleRequest.cs b/Core.Thalos.Application/UseCases/Roles/Input/UpdateRoleRequest.cs index e3efc90..bfbc94c 100644 --- a/Core.Thalos.Application/UseCases/Roles/Input/UpdateRoleRequest.cs +++ b/Core.Thalos.Application/UseCases/Roles/Input/UpdateRoleRequest.cs @@ -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; } } } diff --git a/Core.Thalos.Application/UseCases/Roles/RoleHandler.cs b/Core.Thalos.Application/UseCases/Roles/RoleHandler.cs index 8786b87..4902f9a 100644 --- a/Core.Thalos.Application/UseCases/Roles/RoleHandler.cs +++ b/Core.Thalos.Application/UseCases/Roles/RoleHandler.cs @@ -15,6 +15,7 @@ namespace Core.Thalos.Application.UseCases.Role IComponentHandler, IComponentHandler, IComponentHandler, + IComponentHandler, IComponentHandler, IComponentHandler @@ -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); diff --git a/Core.Thalos.Application/UseCases/Roles/Validator/ChangeRoleStatusValidator.cs b/Core.Thalos.Application/UseCases/Roles/Validator/ChangeRoleStatusValidator.cs index 756b0d6..c76c7d7 100644 --- a/Core.Thalos.Application/UseCases/Roles/Validator/ChangeRoleStatusValidator.cs +++ b/Core.Thalos.Application/UseCases/Roles/Validator/ChangeRoleStatusValidator.cs @@ -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."); } diff --git a/Core.Thalos.Application/UseCases/Tenants/Adapter/TenantPort.cs b/Core.Thalos.Application/UseCases/Tenants/Adapter/TenantPort.cs new file mode 100644 index 0000000..bfdc10e --- /dev/null +++ b/Core.Thalos.Application/UseCases/Tenants/Adapter/TenantPort.cs @@ -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 output) + { + ViewModel = new OkObjectResult(output); + } + } +} diff --git a/Core.Thalos.Application/UseCases/Tenants/Input/ChangeTenantStatusRequest.cs b/Core.Thalos.Application/UseCases/Tenants/Input/ChangeTenantStatusRequest.cs new file mode 100644 index 0000000..1661219 --- /dev/null +++ b/Core.Thalos.Application/UseCases/Tenants/Input/ChangeTenantStatusRequest.cs @@ -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; + } + } +} diff --git a/Core.Thalos.Application/UseCases/Tenants/Input/CreateTenantRequest.cs b/Core.Thalos.Application/UseCases/Tenants/Input/CreateTenantRequest.cs new file mode 100644 index 0000000..f4d0b9c --- /dev/null +++ b/Core.Thalos.Application/UseCases/Tenants/Input/CreateTenantRequest.cs @@ -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; + } + } +} diff --git a/Core.Thalos.Application/UseCases/Tenants/Input/DeleteTenantRequest.cs b/Core.Thalos.Application/UseCases/Tenants/Input/DeleteTenantRequest.cs new file mode 100644 index 0000000..7827d43 --- /dev/null +++ b/Core.Thalos.Application/UseCases/Tenants/Input/DeleteTenantRequest.cs @@ -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; + } + } +} diff --git a/Core.Thalos.Application/UseCases/Tenants/Input/GetAllTenantsRequest.cs b/Core.Thalos.Application/UseCases/Tenants/Input/GetAllTenantsRequest.cs new file mode 100644 index 0000000..c074c5c --- /dev/null +++ b/Core.Thalos.Application/UseCases/Tenants/Input/GetAllTenantsRequest.cs @@ -0,0 +1,12 @@ +using Lib.Architecture.BuildingBlocks; + +namespace Core.Thalos.Application.UseCases.Tenants.Input +{ + public class GetAllTenantsRequest : ICommand + { + public bool Validate() + { + return true; + } + } +} diff --git a/Core.Thalos.Application/UseCases/Tenants/Input/GetTenantRequest.cs b/Core.Thalos.Application/UseCases/Tenants/Input/GetTenantRequest.cs new file mode 100644 index 0000000..a28b8c1 --- /dev/null +++ b/Core.Thalos.Application/UseCases/Tenants/Input/GetTenantRequest.cs @@ -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; + } + } +} diff --git a/Core.Thalos.Application/UseCases/Tenants/Input/UpdateTenantRequest.cs b/Core.Thalos.Application/UseCases/Tenants/Input/UpdateTenantRequest.cs new file mode 100644 index 0000000..83a1c35 --- /dev/null +++ b/Core.Thalos.Application/UseCases/Tenants/Input/UpdateTenantRequest.cs @@ -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; + } + } +} diff --git a/Core.Thalos.Application/UseCases/Tenants/Ports/ITenantPort.cs b/Core.Thalos.Application/UseCases/Tenants/Ports/ITenantPort.cs new file mode 100644 index 0000000..f571132 --- /dev/null +++ b/Core.Thalos.Application/UseCases/Tenants/Ports/ITenantPort.cs @@ -0,0 +1,14 @@ +using Core.Thalos.BuildingBlocks; +using Lib.Architecture.BuildingBlocks; + +namespace Core.Thalos.Application.UseCases.Tenants.Ports +{ + public interface ITenantPort : IBasePort, + ICommandSuccessPort, + ICommandSuccessPort>, + INoContentPort, IBusinessErrorPort, ITimeoutPort, IValidationErrorPort, + INotFoundPort, IForbiddenPort, IUnauthorizedPort, IInternalServerErrorPort, + IBadRequestPort + { + } +} diff --git a/Core.Thalos.Application/UseCases/Tenants/TenantHandler.cs b/Core.Thalos.Application/UseCases/Tenants/TenantHandler.cs new file mode 100644 index 0000000..7bb14dc --- /dev/null +++ b/Core.Thalos.Application/UseCases/Tenants/TenantHandler.cs @@ -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, + IComponentHandler, + IComponentHandler, + IComponentHandler, + IComponentHandler, + IComponentHandler + { + private readonly ITenantPort _port; + private readonly IValidator _changeTenantStatusValidator; + private readonly IValidator _registerTenantValidator; + private readonly IValidator _updateTenantValidator; + private readonly IThalosServiceClient _thalosDALService; + + public TenantHandler( + ITenantPort port, + IValidator changeTenantStatusValidator, + IValidator registerTenantValidator, + IValidator 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); + } + } + } +} diff --git a/Core.Thalos.Application/UseCases/Tenants/Validator/ChangeTenantStatusValidator.cs b/Core.Thalos.Application/UseCases/Tenants/Validator/ChangeTenantStatusValidator.cs new file mode 100644 index 0000000..0758ff4 --- /dev/null +++ b/Core.Thalos.Application/UseCases/Tenants/Validator/ChangeTenantStatusValidator.cs @@ -0,0 +1,15 @@ +using Core.Thalos.Application.UseCases.Tenants.Input; +using FluentValidation; + +namespace Core.Thalos.Application.UseCases.Tenants.Validator +{ + public class ChangeTenantStatusValidator : AbstractValidator + { + 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."); + } + + } +} \ No newline at end of file diff --git a/Core.Thalos.Application/UseCases/Tenants/Validator/CreateTenantValidator.cs b/Core.Thalos.Application/UseCases/Tenants/Validator/CreateTenantValidator.cs new file mode 100644 index 0000000..5da8333 --- /dev/null +++ b/Core.Thalos.Application/UseCases/Tenants/Validator/CreateTenantValidator.cs @@ -0,0 +1,74 @@ +using Core.Thalos.Application.UseCases.Tenants.Input; +using FluentValidation; + +namespace Core.Thalos.Application.UseCases.Tenants.Validator +{ + public class CreateTenantValidator : AbstractValidator + { + 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."); + } + } +} diff --git a/Core.Thalos.Application/UseCases/Tenants/Validator/UpdateTenantValidator.cs b/Core.Thalos.Application/UseCases/Tenants/Validator/UpdateTenantValidator.cs new file mode 100644 index 0000000..84be80b --- /dev/null +++ b/Core.Thalos.Application/UseCases/Tenants/Validator/UpdateTenantValidator.cs @@ -0,0 +1,66 @@ +using Core.Thalos.Application.UseCases.Tenants.Input; +using FluentValidation; + +namespace Core.Thalos.Application.UseCases.Tenants.Validator +{ + public class UpdateTenantValidator : AbstractValidator + { + 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."); + } + } +} diff --git a/Core.Thalos.Application/UseCases/Users/Input/ChangeUserStatusRequest.cs b/Core.Thalos.Application/UseCases/Users/Input/ChangeUserStatusRequest.cs index cd69a05..e5e9671 100644 --- a/Core.Thalos.Application/UseCases/Users/Input/ChangeUserStatusRequest.cs +++ b/Core.Thalos.Application/UseCases/Users/Input/ChangeUserStatusRequest.cs @@ -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; } } } diff --git a/Core.Thalos.Application/UseCases/Users/Input/DeleteUserRequest.cs b/Core.Thalos.Application/UseCases/Users/Input/DeleteUserRequest.cs new file mode 100644 index 0000000..3f51e37 --- /dev/null +++ b/Core.Thalos.Application/UseCases/Users/Input/DeleteUserRequest.cs @@ -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; + } + } +} diff --git a/Core.Thalos.Application/UseCases/Users/Input/GetUserRequest.cs b/Core.Thalos.Application/UseCases/Users/Input/GetUserRequest.cs index 890a4b4..121bb81 100644 --- a/Core.Thalos.Application/UseCases/Users/Input/GetUserRequest.cs +++ b/Core.Thalos.Application/UseCases/Users/Input/GetUserRequest.cs @@ -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; } } } diff --git a/Core.Thalos.Application/UseCases/Users/Input/UpdateUserRequest.cs b/Core.Thalos.Application/UseCases/Users/Input/UpdateUserRequest.cs index 92e9a51..2bf11dc 100644 --- a/Core.Thalos.Application/UseCases/Users/Input/UpdateUserRequest.cs +++ b/Core.Thalos.Application/UseCases/Users/Input/UpdateUserRequest.cs @@ -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; } diff --git a/Core.Thalos.Application/UseCases/Users/UserHandler.cs b/Core.Thalos.Application/UseCases/Users/UserHandler.cs index 5b5ae2c..fa898b4 100644 --- a/Core.Thalos.Application/UseCases/Users/UserHandler.cs +++ b/Core.Thalos.Application/UseCases/Users/UserHandler.cs @@ -12,6 +12,7 @@ namespace Core.Thalos.Application.UseCases.Users IComponentHandler, IComponentHandler, IComponentHandler, + IComponentHandler, IComponentHandler, IComponentHandler, IComponentHandler, @@ -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) { diff --git a/Core.Thalos.Application/UseCases/Users/Validator/ChangeUserStatusValidator.cs b/Core.Thalos.Application/UseCases/Users/Validator/ChangeUserStatusValidator.cs index 85d84cf..9cc298a 100644 --- a/Core.Thalos.Application/UseCases/Users/Validator/ChangeUserStatusValidator.cs +++ b/Core.Thalos.Application/UseCases/Users/Validator/ChangeUserStatusValidator.cs @@ -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."); } diff --git a/Core.Thalos.Application/UseCases/Users/Validator/CreateUserValidator.cs b/Core.Thalos.Application/UseCases/Users/Validator/CreateUserValidator.cs index 938f5a3..0eef68c 100644 --- a/Core.Thalos.Application/UseCases/Users/Validator/CreateUserValidator.cs +++ b/Core.Thalos.Application/UseCases/Users/Validator/CreateUserValidator.cs @@ -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."); } } diff --git a/Core.Thalos.Application/UseCases/Users/Validator/UpdateUserValidator.cs b/Core.Thalos.Application/UseCases/Users/Validator/UpdateUserValidator.cs index a769fc3..98d9179 100644 --- a/Core.Thalos.Application/UseCases/Users/Validator/UpdateUserValidator.cs +++ b/Core.Thalos.Application/UseCases/Users/Validator/UpdateUserValidator.cs @@ -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."); } } diff --git a/Core.Thalos.External/Clients/IThalosServiceClient.cs b/Core.Thalos.External/Clients/IThalosServiceClient.cs index 215d54b..096168a 100644 --- a/Core.Thalos.External/Clients/IThalosServiceClient.cs +++ b/Core.Thalos.External/Clients/IThalosServiceClient.cs @@ -11,7 +11,7 @@ namespace Core.Thalos.External.Clients Task> GetAllUsersAsync(CancellationToken cancellationToken = default); [Get("/v1/User/" + Routes.Id)] - Task GetUserByIdAsync([FromRoute] string id, CancellationToken cancellationToken = default); + Task GetUserByIdAsync([FromRoute] string _id, CancellationToken cancellationToken = default); [Get("/v1/User/" + Routes.Email)] Task GetUserByEmailAsync([FromRoute] string email, CancellationToken cancellationToken = default); @@ -23,7 +23,10 @@ namespace Core.Thalos.External.Clients Task CreateUserAsync([FromBody] UserRequest newUser, [FromRoute] bool sendInvitation, CancellationToken cancellationToken = default); [Put("/v1/User/" + Routes.Id)] - Task UpdateUserAsync([FromBody] UserAdapter entity, [FromRoute] string id, CancellationToken cancellationToken = default); + Task UpdateUserAsync([FromBody] UserAdapter entity, [FromRoute] string _id, CancellationToken cancellationToken = default); + + [Delete("/v1/User/" + Routes.Id)] + Task DeleteUserAsync([FromRoute] string _id, CancellationToken cancellationToken = default); [Patch("/v1/User/" + Routes.LogIn)] Task LoginUserAsync([FromRoute] string email, CancellationToken cancellationToken = default); @@ -32,7 +35,7 @@ namespace Core.Thalos.External.Clients Task LogoutUserAsync([FromRoute] string email, CancellationToken cancellationToken = default); [Patch("/v1/User/" + Routes.ChangeStatus)] - Task ChangeUserStatusAsync([FromRoute] string id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken = default); + Task ChangeUserStatusAsync([FromRoute] string _id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken = default); [Get("/v1/User/{email}/GetTokenAdapter")] Task GetTokenAdapter([FromRoute] string email, CancellationToken cancellationToken = default); @@ -41,16 +44,19 @@ namespace Core.Thalos.External.Clients Task> GetAllRolesAsync(CancellationToken cancellationToken = default); [Get("/v1/Role/" + Routes.Id)] - Task GetRoleByIdAsync([FromRoute] string id, CancellationToken cancellationToken = default); + Task GetRoleByIdAsync([FromRoute] string _id, CancellationToken cancellationToken = default); [Post("/v1/Role")] Task CreateRoleAsync([FromBody] RoleRequest newRole, CancellationToken cancellationToken = default); [Put("/v1/Role/" + Routes.Id)] - Task UpdateRoleAsync([FromBody] RoleAdapter entity, [FromRoute] string id, CancellationToken cancellationToken = default); + Task UpdateRoleAsync([FromBody] RoleAdapter entity, [FromRoute] string _id, CancellationToken cancellationToken = default); + + [Delete("/v1/Role/" + Routes.Id)] + Task DeleteRoleAsync([FromRoute] string _id, CancellationToken cancellationToken = default); [Patch("/v1/Role/" + Routes.ChangeStatus)] - Task ChangeRoleStatusAsync([FromRoute] string id, [FromRoute] Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken = default); + Task ChangeRoleStatusAsync([FromRoute] string _id, [FromRoute] Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken = default); [Post("/v1/Role/" + Routes.AddApplication)] Task AddApplicationToRoleAsync([FromRoute] string RoleId, [FromRoute] ApplicationsEnum application, CancellationToken cancellationToken = default); @@ -65,16 +71,19 @@ namespace Core.Thalos.External.Clients Task> GetAllPermissionsByListAsync([FromBody] string[] request, CancellationToken cancellationToken = default); [Get("/v1/Permission/" + Routes.Id)] - Task GetPermissionByIdAsync([FromRoute] string id, CancellationToken cancellationToken = default); + Task GetPermissionByIdAsync([FromRoute] string _id, CancellationToken cancellationToken = default); [Post("/v1/Permission")] Task CreatePermissionAsync([FromBody] PermissionRequest newPermission, CancellationToken cancellationToken = default); [Put("/v1/Permission/" + Routes.Id)] - Task UpdatePermissionAsync([FromBody] PermissionAdapter entity, [FromRoute] string id, CancellationToken cancellationToken = default); + Task UpdatePermissionAsync([FromBody] PermissionAdapter entity, [FromRoute] string _id, CancellationToken cancellationToken = default); + + [Delete("/v1/Permission/" + Routes.Id)] + Task DeletePermissionAsync([FromRoute] string _id, CancellationToken cancellationToken = default); [Patch("/v1/Permission/" + Routes.ChangeStatus)] - Task ChangeStatusPermissionAsync([FromRoute] string id, [FromRoute] Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken = default); + Task ChangeStatusPermissionAsync([FromRoute] string _id, [FromRoute] Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken = default); [Get("/v1/Module")] Task> GetAllModulesAsync(CancellationToken cancellationToken = default); @@ -83,15 +92,36 @@ namespace Core.Thalos.External.Clients Task> GetAllModulesByListAsync([FromBody] string[] request, CancellationToken cancellationToken = default); [Get("/v1/Module/" + Routes.Id)] - Task GetModuleByIdAsync([FromRoute] string id, CancellationToken cancellationToken = default); + Task GetModuleByIdAsync([FromRoute] string _id, CancellationToken cancellationToken = default); [Post("/v1/Module")] Task CreateModuleAsync([FromBody] ModuleRequest newModule, CancellationToken cancellationToken = default); [Put("/v1/Module/" + Routes.Id)] - Task UpdateModuleAsync([FromBody] ModuleAdapter entity, [FromRoute] string id, CancellationToken cancellationToken = default); + Task UpdateModuleAsync([FromBody] ModuleAdapter entity, [FromRoute] string _id, CancellationToken cancellationToken = default); + + [Delete("/v1/Module/" + Routes.Id)] + Task DeleteModuleAsync([FromRoute] string _id, CancellationToken cancellationToken = default); [Patch("/v1/Module/" + Routes.ChangeStatus)] - Task ChangeStatusModuleAsync([FromRoute] string id, [FromRoute] Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken = default); + Task ChangeStatusModuleAsync([FromRoute] string _id, [FromRoute] Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken = default); + + [Get("/v1/Tenant")] + Task> GetAllTenantsAsync(CancellationToken cancellationToken = default); + + [Get("/v1/Tenant/" + Routes.Id)] + Task GetTenantByIdAsync([FromRoute] string _id, CancellationToken cancellationToken = default); + + [Post("/v1/Tenant")] + Task CreateTenantAsync([FromBody] TenantRequest newTenant, CancellationToken cancellationToken = default); + + [Put("/v1/Tenant/" + Routes.Id)] + Task UpdateTenantAsync([FromBody] TenantAdapter entity, [FromRoute] string _id, CancellationToken cancellationToken = default); + + [Patch("/v1/Tenant/" + Routes.ChangeStatus)] + Task ChangeStatusTenantAsync([FromRoute] string _id, [FromRoute] Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken = default); + + [Delete("/v1/Tenant/" + Routes.Id)] + Task DeleteTenantAsync([FromRoute] string _id, CancellationToken cancellationToken = default); } } diff --git a/Core.Thalos.External/Clients/Requests/TenantRequest.cs b/Core.Thalos.External/Clients/Requests/TenantRequest.cs new file mode 100644 index 0000000..5df05ed --- /dev/null +++ b/Core.Thalos.External/Clients/Requests/TenantRequest.cs @@ -0,0 +1,53 @@ +using Core.Blueprint.Mongo; +using MongoDB.Bson; +using MongoDB.Bson.Serialization.Attributes; + +namespace Core.Thalos.BuildingBlocks +{ + [CollectionAttributeName("Tenants")] + public class TenantRequest : Document + { + [BsonElement("name")] + public string Name { get; set; } = null!; + + [BsonElement("taxIdentifier")] + public string TaxIdentifier { get; set; } = null!; + + [BsonElement("addressLine1")] + public string AddressLine1 { get; set; } = null!; + + [BsonElement("addressLine2")] + [BsonIgnoreIfNull] + public string? AddressLine2 { get; set; } + + [BsonElement("city")] + public string City { get; set; } = null!; + + [BsonElement("state")] + public string State { get; set; } = null!; + + [BsonElement("country")] + public string Country { get; set; } = null!; + + [BsonElement("postalCode")] + public string PostalCode { get; set; } = null!; + + [BsonElement("contactEmail")] + public string ContactEmail { get; set; } = null!; + + [BsonElement("contactPhone")] + public string ContactPhone { get; set; } = null!; + + [BsonElement("website")] + [BsonIgnoreIfNull] + public string? Website { get; set; } + + [BsonElement("connectionString")] + [BsonIgnoreIfNull] + public string? ConnectionString { get; set; } + + [BsonElement("isolated")] + public bool Isolated { get; set; } + } + +} diff --git a/Core.Thalos.External/Core.Thalos.External.csproj b/Core.Thalos.External/Core.Thalos.External.csproj index 271efcf..56d40f9 100644 --- a/Core.Thalos.External/Core.Thalos.External.csproj +++ b/Core.Thalos.External/Core.Thalos.External.csproj @@ -8,7 +8,7 @@ - + diff --git a/Core.Thalos.Service.API/Controllers/ModuleController.cs b/Core.Thalos.Service.API/Controllers/ModuleController.cs index dd4d2c6..1eae85c 100644 --- a/Core.Thalos.Service.API/Controllers/ModuleController.cs +++ b/Core.Thalos.Service.API/Controllers/ModuleController.cs @@ -23,6 +23,7 @@ namespace Core.Thalos.Service.API.Controllers private readonly IComponentHandler getAllModulesByListHandler; private readonly IComponentHandler createModuleHandler; private readonly IComponentHandler updateModuleHandler; + private readonly IComponentHandler deleteModuleHandler; private readonly IComponentHandler changeModuleStatusHandler; private readonly IModulePort port; @@ -35,12 +36,14 @@ namespace Core.Thalos.Service.API.Controllers IComponentHandler getAllModulesByListHandler, IComponentHandler createModuleHandler, IComponentHandler updateModuleHandler, + IComponentHandler deleteModuleHandler, IComponentHandler changeModuleStatusHandler, IModulePort port ) { this.createModuleHandler = createModuleHandler; this.updateModuleHandler = updateModuleHandler; + this.deleteModuleHandler = deleteModuleHandler; this.changeModuleStatusHandler = changeModuleStatusHandler; this.getAllModulesHandler = getAllModulesHandler; this.getModuleHandler = getModuleHandler; @@ -104,7 +107,7 @@ namespace Core.Thalos.Service.API.Controllers } /// - /// Gets the module by identifier. + /// Gets the module by mongo identifier. /// [HttpPost] [Route("GetById")] @@ -119,9 +122,9 @@ namespace Core.Thalos.Service.API.Controllers public async Task GetModuleById([FromBody] GetModuleRequest request, CancellationToken cancellationToken) { - if (request.Id == null || !request.Id.Any()) + if (request._Id == null || !request._Id.Any()) { - return BadRequest("Invalid Module Id"); + return BadRequest("Invalid Module _Id"); } await getModuleHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); @@ -149,7 +152,7 @@ namespace Core.Thalos.Service.API.Controllers } /// - /// Updates a full module by identifier. + /// Updates a full module by mongo identifier. /// [HttpPut("Update")] [ProducesResponseType(StatusCodes.Status200OK)] @@ -167,6 +170,25 @@ namespace Core.Thalos.Service.API.Controllers return port.ViewModel; } + /// + /// Deletes a full module by mongo identifier. + /// + [HttpDelete("Delete")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] + [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [Permission("ModuleManagement.Write")] + public async Task DeleteModuleAsync([FromBody] DeleteModuleRequest request, CancellationToken cancellationToken = default) + { + await deleteModuleHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); + + return port.ViewModel; + } + /// /// Changes the status of the module. /// @@ -183,7 +205,7 @@ namespace Core.Thalos.Service.API.Controllers public async Task ChangeModuleStatusAsync([FromBody] ChangeModuleStatusRequest request, CancellationToken cancellationToken) { - if (string.IsNullOrEmpty(request.Id)) { return BadRequest("Invalid module identifier"); } + if (string.IsNullOrEmpty(request._Id)) { return BadRequest("Invalid module mongo identifier"); } await changeModuleStatusHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); diff --git a/Core.Thalos.Service.API/Controllers/PermissionController.cs b/Core.Thalos.Service.API/Controllers/PermissionController.cs index 22798ee..9f7782f 100644 --- a/Core.Thalos.Service.API/Controllers/PermissionController.cs +++ b/Core.Thalos.Service.API/Controllers/PermissionController.cs @@ -23,6 +23,7 @@ namespace Core.Thalos.Service.API.Controllers private readonly IComponentHandler getAllPermissionsByListHandler; private readonly IComponentHandler createPermissionHandler; private readonly IComponentHandler updatePermissionHandler; + private readonly IComponentHandler deletePermissionHandler; private readonly IComponentHandler changePermissionStatusHandler; private readonly IPermissionPort port; @@ -35,12 +36,14 @@ namespace Core.Thalos.Service.API.Controllers IComponentHandler getAllPermissionsByListHandler, IComponentHandler createPermissionHandler, IComponentHandler updatePermissionHandler, + IComponentHandler deletePermissionHandler, IComponentHandler changePermissionStatusHandler, IPermissionPort port ) { this.createPermissionHandler = createPermissionHandler; this.updatePermissionHandler = updatePermissionHandler; + this.deletePermissionHandler = deletePermissionHandler; this.changePermissionStatusHandler = changePermissionStatusHandler; this.getAllPermissionsHandler = getAllPermissionsHandler; this.getPermissionHandler = getPermissionHandler; @@ -104,7 +107,7 @@ namespace Core.Thalos.Service.API.Controllers } /// - /// Gets the permission by identifier. + /// Gets the permission by mongo identifier. /// [HttpPost] [Route("GetById")] @@ -119,9 +122,9 @@ namespace Core.Thalos.Service.API.Controllers public async Task GetPermissionById([FromBody] GetPermissionRequest request, CancellationToken cancellationToken) { - if (request.Id == null || !request.Id.Any()) + if (request._Id == null || !request._Id.Any()) { - return BadRequest("Invalid Permission Id"); + return BadRequest("Invalid Permission _Id"); } await getPermissionHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); @@ -149,7 +152,7 @@ namespace Core.Thalos.Service.API.Controllers } /// - /// Updates a full permission by identifier. + /// Updates a full permission by mongo identifier. /// [HttpPut("Update")] [ProducesResponseType(StatusCodes.Status200OK)] @@ -167,6 +170,25 @@ namespace Core.Thalos.Service.API.Controllers return port.ViewModel; } + /// + /// Deletes a full permission by mongo identifier. + /// + [HttpDelete("Delete")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] + [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [Permission("PermissionManagement.Write")] + public async Task DeletePermissionAsync([FromBody] DeletePermissionRequest request, CancellationToken cancellationToken = default) + { + await deletePermissionHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); + + return port.ViewModel; + } + /// /// Changes the status of the permission. /// @@ -183,7 +205,7 @@ namespace Core.Thalos.Service.API.Controllers public async Task ChangePermissionStatusAsync([FromBody] ChangePermissionStatusRequest request, CancellationToken cancellationToken) { - if (string.IsNullOrEmpty(request.Id)) { return BadRequest("Invalid permission identifier"); } + if (string.IsNullOrEmpty(request._Id)) { return BadRequest("Invalid permission mongo identifier"); } await changePermissionStatusHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); diff --git a/Core.Thalos.Service.API/Controllers/RoleController.cs b/Core.Thalos.Service.API/Controllers/RoleController.cs index 9547fa7..dbd5bbd 100644 --- a/Core.Thalos.Service.API/Controllers/RoleController.cs +++ b/Core.Thalos.Service.API/Controllers/RoleController.cs @@ -22,6 +22,7 @@ namespace Core.Thalos.Service.API.Controllers private readonly IComponentHandler getAllRolesHandler; private readonly IComponentHandler createRoleHandler; private readonly IComponentHandler updateRoleHandler; + private readonly IComponentHandler deleteRoleHandler; private readonly IComponentHandler changeStatusRoleHandler; private readonly IComponentHandler addApplicationToRoleHandler; private readonly IComponentHandler removeApplicationToRoleHandler; @@ -35,6 +36,7 @@ namespace Core.Thalos.Service.API.Controllers IComponentHandler getAllRolesHandler, IComponentHandler createRoleHandler, IComponentHandler updateRoleHandler, + IComponentHandler deleteRoleHandler, IComponentHandler changeRoleStatusHandler, IComponentHandler addApplicationToRoleHandler, IComponentHandler removeApplicationToRoleHandler, @@ -43,6 +45,7 @@ namespace Core.Thalos.Service.API.Controllers { this.createRoleHandler = createRoleHandler; this.updateRoleHandler = updateRoleHandler; + this.deleteRoleHandler = deleteRoleHandler; this.changeStatusRoleHandler = changeRoleStatusHandler; this.getAllRolesHandler = getAllRolesHandler; this.getRoleHandler = getRoleHandler; @@ -71,7 +74,7 @@ namespace Core.Thalos.Service.API.Controllers } /// - /// Gets the role by identifier. + /// Gets the role by mongo identifier. /// [HttpPost] [Route("GetById")] @@ -85,7 +88,7 @@ namespace Core.Thalos.Service.API.Controllers [Permission("RoleManagement.Read")] public async Task GetRoleById([FromBody] GetRoleRequest request, CancellationToken cancellationToken) { - if (string.IsNullOrEmpty(request.Id)) { return BadRequest("Invalid role identifier"); } + if (string.IsNullOrEmpty(request._Id)) { return BadRequest("Invalid role mongo identifier"); } await getRoleHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); @@ -112,7 +115,7 @@ namespace Core.Thalos.Service.API.Controllers } /// - /// Updates a full role by identifier. + /// Updates a full role by mongo identifier. /// [HttpPut("Update")] [ProducesResponseType(StatusCodes.Status200OK)] @@ -130,6 +133,25 @@ namespace Core.Thalos.Service.API.Controllers return port.ViewModel; } + /// + /// Deletes a full role by mongo identifier. + /// + [HttpDelete("Delete")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] + [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [Permission("RoleManagement.Write")] + public async Task DeleteeRoleAsync([FromBody] DeleteRoleRequest entity, CancellationToken cancellationToken = default) + { + await deleteRoleHandler.ExecuteAsync(entity, cancellationToken).ConfigureAwait(false); + + return port.ViewModel; + } + /// /// Changes the status of the role. /// @@ -145,7 +167,7 @@ namespace Core.Thalos.Service.API.Controllers [Permission("RoleManagement.Write")] public async Task ChageRoleStatusAsync(ChangeRoleStatusRequest request, CancellationToken cancellationToken) { - if (string.IsNullOrEmpty(request.Id)) { return BadRequest("Invalid role identifier"); } + if (string.IsNullOrEmpty(request._Id)) { return BadRequest("Invalid role mongo identifier"); } await changeStatusRoleHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); @@ -167,7 +189,7 @@ namespace Core.Thalos.Service.API.Controllers [Permission("RoleManagement.Write")] public async Task AddApplicationToRoleAsync(AddApplicationToRoleRequest request, CancellationToken cancellationToken) { - if (string.IsNullOrEmpty(request.RoleId)) { return BadRequest("Invalid role identifier"); } + if (string.IsNullOrEmpty(request.RoleId)) { return BadRequest("Invalid role mongo identifier"); } await addApplicationToRoleHandler.ExecuteAsync(request, cancellationToken); @@ -190,7 +212,7 @@ namespace Core.Thalos.Service.API.Controllers public async Task RemoveApplicationToRoleAsync(RemoveApplicationFromRoleRequest request, CancellationToken cancellationToken) { - if (string.IsNullOrEmpty(request.RoleId)) { return BadRequest("Invalid role identifier"); } + if (string.IsNullOrEmpty(request.RoleId)) { return BadRequest("Invalid role mongo identifier"); } await removeApplicationToRoleHandler.ExecuteAsync(request, cancellationToken); diff --git a/Core.Thalos.Service.API/Controllers/TenantController.cs b/Core.Thalos.Service.API/Controllers/TenantController.cs new file mode 100644 index 0000000..e0075d5 --- /dev/null +++ b/Core.Thalos.Service.API/Controllers/TenantController.cs @@ -0,0 +1,176 @@ +using Asp.Versioning; +using Core.Thalos.Application.UseCases.Tenants.Input; +using Core.Thalos.Application.UseCases.Tenants.Ports; +using Core.Thalos.BuildingBlocks; +using Lib.Architecture.BuildingBlocks; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; + +namespace Core.Thalos.Service.API.Controllers +{ + /// + /// Handles all services and business rules related to . + /// + [ApiVersion("1.0")] + [Route("api/v{api-version:apiVersion}/[controller]")] + [Produces("application/json")] + [ApiController] + [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] + public class TenantController : ControllerBase + { + private readonly IComponentHandler getTenantHandler; + private readonly IComponentHandler getAllTenantsHandler; + private readonly IComponentHandler createTenantHandler; + private readonly IComponentHandler updateTenantHandler; + private readonly IComponentHandler deleteTenantHandler; + private readonly IComponentHandler changeTenantStatusHandler; + private readonly ITenantPort port; + + /// + /// Handles all services and business rules related to . + /// + public TenantController( + IComponentHandler getTenantHandler, + IComponentHandler getAllTenantsHandler, + IComponentHandler createTenantHandler, + IComponentHandler updateTenantHandler, + IComponentHandler deleteTenantHandler, + IComponentHandler changeTenantStatusHandler, + ITenantPort port + ) + { + this.createTenantHandler = createTenantHandler; + this.updateTenantHandler = updateTenantHandler; + this.deleteTenantHandler = deleteTenantHandler; + this.changeTenantStatusHandler = changeTenantStatusHandler; + this.getAllTenantsHandler = getAllTenantsHandler; + this.getTenantHandler = getTenantHandler; + this.port = port; + } + + /// + /// Gets all the Tenants. + /// + [HttpGet("GetAll")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] + [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [Permission("TenantManagement.Read, RoleManagement.Read")] + public async Task GetAllTenantsAsync(CancellationToken cancellationToken) + { + await getAllTenantsHandler.ExecuteAsync(new GetAllTenantsRequest { }, cancellationToken).ConfigureAwait(false); + + return port.ViewModel; + } + + /// + /// Gets the Tenant by mongo identifier. + /// + [HttpPost] + [Route("GetById")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] + [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + [Permission("TenantManagement.Read")] + public async Task GetTenantById([FromBody] GetTenantRequest request, CancellationToken cancellationToken) + { + + if (request._Id == null || !request._Id.Any()) + { + return BadRequest("Invalid Tenant _Id"); + } + + await getTenantHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); + + return port.ViewModel; + } + + /// + /// Creates a new Tenant. + /// + [HttpPost("Create")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] + [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [Permission("TenantManagement.Write")] + public async Task CreateTenantAsync([FromBody] CreateTenantRequest newTenant, CancellationToken cancellationToken = default) + { + await createTenantHandler.ExecuteAsync(newTenant, cancellationToken).ConfigureAwait(false); + + return port.ViewModel; + } + + /// + /// Updates a full Tenant by mongo identifier. + /// + [HttpPut("Update")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] + [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [Permission("TenantManagement.Write")] + public async Task UpdateTenantAsync([FromBody] UpdateTenantRequest request, CancellationToken cancellationToken = default) + { + await updateTenantHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); + + return port.ViewModel; + } + + /// + /// Deletes a full Tenant by mongo identifier. + /// + [HttpDelete("Delete")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] + [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [Permission("TenantManagement.Write")] + public async Task DeleteTenantAsync([FromBody] DeleteTenantRequest request, CancellationToken cancellationToken = default) + { + await deleteTenantHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); + + return port.ViewModel; + } + + /// + /// Changes the status of the Tenant. + /// + [HttpPatch] + [Route("ChangeStatus")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] + [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + [Permission("TenantManagement.Write")] + public async Task ChangeTenantStatusAsync([FromBody] ChangeTenantStatusRequest request, + CancellationToken cancellationToken) + { + if (string.IsNullOrEmpty(request._Id)) { return BadRequest("Invalid Tenant mongo identifier"); } + + await changeTenantStatusHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); + + return port.ViewModel; + } + } +} diff --git a/Core.Thalos.Service.API/Controllers/UserController.cs b/Core.Thalos.Service.API/Controllers/UserController.cs index 8354022..cbed6da 100644 --- a/Core.Thalos.Service.API/Controllers/UserController.cs +++ b/Core.Thalos.Service.API/Controllers/UserController.cs @@ -22,6 +22,7 @@ namespace Core.Thalos.Service.API.Controllers private readonly IComponentHandler getAllUsersHandler; private readonly IComponentHandler createUserHandler; private readonly IComponentHandler updateUserHandler; + private readonly IComponentHandler deleteUserHandler; private readonly IComponentHandler ChangeUserStatusHandler; private readonly IComponentHandler loginUserHandler; private readonly IComponentHandler logoutUserHandler; @@ -38,6 +39,7 @@ namespace Core.Thalos.Service.API.Controllers IComponentHandler getAllUsersHandler, IComponentHandler createUserHandler, IComponentHandler updateUserHandler, + IComponentHandler deleteUserHandler, IComponentHandler changeUserStatusHandler, IComponentHandler loginUserHandler, IComponentHandler logoutUserHandler, @@ -48,6 +50,7 @@ namespace Core.Thalos.Service.API.Controllers { this.createUserHandler = createUserHandler; this.updateUserHandler = updateUserHandler; + this.deleteUserHandler = deleteUserHandler; this.ChangeUserStatusHandler = changeUserStatusHandler; this.getAllUsersHandler = getAllUsersHandler; this.getUserHandler = getUserHandler; @@ -80,7 +83,7 @@ namespace Core.Thalos.Service.API.Controllers } /// - /// Gets the user by identifier. + /// Gets the user by mongo identifier. /// [HttpPost] [Route("GetById")] @@ -95,7 +98,7 @@ namespace Core.Thalos.Service.API.Controllers [Permission("UserManagement.Read")] public async Task GetUserById([FromBody] GetUserRequest request, CancellationToken cancellationToken) { - if (string.IsNullOrEmpty(request.Id)) { return BadRequest("Invalid user identifier"); } + if (string.IsNullOrEmpty(request._Id)) { return BadRequest("Invalid user mongo identifier"); } await getUserHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); @@ -146,7 +149,7 @@ namespace Core.Thalos.Service.API.Controllers } /// - /// Updates a full user by identifier. + /// Updates a full user by mongo identifier. /// [HttpPut("Update")] [ProducesResponseType(StatusCodes.Status200OK)] @@ -166,6 +169,27 @@ namespace Core.Thalos.Service.API.Controllers return port.ViewModel; } + /// + /// Deletes a full user by mongo identifier. + /// + [HttpDelete("Delete")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] + [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] + [Permission("UserManagement.Write")] + public async Task DeleteUserAsync([FromBody] DeleteUserRequest request, + CancellationToken cancellationToken = default) + { + await deleteUserHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); + + return port.ViewModel; + } + /// /// Logs in the user. /// @@ -223,7 +247,7 @@ namespace Core.Thalos.Service.API.Controllers [Permission("UserManagement.Write")] public async Task ChangeUserStatusAsync([FromBody] ChangeUserStatusRequest request, CancellationToken cancellationToken) { - if (string.IsNullOrEmpty(request.Id)) { return BadRequest("Invalid user identifier"); } + if (string.IsNullOrEmpty(request._Id)) { return BadRequest("Invalid user mongo identifier"); } await ChangeUserStatusHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); diff --git a/Core.Thalos.Service.API/Extensions/ServiceCollectionExtension.cs b/Core.Thalos.Service.API/Extensions/ServiceCollectionExtension.cs index 58425d6..3176e0a 100644 --- a/Core.Thalos.Service.API/Extensions/ServiceCollectionExtension.cs +++ b/Core.Thalos.Service.API/Extensions/ServiceCollectionExtension.cs @@ -13,6 +13,11 @@ using Core.Thalos.Application.UseCases.Roles.Adapter; using Core.Thalos.Application.UseCases.Roles.Input; using Core.Thalos.Application.UseCases.Roles.Ports; using Core.Thalos.Application.UseCases.Roles.Validator; +using Core.Thalos.Application.UseCases.Tenants; +using Core.Thalos.Application.UseCases.Tenants.Adapter; +using Core.Thalos.Application.UseCases.Tenants.Input; +using Core.Thalos.Application.UseCases.Tenants.Ports; +using Core.Thalos.Application.UseCases.Tenants.Validator; using Core.Thalos.Application.UseCases.Users; using Core.Thalos.Application.UseCases.Users.Adapter; using Core.Thalos.Application.UseCases.Users.Input; @@ -32,6 +37,7 @@ namespace Core.Thalos.Service.API.Extensions services.AddScoped(); services.AddScoped, UserHandler>(); services.AddScoped, UserHandler>(); + services.AddScoped, UserHandler>(); services.AddScoped, UserHandler>(); services.AddScoped, UserHandler>(); services.AddScoped, UserHandler>(); @@ -58,6 +64,7 @@ namespace Core.Thalos.Service.API.Extensions services.AddScoped(); services.AddScoped, RoleHandler>(); services.AddScoped, RoleHandler>(); + services.AddScoped, RoleHandler>(); services.AddScoped, RoleHandler>(); services.AddScoped, RoleHandler>(); @@ -80,6 +87,7 @@ namespace Core.Thalos.Service.API.Extensions services.AddScoped(); services.AddScoped, PermissionHandler>(); services.AddScoped, PermissionHandler>(); + services.AddScoped, PermissionHandler>(); services.AddScoped, PermissionHandler>(); services.AddValidatorsFromAssemblyContaining(); @@ -101,6 +109,7 @@ namespace Core.Thalos.Service.API.Extensions services.AddScoped(); services.AddScoped, ModuleHandler>(); services.AddScoped, ModuleHandler>(); + services.AddScoped, ModuleHandler>(); services.AddValidatorsFromAssemblyContaining(); services.AddScoped, GetAllModulesByListValidator>(); @@ -120,6 +129,27 @@ namespace Core.Thalos.Service.API.Extensions #endregion + #region Tenant Services + + services.AddScoped(); + services.AddScoped, TenantHandler>(); + services.AddScoped, TenantHandler>(); + services.AddScoped, TenantHandler>(); + + services.AddValidatorsFromAssemblyContaining(); + services.AddScoped, CreateTenantValidator>(); + services.AddScoped, TenantHandler>(); + + services.AddValidatorsFromAssemblyContaining(); + services.AddScoped, UpdateTenantValidator>(); + services.AddScoped, TenantHandler>(); + + services.AddValidatorsFromAssemblyContaining(); + services.AddScoped, ChangeTenantStatusValidator>(); + services.AddScoped, TenantHandler>(); + + #endregion + return services; } }