Add tenant services, change id by _id and include delete endpoint for all entities
This commit is contained in:
parent
f3d63ca0e3
commit
296aff13fe
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -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.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -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.");
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -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.");
|
||||
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
|
||||
namespace Core.Thalos.Application.UseCases.Tenants.Input
|
||||
{
|
||||
public class GetAllTenantsRequest : ICommand
|
||||
{
|
||||
public bool Validate()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
{
|
||||
}
|
||||
}
|
||||
223
Core.Thalos.Application/UseCases/Tenants/TenantHandler.cs
Normal file
223
Core.Thalos.Application/UseCases/Tenants/TenantHandler.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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; }
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
@ -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.");
|
||||
}
|
||||
|
||||
|
||||
@ -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.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -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.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ namespace Core.Thalos.External.Clients
|
||||
Task<IEnumerable<UserAdapter>> GetAllUsersAsync(CancellationToken cancellationToken = default);
|
||||
|
||||
[Get("/v1/User/" + Routes.Id)]
|
||||
Task<UserAdapter> GetUserByIdAsync([FromRoute] string id, CancellationToken cancellationToken = default);
|
||||
Task<UserAdapter> GetUserByIdAsync([FromRoute] string _id, CancellationToken cancellationToken = default);
|
||||
|
||||
[Get("/v1/User/" + Routes.Email)]
|
||||
Task<UserAdapter> GetUserByEmailAsync([FromRoute] string email, CancellationToken cancellationToken = default);
|
||||
@ -23,7 +23,10 @@ namespace Core.Thalos.External.Clients
|
||||
Task<UserAdapter> CreateUserAsync([FromBody] UserRequest newUser, [FromRoute] bool sendInvitation, CancellationToken cancellationToken = default);
|
||||
|
||||
[Put("/v1/User/" + Routes.Id)]
|
||||
Task<UserAdapter> UpdateUserAsync([FromBody] UserAdapter entity, [FromRoute] string id, CancellationToken cancellationToken = default);
|
||||
Task<UserAdapter> UpdateUserAsync([FromBody] UserAdapter entity, [FromRoute] string _id, CancellationToken cancellationToken = default);
|
||||
|
||||
[Delete("/v1/User/" + Routes.Id)]
|
||||
Task<UserAdapter> DeleteUserAsync([FromRoute] string _id, CancellationToken cancellationToken = default);
|
||||
|
||||
[Patch("/v1/User/" + Routes.LogIn)]
|
||||
Task<UserAdapter> LoginUserAsync([FromRoute] string email, CancellationToken cancellationToken = default);
|
||||
@ -32,7 +35,7 @@ namespace Core.Thalos.External.Clients
|
||||
Task<UserAdapter> LogoutUserAsync([FromRoute] string email, CancellationToken cancellationToken = default);
|
||||
|
||||
[Patch("/v1/User/" + Routes.ChangeStatus)]
|
||||
Task<UserAdapter> ChangeUserStatusAsync([FromRoute] string id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken = default);
|
||||
Task<UserAdapter> ChangeUserStatusAsync([FromRoute] string _id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken = default);
|
||||
|
||||
[Get("/v1/User/{email}/GetTokenAdapter")]
|
||||
Task<TokenAdapter> GetTokenAdapter([FromRoute] string email, CancellationToken cancellationToken = default);
|
||||
@ -41,16 +44,19 @@ namespace Core.Thalos.External.Clients
|
||||
Task<IEnumerable<RoleAdapter>> GetAllRolesAsync(CancellationToken cancellationToken = default);
|
||||
|
||||
[Get("/v1/Role/" + Routes.Id)]
|
||||
Task<RoleAdapter> GetRoleByIdAsync([FromRoute] string id, CancellationToken cancellationToken = default);
|
||||
Task<RoleAdapter> GetRoleByIdAsync([FromRoute] string _id, CancellationToken cancellationToken = default);
|
||||
|
||||
[Post("/v1/Role")]
|
||||
Task<RoleAdapter> CreateRoleAsync([FromBody] RoleRequest newRole, CancellationToken cancellationToken = default);
|
||||
|
||||
[Put("/v1/Role/" + Routes.Id)]
|
||||
Task<RoleAdapter> UpdateRoleAsync([FromBody] RoleAdapter entity, [FromRoute] string id, CancellationToken cancellationToken = default);
|
||||
Task<RoleAdapter> UpdateRoleAsync([FromBody] RoleAdapter entity, [FromRoute] string _id, CancellationToken cancellationToken = default);
|
||||
|
||||
[Delete("/v1/Role/" + Routes.Id)]
|
||||
Task<RoleAdapter> DeleteRoleAsync([FromRoute] string _id, CancellationToken cancellationToken = default);
|
||||
|
||||
[Patch("/v1/Role/" + Routes.ChangeStatus)]
|
||||
Task<RoleAdapter> ChangeRoleStatusAsync([FromRoute] string id, [FromRoute] Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken = default);
|
||||
Task<RoleAdapter> ChangeRoleStatusAsync([FromRoute] string _id, [FromRoute] Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken = default);
|
||||
|
||||
[Post("/v1/Role/" + Routes.AddApplication)]
|
||||
Task<RoleAdapter> AddApplicationToRoleAsync([FromRoute] string RoleId, [FromRoute] ApplicationsEnum application, CancellationToken cancellationToken = default);
|
||||
@ -65,16 +71,19 @@ namespace Core.Thalos.External.Clients
|
||||
Task<IEnumerable<PermissionAdapter>> GetAllPermissionsByListAsync([FromBody] string[] request, CancellationToken cancellationToken = default);
|
||||
|
||||
[Get("/v1/Permission/" + Routes.Id)]
|
||||
Task<PermissionAdapter> GetPermissionByIdAsync([FromRoute] string id, CancellationToken cancellationToken = default);
|
||||
Task<PermissionAdapter> GetPermissionByIdAsync([FromRoute] string _id, CancellationToken cancellationToken = default);
|
||||
|
||||
[Post("/v1/Permission")]
|
||||
Task<PermissionAdapter> CreatePermissionAsync([FromBody] PermissionRequest newPermission, CancellationToken cancellationToken = default);
|
||||
|
||||
[Put("/v1/Permission/" + Routes.Id)]
|
||||
Task<PermissionAdapter> UpdatePermissionAsync([FromBody] PermissionAdapter entity, [FromRoute] string id, CancellationToken cancellationToken = default);
|
||||
Task<PermissionAdapter> UpdatePermissionAsync([FromBody] PermissionAdapter entity, [FromRoute] string _id, CancellationToken cancellationToken = default);
|
||||
|
||||
[Delete("/v1/Permission/" + Routes.Id)]
|
||||
Task<PermissionAdapter> DeletePermissionAsync([FromRoute] string _id, CancellationToken cancellationToken = default);
|
||||
|
||||
[Patch("/v1/Permission/" + Routes.ChangeStatus)]
|
||||
Task<PermissionAdapter> ChangeStatusPermissionAsync([FromRoute] string id, [FromRoute] Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken = default);
|
||||
Task<PermissionAdapter> ChangeStatusPermissionAsync([FromRoute] string _id, [FromRoute] Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken = default);
|
||||
|
||||
[Get("/v1/Module")]
|
||||
Task<IEnumerable<ModuleAdapter>> GetAllModulesAsync(CancellationToken cancellationToken = default);
|
||||
@ -83,15 +92,36 @@ namespace Core.Thalos.External.Clients
|
||||
Task<IEnumerable<ModuleAdapter>> GetAllModulesByListAsync([FromBody] string[] request, CancellationToken cancellationToken = default);
|
||||
|
||||
[Get("/v1/Module/" + Routes.Id)]
|
||||
Task<ModuleAdapter> GetModuleByIdAsync([FromRoute] string id, CancellationToken cancellationToken = default);
|
||||
Task<ModuleAdapter> GetModuleByIdAsync([FromRoute] string _id, CancellationToken cancellationToken = default);
|
||||
|
||||
[Post("/v1/Module")]
|
||||
Task<ModuleAdapter> CreateModuleAsync([FromBody] ModuleRequest newModule, CancellationToken cancellationToken = default);
|
||||
|
||||
[Put("/v1/Module/" + Routes.Id)]
|
||||
Task<ModuleAdapter> UpdateModuleAsync([FromBody] ModuleAdapter entity, [FromRoute] string id, CancellationToken cancellationToken = default);
|
||||
Task<ModuleAdapter> UpdateModuleAsync([FromBody] ModuleAdapter entity, [FromRoute] string _id, CancellationToken cancellationToken = default);
|
||||
|
||||
[Delete("/v1/Module/" + Routes.Id)]
|
||||
Task<ModuleAdapter> DeleteModuleAsync([FromRoute] string _id, CancellationToken cancellationToken = default);
|
||||
|
||||
[Patch("/v1/Module/" + Routes.ChangeStatus)]
|
||||
Task<ModuleAdapter> ChangeStatusModuleAsync([FromRoute] string id, [FromRoute] Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken = default);
|
||||
Task<ModuleAdapter> ChangeStatusModuleAsync([FromRoute] string _id, [FromRoute] Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken = default);
|
||||
|
||||
[Get("/v1/Tenant")]
|
||||
Task<IEnumerable<TenantAdapter>> GetAllTenantsAsync(CancellationToken cancellationToken = default);
|
||||
|
||||
[Get("/v1/Tenant/" + Routes.Id)]
|
||||
Task<TenantAdapter> GetTenantByIdAsync([FromRoute] string _id, CancellationToken cancellationToken = default);
|
||||
|
||||
[Post("/v1/Tenant")]
|
||||
Task<TenantAdapter> CreateTenantAsync([FromBody] TenantRequest newTenant, CancellationToken cancellationToken = default);
|
||||
|
||||
[Put("/v1/Tenant/" + Routes.Id)]
|
||||
Task<TenantAdapter> UpdateTenantAsync([FromBody] TenantAdapter entity, [FromRoute] string _id, CancellationToken cancellationToken = default);
|
||||
|
||||
[Patch("/v1/Tenant/" + Routes.ChangeStatus)]
|
||||
Task<TenantAdapter> ChangeStatusTenantAsync([FromRoute] string _id, [FromRoute] Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken = default);
|
||||
|
||||
[Delete("/v1/Tenant/" + Routes.Id)]
|
||||
Task<TenantAdapter> DeleteTenantAsync([FromRoute] string _id, CancellationToken cancellationToken = default);
|
||||
}
|
||||
}
|
||||
|
||||
53
Core.Thalos.External/Clients/Requests/TenantRequest.cs
Normal file
53
Core.Thalos.External/Clients/Requests/TenantRequest.cs
Normal file
@ -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; }
|
||||
}
|
||||
|
||||
}
|
||||
@ -8,7 +8,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Core.Blueprint.Storage" Version="1.0.1" />
|
||||
<PackageReference Include="Core.Thalos.BuildingBlocks" Version="1.0.8" />
|
||||
<PackageReference Include="Core.Thalos.BuildingBlocks" Version="1.1.2" />
|
||||
<PackageReference Include="Lib.Architecture.BuildingBlocks" Version="1.0.0" />
|
||||
<PackageReference Include="Refit" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
@ -3,7 +3,6 @@ using Core.Thalos.Application.UseCases.Modules.Input;
|
||||
using Core.Thalos.Application.UseCases.Modules.Ports;
|
||||
using Core.Thalos.BuildingBlocks;
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Core.Thalos.Service.API.Controllers
|
||||
@ -15,7 +14,7 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
[Route("api/v{api-version:apiVersion}/[controller]")]
|
||||
[Produces("application/json")]
|
||||
[ApiController]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
public class ModuleController : ControllerBase
|
||||
{
|
||||
private readonly IComponentHandler<GetModuleRequest> getModuleHandler;
|
||||
@ -23,6 +22,7 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
private readonly IComponentHandler<GetAllModulesByListRequest> getAllModulesByListHandler;
|
||||
private readonly IComponentHandler<CreateModuleRequest> createModuleHandler;
|
||||
private readonly IComponentHandler<UpdateModuleRequest> updateModuleHandler;
|
||||
private readonly IComponentHandler<DeleteModuleRequest> deleteModuleHandler;
|
||||
private readonly IComponentHandler<ChangeModuleStatusRequest> changeModuleStatusHandler;
|
||||
private readonly IModulePort port;
|
||||
|
||||
@ -35,12 +35,14 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
IComponentHandler<GetAllModulesByListRequest> getAllModulesByListHandler,
|
||||
IComponentHandler<CreateModuleRequest> createModuleHandler,
|
||||
IComponentHandler<UpdateModuleRequest> updateModuleHandler,
|
||||
IComponentHandler<DeleteModuleRequest> deleteModuleHandler,
|
||||
IComponentHandler<ChangeModuleStatusRequest> changeModuleStatusHandler,
|
||||
IModulePort port
|
||||
)
|
||||
{
|
||||
this.createModuleHandler = createModuleHandler;
|
||||
this.updateModuleHandler = updateModuleHandler;
|
||||
this.deleteModuleHandler = deleteModuleHandler;
|
||||
this.changeModuleStatusHandler = changeModuleStatusHandler;
|
||||
this.getAllModulesHandler = getAllModulesHandler;
|
||||
this.getModuleHandler = getModuleHandler;
|
||||
@ -59,7 +61,7 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[Permission("ModuleManagement.Read, RoleManagement.Read")]
|
||||
//[Permission("ModuleManagement.Read, RoleManagement.Read")]
|
||||
public async Task<IActionResult> GetAllModulesAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
await getAllModulesHandler.ExecuteAsync(new GetAllModulesRequest { }, cancellationToken).ConfigureAwait(false);
|
||||
@ -89,7 +91,7 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
[Permission("ModuleManagement.Read")]
|
||||
//[Permission("ModuleManagement.Read")]
|
||||
public async Task<IActionResult> GetAllModulesByListAsync([FromBody] GetAllModulesByListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
@ -104,7 +106,7 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the module by identifier.
|
||||
/// Gets the module by mongo identifier.
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
[Route("GetById")]
|
||||
@ -115,13 +117,13 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
[Permission("ModuleManagement.Read")]
|
||||
//[Permission("ModuleManagement.Read")]
|
||||
public async Task<IActionResult> 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);
|
||||
@ -140,7 +142,7 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[Permission("ModuleManagement.Write")]
|
||||
//[Permission("ModuleManagement.Write")]
|
||||
public async Task<IActionResult> CreateModuleAsync([FromBody] CreateModuleRequest newModule, CancellationToken cancellationToken = default)
|
||||
{
|
||||
await createModuleHandler.ExecuteAsync(newModule, cancellationToken).ConfigureAwait(false);
|
||||
@ -149,7 +151,7 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates a full module by identifier.
|
||||
/// Updates a full module by mongo identifier.
|
||||
/// </summary>
|
||||
[HttpPut("Update")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
@ -159,7 +161,7 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[Permission("ModuleManagement.Write")]
|
||||
//[Permission("ModuleManagement.Write")]
|
||||
public async Task<IActionResult> UpdateModuleAsync([FromBody] UpdateModuleRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
await updateModuleHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
@ -167,6 +169,25 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
return port.ViewModel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a full module by mongo identifier.
|
||||
/// </summary>
|
||||
[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<IActionResult> DeleteModuleAsync([FromBody] DeleteModuleRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
await deleteModuleHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
return port.ViewModel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes the status of the module.
|
||||
/// </summary>
|
||||
@ -179,11 +200,11 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
[Permission("ModuleManagement.Write")]
|
||||
//[Permission("ModuleManagement.Write")]
|
||||
public async Task<IActionResult> 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);
|
||||
|
||||
|
||||
@ -3,7 +3,6 @@ using Core.Thalos.Application.UseCases.Permissions.Input;
|
||||
using Core.Thalos.Application.UseCases.Permissions.Ports;
|
||||
using Core.Thalos.BuildingBlocks;
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Core.Thalos.Service.API.Controllers
|
||||
@ -15,7 +14,7 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
[Route("api/v{api-version:apiVersion}/[controller]")]
|
||||
[Produces("application/json")]
|
||||
[ApiController]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
public class PermissionController : ControllerBase
|
||||
{
|
||||
private readonly IComponentHandler<GetPermissionRequest> getPermissionHandler;
|
||||
@ -23,6 +22,7 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
private readonly IComponentHandler<GetAllPermissionsByListRequest> getAllPermissionsByListHandler;
|
||||
private readonly IComponentHandler<CreatePermissionRequest> createPermissionHandler;
|
||||
private readonly IComponentHandler<UpdatePermissionRequest> updatePermissionHandler;
|
||||
private readonly IComponentHandler<DeletePermissionRequest> deletePermissionHandler;
|
||||
private readonly IComponentHandler<ChangePermissionStatusRequest> changePermissionStatusHandler;
|
||||
private readonly IPermissionPort port;
|
||||
|
||||
@ -35,12 +35,14 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
IComponentHandler<GetAllPermissionsByListRequest> getAllPermissionsByListHandler,
|
||||
IComponentHandler<CreatePermissionRequest> createPermissionHandler,
|
||||
IComponentHandler<UpdatePermissionRequest> updatePermissionHandler,
|
||||
IComponentHandler<DeletePermissionRequest> deletePermissionHandler,
|
||||
IComponentHandler<ChangePermissionStatusRequest> changePermissionStatusHandler,
|
||||
IPermissionPort port
|
||||
)
|
||||
{
|
||||
this.createPermissionHandler = createPermissionHandler;
|
||||
this.updatePermissionHandler = updatePermissionHandler;
|
||||
this.deletePermissionHandler = deletePermissionHandler;
|
||||
this.changePermissionStatusHandler = changePermissionStatusHandler;
|
||||
this.getAllPermissionsHandler = getAllPermissionsHandler;
|
||||
this.getPermissionHandler = getPermissionHandler;
|
||||
@ -59,7 +61,7 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[Permission("PermissionManagement.Read, RoleManagement.Read")]
|
||||
//[Permission("PermissionManagement.Read, RoleManagement.Read")]
|
||||
public async Task<IActionResult> GetAllPermissionsAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
await getAllPermissionsHandler.ExecuteAsync(new GetAllPermissionsRequest { }, cancellationToken).ConfigureAwait(false);
|
||||
@ -89,7 +91,7 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
[Permission("PermissionManagement.Read")]
|
||||
//[Permission("PermissionManagement.Read")]
|
||||
public async Task<IActionResult> GetAllPermissionsByListAsync([FromBody] GetAllPermissionsByListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
@ -104,7 +106,7 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the permission by identifier.
|
||||
/// Gets the permission by mongo identifier.
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
[Route("GetById")]
|
||||
@ -115,13 +117,13 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
[Permission("PermissionManagement.Read")]
|
||||
//[Permission("PermissionManagement.Read")]
|
||||
public async Task<IActionResult> 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);
|
||||
@ -140,7 +142,7 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[Permission("PermissionManagement.Write")]
|
||||
//[Permission("PermissionManagement.Write")]
|
||||
public async Task<IActionResult> CreatePermissionAsync([FromBody] CreatePermissionRequest newPermission, CancellationToken cancellationToken = default)
|
||||
{
|
||||
await createPermissionHandler.ExecuteAsync(newPermission, cancellationToken).ConfigureAwait(false);
|
||||
@ -149,7 +151,7 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates a full permission by identifier.
|
||||
/// Updates a full permission by mongo identifier.
|
||||
/// </summary>
|
||||
[HttpPut("Update")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
@ -159,7 +161,7 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[Permission("PermissionManagement.Write")]
|
||||
//[Permission("PermissionManagement.Write")]
|
||||
public async Task<IActionResult> UpdatePermissionAsync([FromBody] UpdatePermissionRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
await updatePermissionHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
@ -167,6 +169,25 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
return port.ViewModel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a full permission by mongo identifier.
|
||||
/// </summary>
|
||||
[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<IActionResult> DeletePermissionAsync([FromBody] DeletePermissionRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
await deletePermissionHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
return port.ViewModel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes the status of the permission.
|
||||
/// </summary>
|
||||
@ -179,11 +200,11 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
[Permission("PermissionManagement.Write")]
|
||||
//[Permission("PermissionManagement.Write")]
|
||||
public async Task<IActionResult> 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);
|
||||
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
using Asp.Versioning;
|
||||
using Core.Thalos.Application.UseCases.Roles.Input;
|
||||
using Core.Thalos.Application.UseCases.Roles.Ports;
|
||||
using Core.Thalos.BuildingBlocks;
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Core.Thalos.Service.API.Controllers
|
||||
@ -15,13 +13,14 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
[Route("api/v{api-version:apiVersion}/[controller]")]
|
||||
[Produces("application/json")]
|
||||
[ApiController]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
public class RoleController : ControllerBase
|
||||
{
|
||||
private readonly IComponentHandler<GetRoleRequest> getRoleHandler;
|
||||
private readonly IComponentHandler<GetAllRolesRequest> getAllRolesHandler;
|
||||
private readonly IComponentHandler<CreateRoleRequest> createRoleHandler;
|
||||
private readonly IComponentHandler<UpdateRoleRequest> updateRoleHandler;
|
||||
private readonly IComponentHandler<DeleteRoleRequest> deleteRoleHandler;
|
||||
private readonly IComponentHandler<ChangeRoleStatusRequest> changeStatusRoleHandler;
|
||||
private readonly IComponentHandler<AddApplicationToRoleRequest> addApplicationToRoleHandler;
|
||||
private readonly IComponentHandler<RemoveApplicationFromRoleRequest> removeApplicationToRoleHandler;
|
||||
@ -35,6 +34,7 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
IComponentHandler<GetAllRolesRequest> getAllRolesHandler,
|
||||
IComponentHandler<CreateRoleRequest> createRoleHandler,
|
||||
IComponentHandler<UpdateRoleRequest> updateRoleHandler,
|
||||
IComponentHandler<DeleteRoleRequest> deleteRoleHandler,
|
||||
IComponentHandler<ChangeRoleStatusRequest> changeRoleStatusHandler,
|
||||
IComponentHandler<AddApplicationToRoleRequest> addApplicationToRoleHandler,
|
||||
IComponentHandler<RemoveApplicationFromRoleRequest> removeApplicationToRoleHandler,
|
||||
@ -43,6 +43,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;
|
||||
@ -62,7 +63,7 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[Permission("RoleManagement.Read")]
|
||||
//[Permission("RoleManagement.Read")]
|
||||
public async Task<IActionResult> GetAllRolesAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
await getAllRolesHandler.ExecuteAsync(new GetAllRolesRequest { }, cancellationToken).ConfigureAwait(false);
|
||||
@ -71,7 +72,7 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the role by identifier.
|
||||
/// Gets the role by mongo identifier.
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
[Route("GetById")]
|
||||
@ -82,10 +83,10 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
[Permission("RoleManagement.Read")]
|
||||
//[Permission("RoleManagement.Read")]
|
||||
public async Task<IActionResult> 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);
|
||||
|
||||
@ -103,7 +104,7 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[Permission("RoleManagement.Write")]
|
||||
//[Permission("RoleManagement.Write")]
|
||||
public async Task<IActionResult> CreateRoleAsync([FromBody] CreateRoleRequest newRole, CancellationToken cancellationToken = default)
|
||||
{
|
||||
await createRoleHandler.ExecuteAsync(newRole, cancellationToken).ConfigureAwait(false);
|
||||
@ -112,7 +113,7 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates a full role by identifier.
|
||||
/// Updates a full role by mongo identifier.
|
||||
/// </summary>
|
||||
[HttpPut("Update")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
@ -122,7 +123,7 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[Permission("RoleManagement.Write")]
|
||||
//[Permission("RoleManagement.Write")]
|
||||
public async Task<IActionResult> UpdateRoleAsync([FromBody] UpdateRoleRequest entity, CancellationToken cancellationToken = default)
|
||||
{
|
||||
await updateRoleHandler.ExecuteAsync(entity, cancellationToken).ConfigureAwait(false);
|
||||
@ -130,6 +131,25 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
return port.ViewModel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a full role by mongo identifier.
|
||||
/// </summary>
|
||||
[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<IActionResult> DeleteeRoleAsync([FromBody] DeleteRoleRequest entity, CancellationToken cancellationToken = default)
|
||||
{
|
||||
await deleteRoleHandler.ExecuteAsync(entity, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
return port.ViewModel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes the status of the role.
|
||||
/// </summary>
|
||||
@ -142,10 +162,10 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
[Permission("RoleManagement.Write")]
|
||||
//[Permission("RoleManagement.Write")]
|
||||
public async Task<IActionResult> 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);
|
||||
|
||||
@ -164,10 +184,10 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
[Permission("RoleManagement.Write")]
|
||||
//[Permission("RoleManagement.Write")]
|
||||
public async Task<IActionResult> 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);
|
||||
|
||||
@ -186,11 +206,11 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
[Permission("RoleManagement.Write")]
|
||||
//[Permission("RoleManagement.Write")]
|
||||
public async Task<IActionResult> 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);
|
||||
|
||||
|
||||
174
Core.Thalos.Service.API/Controllers/TenantController.cs
Normal file
174
Core.Thalos.Service.API/Controllers/TenantController.cs
Normal file
@ -0,0 +1,174 @@
|
||||
using Asp.Versioning;
|
||||
using Core.Thalos.Application.UseCases.Tenants.Input;
|
||||
using Core.Thalos.Application.UseCases.Tenants.Ports;
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Core.Thalos.Service.API.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles all services and business rules related to <see cref="TenantController"/>.
|
||||
/// </summary>
|
||||
[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<GetTenantRequest> getTenantHandler;
|
||||
private readonly IComponentHandler<GetAllTenantsRequest> getAllTenantsHandler;
|
||||
private readonly IComponentHandler<CreateTenantRequest> createTenantHandler;
|
||||
private readonly IComponentHandler<UpdateTenantRequest> updateTenantHandler;
|
||||
private readonly IComponentHandler<DeleteTenantRequest> deleteTenantHandler;
|
||||
private readonly IComponentHandler<ChangeTenantStatusRequest> changeTenantStatusHandler;
|
||||
private readonly ITenantPort port;
|
||||
|
||||
/// <summary>
|
||||
/// Handles all services and business rules related to <see cref="TenantController"/>.
|
||||
/// </summary>
|
||||
public TenantController(
|
||||
IComponentHandler<GetTenantRequest> getTenantHandler,
|
||||
IComponentHandler<GetAllTenantsRequest> getAllTenantsHandler,
|
||||
IComponentHandler<CreateTenantRequest> createTenantHandler,
|
||||
IComponentHandler<UpdateTenantRequest> updateTenantHandler,
|
||||
IComponentHandler<DeleteTenantRequest> deleteTenantHandler,
|
||||
IComponentHandler<ChangeTenantStatusRequest> changeTenantStatusHandler,
|
||||
ITenantPort port
|
||||
)
|
||||
{
|
||||
this.createTenantHandler = createTenantHandler;
|
||||
this.updateTenantHandler = updateTenantHandler;
|
||||
this.deleteTenantHandler = deleteTenantHandler;
|
||||
this.changeTenantStatusHandler = changeTenantStatusHandler;
|
||||
this.getAllTenantsHandler = getAllTenantsHandler;
|
||||
this.getTenantHandler = getTenantHandler;
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the Tenants.
|
||||
/// </summary>
|
||||
[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<IActionResult> GetAllTenantsAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
await getAllTenantsHandler.ExecuteAsync(new GetAllTenantsRequest { }, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
return port.ViewModel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Tenant by mongo identifier.
|
||||
/// </summary>
|
||||
[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<IActionResult> 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new Tenant.
|
||||
/// </summary>
|
||||
[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<IActionResult> CreateTenantAsync([FromBody] CreateTenantRequest newTenant, CancellationToken cancellationToken = default)
|
||||
{
|
||||
await createTenantHandler.ExecuteAsync(newTenant, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
return port.ViewModel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates a full Tenant by mongo identifier.
|
||||
/// </summary>
|
||||
[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<IActionResult> UpdateTenantAsync([FromBody] UpdateTenantRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
await updateTenantHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
return port.ViewModel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a full Tenant by mongo identifier.
|
||||
/// </summary>
|
||||
[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<IActionResult> DeleteTenantAsync([FromBody] DeleteTenantRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
await deleteTenantHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
return port.ViewModel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes the status of the Tenant.
|
||||
/// </summary>
|
||||
[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<IActionResult> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -22,6 +22,7 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
private readonly IComponentHandler<GetAllUsersRequest> getAllUsersHandler;
|
||||
private readonly IComponentHandler<CreateUserRequest> createUserHandler;
|
||||
private readonly IComponentHandler<UpdateUserRequest> updateUserHandler;
|
||||
private readonly IComponentHandler<DeleteUserRequest> deleteUserHandler;
|
||||
private readonly IComponentHandler<ChangeUserStatusRequest> ChangeUserStatusHandler;
|
||||
private readonly IComponentHandler<LoginUserRequest> loginUserHandler;
|
||||
private readonly IComponentHandler<LogoutUserRequest> logoutUserHandler;
|
||||
@ -38,6 +39,7 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
IComponentHandler<GetAllUsersRequest> getAllUsersHandler,
|
||||
IComponentHandler<CreateUserRequest> createUserHandler,
|
||||
IComponentHandler<UpdateUserRequest> updateUserHandler,
|
||||
IComponentHandler<DeleteUserRequest> deleteUserHandler,
|
||||
IComponentHandler<ChangeUserStatusRequest> changeUserStatusHandler,
|
||||
IComponentHandler<LoginUserRequest> loginUserHandler,
|
||||
IComponentHandler<LogoutUserRequest> 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;
|
||||
@ -70,8 +73,8 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
[Permission("UserManagement.Read")]
|
||||
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
//[Permission("UserManagement.Read")]
|
||||
public async Task<IActionResult> GetAllUsersAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
await getAllUsersHandler.ExecuteAsync(new GetAllUsersRequest { }, cancellationToken).ConfigureAwait(false);
|
||||
@ -80,7 +83,7 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the user by identifier.
|
||||
/// Gets the user by mongo identifier.
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
[Route("GetById")]
|
||||
@ -91,11 +94,11 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
[Permission("UserManagement.Read")]
|
||||
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
//[Permission("UserManagement.Read")]
|
||||
public async Task<IActionResult> 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);
|
||||
|
||||
@ -114,7 +117,7 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
[Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.GoogleScheme}")]
|
||||
//[Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.GoogleScheme}")]
|
||||
public async Task<IActionResult> GetUserByEmail([FromBody] GetUserByEmailRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
if (string.IsNullOrEmpty(request.Email)) { return BadRequest("Invalid user email"); }
|
||||
@ -136,8 +139,8 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
[Permission("UserManagement.Write")]
|
||||
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
//[Permission("UserManagement.Write")]
|
||||
public async Task<IActionResult> CreateUserAsync([FromBody] CreateUserRequest newUser, CancellationToken cancellationToken = default)
|
||||
{
|
||||
await createUserHandler.ExecuteAsync(newUser, cancellationToken).ConfigureAwait(false);
|
||||
@ -146,7 +149,7 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates a full user by identifier.
|
||||
/// Updates a full user by mongo identifier.
|
||||
/// </summary>
|
||||
[HttpPut("Update")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
@ -156,8 +159,8 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
[Permission("UserManagement.Write")]
|
||||
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
//[Permission("UserManagement.Write")]
|
||||
public async Task<IActionResult> UpdateUserAsync([FromBody] UpdateUserRequest request,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
@ -166,6 +169,27 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
return port.ViewModel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a full user by mongo identifier.
|
||||
/// </summary>
|
||||
[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<IActionResult> DeleteUserAsync([FromBody] DeleteUserRequest request,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
await deleteUserHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
return port.ViewModel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Logs in the user.
|
||||
/// </summary>
|
||||
@ -177,7 +201,7 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
[Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.GoogleScheme}")]
|
||||
//[Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.GoogleScheme}")]
|
||||
public async Task<IActionResult> LoginUserAsync([FromBody] LoginUserRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
if (string.IsNullOrEmpty(request.Email)) { return BadRequest("Invalid user email"); }
|
||||
@ -219,11 +243,11 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
[Permission("UserManagement.Write")]
|
||||
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
//[Permission("UserManagement.Write")]
|
||||
public async Task<IActionResult> 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);
|
||||
|
||||
@ -258,7 +282,7 @@ namespace Core.Thalos.Service.API.Controllers
|
||||
[HttpPost]
|
||||
[Route("GetTokenAdapter")]
|
||||
[ProducesResponseType(typeof(TokenAdapter), StatusCodes.Status200OK)]
|
||||
[Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.GoogleScheme}")]
|
||||
//[Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.GoogleScheme}")]
|
||||
public async Task<IActionResult> GetTokenAdapter([FromBody] GetTokenAdapterRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
if (string.IsNullOrEmpty(request.Email)) { return BadRequest("Invalid user email"); }
|
||||
|
||||
@ -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<IUserPort, UserPort>();
|
||||
services.AddScoped<IComponentHandler<GetAllUsersRequest>, UserHandler>();
|
||||
services.AddScoped<IComponentHandler<GetUserRequest>, UserHandler>();
|
||||
services.AddScoped<IComponentHandler<DeleteUserRequest>, UserHandler>();
|
||||
services.AddScoped<IComponentHandler<LoginUserRequest>, UserHandler>();
|
||||
services.AddScoped<IComponentHandler<LogoutUserRequest>, UserHandler>();
|
||||
services.AddScoped<IComponentHandler<GetUserByEmailRequest>, UserHandler>();
|
||||
@ -58,6 +64,7 @@ namespace Core.Thalos.Service.API.Extensions
|
||||
services.AddScoped<IRolePort, RolePort>();
|
||||
services.AddScoped<IComponentHandler<GetAllRolesRequest>, RoleHandler>();
|
||||
services.AddScoped<IComponentHandler<GetRoleRequest>, RoleHandler>();
|
||||
services.AddScoped<IComponentHandler<DeleteRoleRequest>, RoleHandler>();
|
||||
services.AddScoped<IComponentHandler<AddApplicationToRoleRequest>, RoleHandler>();
|
||||
services.AddScoped<IComponentHandler<RemoveApplicationFromRoleRequest>, RoleHandler>();
|
||||
|
||||
@ -80,6 +87,7 @@ namespace Core.Thalos.Service.API.Extensions
|
||||
services.AddScoped<IPermissionPort, PermissionPort>();
|
||||
services.AddScoped<IComponentHandler<GetAllPermissionsRequest>, PermissionHandler>();
|
||||
services.AddScoped<IComponentHandler<GetPermissionRequest>, PermissionHandler>();
|
||||
services.AddScoped<IComponentHandler<DeletePermissionRequest>, PermissionHandler>();
|
||||
services.AddScoped<IComponentHandler<GetAllPermissionsByListRequest>, PermissionHandler>();
|
||||
|
||||
services.AddValidatorsFromAssemblyContaining<CreatePermissionValidator>();
|
||||
@ -101,6 +109,7 @@ namespace Core.Thalos.Service.API.Extensions
|
||||
services.AddScoped<IModulePort, ModulePort>();
|
||||
services.AddScoped<IComponentHandler<GetAllModulesRequest>, ModuleHandler>();
|
||||
services.AddScoped<IComponentHandler<GetModuleRequest>, ModuleHandler>();
|
||||
services.AddScoped<IComponentHandler<DeleteModuleRequest>, ModuleHandler>();
|
||||
|
||||
services.AddValidatorsFromAssemblyContaining<GetAllModulesByListValidator>();
|
||||
services.AddScoped<IValidator<GetAllModulesByListRequest>, GetAllModulesByListValidator>();
|
||||
@ -120,6 +129,27 @@ namespace Core.Thalos.Service.API.Extensions
|
||||
|
||||
#endregion
|
||||
|
||||
#region Tenant Services
|
||||
|
||||
services.AddScoped<ITenantPort, TenantPort>();
|
||||
services.AddScoped<IComponentHandler<GetAllTenantsRequest>, TenantHandler>();
|
||||
services.AddScoped<IComponentHandler<GetTenantRequest>, TenantHandler>();
|
||||
services.AddScoped<IComponentHandler<DeleteTenantRequest>, TenantHandler>();
|
||||
|
||||
services.AddValidatorsFromAssemblyContaining<CreateTenantValidator>();
|
||||
services.AddScoped<IValidator<CreateTenantRequest>, CreateTenantValidator>();
|
||||
services.AddScoped<IComponentHandler<CreateTenantRequest>, TenantHandler>();
|
||||
|
||||
services.AddValidatorsFromAssemblyContaining<UpdateTenantValidator>();
|
||||
services.AddScoped<IValidator<UpdateTenantRequest>, UpdateTenantValidator>();
|
||||
services.AddScoped<IComponentHandler<UpdateTenantRequest>, TenantHandler>();
|
||||
|
||||
services.AddValidatorsFromAssemblyContaining<ChangeTenantStatusValidator>();
|
||||
services.AddScoped<IValidator<ChangeTenantStatusRequest>, ChangeTenantStatusValidator>();
|
||||
services.AddScoped<IComponentHandler<ChangeTenantStatusRequest>, TenantHandler>();
|
||||
|
||||
#endregion
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user