Compare commits
	
		
			14 Commits
		
	
	
		
			feature/fi
			...
			feature/ad
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | 39341a6640 | ||
| 5d637e9d4f | |||
|   | 2d1dfb19ed | ||
|   | 296aff13fe | ||
|   | f3d63ca0e3 | ||
|   | abcddaba9d | ||
| c1637b9e20 | |||
|   | 598081acea | ||
|   | 6d884d0d8b | ||
|   | 4d43ac70cd | ||
| 3b42b60757 | |||
| 4cea65632b | |||
| a9981b6eb3 | |||
| a09540f20a | 
| @@ -1,5 +1,5 @@ | ||||
| using Core.Thalos.Adapters; | ||||
| using Core.Thalos.Application.UseCases.Modules.Ports; | ||||
| using Core.Thalos.Application.UseCases.Modules.Ports; | ||||
| using Core.Thalos.BuildingBlocks; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
|  | ||||
|   | ||||
| @@ -1,16 +1,16 @@ | ||||
| using Core.Thalos.Adapters.Common.Enums; | ||||
| using Core.Blueprint.Mongo; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| 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; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| using Core.Thalos.Adapters.Common.Enums; | ||||
| using Core.Thalos.BuildingBlocks; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Thalos.Application.UseCases.Modules.Input | ||||
|   | ||||
| @@ -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; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,11 +1,11 @@ | ||||
| using Core.Thalos.Adapters.Common.Enums; | ||||
| using Core.Thalos.BuildingBlocks; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| 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; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| using Core.Thalos.Adapters; | ||||
| using Core.Thalos.Application.UseCases.Modules.Input; | ||||
| using Core.Thalos.Application.UseCases.Modules.Input; | ||||
| using Core.Thalos.Application.UseCases.Modules.Ports; | ||||
| using Core.Thalos.BuildingBlocks; | ||||
| using Core.Thalos.External.Clients; | ||||
| using Core.Thalos.External.Clients.Requests; | ||||
| using FluentValidation; | ||||
| @@ -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); | ||||
|  | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| using Core.Thalos.Adapters; | ||||
| using Core.Thalos.BuildingBlocks; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Thalos.Application.UseCases.Modules.Ports | ||||
|   | ||||
| @@ -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."); | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -1,5 +1,5 @@ | ||||
| using Core.Thalos.Adapters; | ||||
| using Core.Thalos.Application.UseCases.Permissions.Ports; | ||||
| using Core.Thalos.Application.UseCases.Permissions.Ports; | ||||
| using Core.Thalos.BuildingBlocks; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
|  | ||||
|   | ||||
| @@ -1,16 +1,16 @@ | ||||
| using Core.Thalos.Adapters.Common.Enums; | ||||
| using Core.Blueprint.Mongo; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| 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; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| using Core.Thalos.Adapters.Common.Constants; | ||||
| using Core.Thalos.BuildingBlocks; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Thalos.Application.UseCases.Permissions.Input | ||||
|   | ||||
| @@ -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; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,19 +1,18 @@ | ||||
| using Core.Thalos.Adapters.Common.Constants; | ||||
| using Core.Thalos.Adapters.Common.Enums; | ||||
| using Core.Thalos.BuildingBlocks; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| 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 StatusEnum Status { get; set; } | ||||
|         public Blueprint.Mongo.StatusEnum Status { get; set; } | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return Id != null; | ||||
|             return _Id != null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| using Core.Thalos.Adapters; | ||||
| using Core.Thalos.Application.UseCases.Permissions.Input; | ||||
| using Core.Thalos.Application.UseCases.Permissions.Input; | ||||
| using Core.Thalos.Application.UseCases.Permissions.Ports; | ||||
| using Core.Thalos.BuildingBlocks; | ||||
| using Core.Thalos.External.Clients; | ||||
| using Core.Thalos.External.Clients.Requests; | ||||
| using FluentValidation; | ||||
| @@ -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); | ||||
|  | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| using Core.Thalos.Adapters; | ||||
| using Core.Thalos.BuildingBlocks; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Thalos.Application.UseCases.Permissions.Ports | ||||
|   | ||||
| @@ -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."); | ||||
|         } | ||||
|  | ||||
|   | ||||
| @@ -1,5 +1,5 @@ | ||||
| using Core.Thalos.Adapters; | ||||
| using Core.Thalos.Application.UseCases.Roles.Ports; | ||||
| using Core.Thalos.Application.UseCases.Roles.Ports; | ||||
| using Core.Thalos.BuildingBlocks; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
|  | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| using Core.Thalos.Adapters.Common.Enums; | ||||
| using Core.Thalos.BuildingBlocks; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Thalos.Application.UseCases.Roles.Input | ||||
|   | ||||
| @@ -1,15 +1,15 @@ | ||||
| using Core.Thalos.Adapters.Common.Enums; | ||||
| using Core.Blueprint.Mongo; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| 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; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| using Core.Thalos.Adapters.Common.Enums; | ||||
| using Core.Thalos.BuildingBlocks; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using System.Text.Json.Serialization; | ||||
|  | ||||
|   | ||||
| @@ -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; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| using Core.Thalos.Adapters.Common.Enums; | ||||
| using Core.Thalos.BuildingBlocks; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Thalos.Application.UseCases.Roles.Input | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| using Core.Thalos.Adapters.Common.Enums; | ||||
| using Core.Thalos.BuildingBlocks; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using System.Text.Json.Serialization; | ||||
|  | ||||
| @@ -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; } | ||||
|  | ||||
| @@ -14,11 +14,11 @@ namespace Core.Thalos.Application.UseCases.Roles.Input | ||||
|         public ApplicationsEnum[]? Applications { get; set; } | ||||
|         public string[] Modules { get; set; } = null!; | ||||
|         public string[] Permissions { get; set; } = null!; | ||||
|         public StatusEnum Status { get; set; } | ||||
|         public Blueprint.Mongo.StatusEnum Status { get; set; } | ||||
|  | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return Id != null; | ||||
|             return _Id != null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| using Core.Thalos.Adapters; | ||||
| using Core.Thalos.BuildingBlocks; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Thalos.Application.UseCases.Roles.Ports | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| using Core.Thalos.Adapters; | ||||
| using Core.Thalos.Application.UseCases.Roles.Input; | ||||
| using Core.Thalos.Application.UseCases.Roles.Input; | ||||
| using Core.Thalos.Application.UseCases.Roles.Ports; | ||||
| using Core.Thalos.BuildingBlocks; | ||||
| using Core.Thalos.External.Clients; | ||||
| using Core.Thalos.External.Clients.Requests; | ||||
| using FluentValidation; | ||||
| @@ -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; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -1,8 +1,8 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| 
 | ||||
| namespace Core.Thalos.Application.UseCases.Users.Input | ||||
| namespace Core.Thalos.Application.UseCases.Tenants.Input | ||||
| { | ||||
|     public class GetConsentFormPDFRequest : ICommand | ||||
|     public class GetAllTenantsRequest : ICommand | ||||
|     { | ||||
|         public bool Validate() | ||||
|         { | ||||
| @@ -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."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -1,6 +1,6 @@ | ||||
| using Core.Blueprint.Storage.Adapters; | ||||
| using Core.Thalos.Adapters; | ||||
| using Core.Thalos.Application.UseCases.Users.Ports; | ||||
| using Core.Thalos.BuildingBlocks; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
|  | ||||
|   | ||||
| @@ -1,14 +0,0 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Thalos.Application.UseCases.Users.Input | ||||
| { | ||||
|     public class AddCompanyToUserRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string UserId { get; set; } | ||||
|         public string CompanyId { get; set; } | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return true; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -1,14 +0,0 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Thalos.Application.UseCases.Users.Input | ||||
| { | ||||
|     public class AddProjectToUserRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string UserId { get; set; } | ||||
|         public string ProjectId { get; set; } | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return true; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -1,16 +1,16 @@ | ||||
| using Core.Thalos.Adapters.Common.Enums; | ||||
| using Core.Blueprint.Mongo; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| 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; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -2,11 +2,12 @@ | ||||
| 
 | ||||
| namespace Core.Thalos.Application.UseCases.Users.Input | ||||
| { | ||||
|     public class AcceptUserConsentFormRequest : ICommand | ||||
|     public class DeleteUserRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string _Id { get; set; } | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return true; | ||||
|             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; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,14 +0,0 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Thalos.Application.UseCases.Users.Input | ||||
| { | ||||
|     public class RemoveCompanyFromUserRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string UserId { get; set; } | ||||
|         public string CompanyId { get; set; } | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return true; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -1,14 +0,0 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Thalos.Application.UseCases.Users.Input | ||||
| { | ||||
|     public class RemoveProjectFromUserRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string UserId { get; set; } | ||||
|         public string ProjectId { get; set; } | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return true; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -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; } | ||||
|   | ||||
| @@ -1,5 +1,5 @@ | ||||
| using Core.Blueprint.Storage.Adapters; | ||||
| using Core.Thalos.Adapters; | ||||
| using Core.Thalos.BuildingBlocks; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Thalos.Application.UseCases.Users.Ports | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| using Core.Thalos.Adapters; | ||||
| using Core.Thalos.Application.UseCases.Users.Input; | ||||
| using Core.Thalos.Application.UseCases.Users.Input; | ||||
| using Core.Thalos.Application.UseCases.Users.Ports; | ||||
| using Core.Thalos.BuildingBlocks; | ||||
| using Core.Thalos.External.Clients; | ||||
| using Core.Thalos.External.Clients.Requests; | ||||
| using FluentValidation; | ||||
| @@ -12,13 +12,10 @@ namespace Core.Thalos.Application.UseCases.Users | ||||
|         IComponentHandler<ChangeUserStatusRequest>, | ||||
|         IComponentHandler<GetAllUsersRequest>, | ||||
|         IComponentHandler<UpdateUserRequest>, | ||||
|         IComponentHandler<DeleteUserRequest>, | ||||
|         IComponentHandler<GetUserRequest>, | ||||
|         IComponentHandler<GetUserByEmailRequest>, | ||||
|         IComponentHandler<CreateUserRequest>, | ||||
|         IComponentHandler<AddProjectToUserRequest>, | ||||
|         IComponentHandler<RemoveProjectFromUserRequest>, | ||||
|         IComponentHandler<AddCompanyToUserRequest>, | ||||
|         IComponentHandler<RemoveCompanyFromUserRequest>, | ||||
|         IComponentHandler<LoginUserRequest>, | ||||
|         IComponentHandler<LogoutUserRequest>, | ||||
|         IComponentHandler<ValidateUserExistenceRequest>, | ||||
| @@ -50,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) | ||||
|                 { | ||||
| @@ -142,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) | ||||
|                 { | ||||
| @@ -177,8 +196,6 @@ namespace Core.Thalos.Application.UseCases.Users | ||||
|                     MiddleName = command.MiddleName, | ||||
|                     LastName = command.LastName, | ||||
|                     RoleId = command.RoleId, | ||||
|                     Companies = command.Companies, | ||||
|                     Projects = command.Projects, | ||||
|                 }; | ||||
|  | ||||
|                 var result = await _thalosDALService.CreateUserAsync(request, command.SendInvitation, cancellationToken).ConfigureAwait(false); | ||||
| @@ -211,17 +228,15 @@ 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, | ||||
|                     LastName = command.LastName, | ||||
|                     RoleId = command.RoleId, | ||||
|                     Companies = command.Companies, | ||||
|                     Projects = command.Projects | ||||
|                 }; | ||||
|  | ||||
|                 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) | ||||
|                 { | ||||
| @@ -281,94 +296,6 @@ namespace Core.Thalos.Application.UseCases.Users | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(AddCompanyToUserRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 var result = await _thalosDALService.AddCompanyToUserAsync(command.UserId, command.CompanyId, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(RemoveCompanyFromUserRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 var result = await _thalosDALService.RemoveCompanyToUserAsync(command.UserId, command.CompanyId, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(AddProjectToUserRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 var result = await _thalosDALService.AddProjectToUserAsync(command.UserId, command.ProjectId, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(RemoveProjectFromUserRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 var result = await _thalosDALService.RemoveProjectToUserAsync(command.UserId, command.ProjectId, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(GetTokenAdapterRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|   | ||||
| @@ -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."); | ||||
|         } | ||||
|  | ||||
|   | ||||
| @@ -7,7 +7,7 @@ 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("RoleId").WithMessage("RoleId is Obligatory."); | ||||
|   | ||||
| @@ -1,7 +1,4 @@ | ||||
| using Core.Blueprint.Storage.Adapters; | ||||
| using Core.Thalos.Adapters; | ||||
| using Core.Thalos.Adapters.Common.Constants; | ||||
| using Core.Thalos.Adapters.Common.Enums; | ||||
| using Core.Thalos.BuildingBlocks; | ||||
| using Core.Thalos.External.Clients.Requests; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
| using Refit; | ||||
| @@ -14,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); | ||||
| @@ -26,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); | ||||
| @@ -35,37 +35,28 @@ 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, 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); | ||||
|  | ||||
|         [Post("/v1/User/" + Routes.AddCompany)] | ||||
|         Task<UserAdapter> AddCompanyToUserAsync([FromRoute] string userId, [FromRoute] string companyId, CancellationToken cancellationToken = default); | ||||
|  | ||||
|         [Delete("/v1/User/" + Routes.RemoveCompany)] | ||||
|         Task<UserAdapter> RemoveCompanyToUserAsync([FromRoute] string userId, [FromRoute] string companyId, CancellationToken cancellationToken = default); | ||||
|  | ||||
|         [Post("/v1/User/" + Routes.AddProject)] | ||||
|         Task<UserAdapter> AddProjectToUserAsync([FromRoute] string userId, [FromRoute] string projectId, CancellationToken cancellationToken = default); | ||||
|  | ||||
|         [Delete("/v1/User/" + Routes.RemoveProject)] | ||||
|         Task<UserAdapter> RemoveProjectToUserAsync([FromRoute] string userId, [FromRoute] string projectId, CancellationToken cancellationToken = default); | ||||
|  | ||||
|         [Get("/v1/Role")] | ||||
|         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] 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); | ||||
| @@ -80,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] 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); | ||||
| @@ -98,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] 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); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| using Core.Thalos.Adapters.Common.Enums; | ||||
| using Core.Thalos.BuildingBlocks; | ||||
| using System.Text.Json.Serialization; | ||||
|  | ||||
| namespace Core.Thalos.External.Clients.Requests | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| using Core.Thalos.Adapters.Common.Constants; | ||||
| using Core.Thalos.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Thalos.External.Clients.Requests | ||||
| { | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| using Core.Thalos.Adapters.Common.Enums; | ||||
| using Core.Thalos.BuildingBlocks; | ||||
| using System.Text.Json.Serialization; | ||||
|  | ||||
| namespace Core.Thalos.External.Clients.Requests | ||||
|   | ||||
							
								
								
									
										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; } | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -7,7 +7,5 @@ | ||||
|         public string? MiddleName { get; set; } | ||||
|         public string LastName { get; set; } = null!; | ||||
|         public string RoleId { get; set; } = null!; | ||||
|         public string[] Companies { get; set; } = null!; | ||||
|         public string[]? Projects { get; set; } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -7,8 +7,8 @@ | ||||
|   </PropertyGroup> | ||||
|  | ||||
|   <ItemGroup> | ||||
|     <PackageReference Include="Core.Blueprint.Storage" Version="1.0.0" /> | ||||
|     <PackageReference Include="Core.Thalos.BuildingBlocks" Version="1.0.2" /> | ||||
|     <PackageReference Include="Core.Blueprint.Storage" Version="1.0.1" /> | ||||
|     <PackageReference Include="Core.Thalos.BuildingBlocks" Version="1.1.4" /> | ||||
|     <PackageReference Include="Lib.Architecture.BuildingBlocks" Version="1.0.0" /> | ||||
|     <PackageReference Include="Refit" Version="8.0.0" /> | ||||
|   </ItemGroup> | ||||
|   | ||||
| @@ -1,9 +1,7 @@ | ||||
| using Asp.Versioning; | ||||
| using Core.Thalos.Adapters; | ||||
| using Core.Thalos.Adapters.Attributes; | ||||
| using Core.Thalos.Adapters.Common.Constants; | ||||
| 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; | ||||
| @@ -17,6 +15,7 @@ namespace Core.Thalos.Service.API.Controllers | ||||
|     [Route("api/v{api-version:apiVersion}/[controller]")] | ||||
|     [Produces("application/json")] | ||||
|     [ApiController] | ||||
|     [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|     public class ModuleController : ControllerBase | ||||
|     { | ||||
|         private readonly IComponentHandler<GetModuleRequest> getModuleHandler; | ||||
| @@ -24,6 +23,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; | ||||
|  | ||||
| @@ -36,12 +36,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; | ||||
| @@ -60,8 +62,7 @@ namespace Core.Thalos.Service.API.Controllers | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         //[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); | ||||
| @@ -91,8 +92,7 @@ namespace Core.Thalos.Service.API.Controllers | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         //[Permission("ModuleManagement.Read")] | ||||
|         [Permission("ModuleManagement.Read")] | ||||
|         public async Task<IActionResult> GetAllModulesByListAsync([FromBody] GetAllModulesByListRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|  | ||||
| @@ -107,7 +107,7 @@ namespace Core.Thalos.Service.API.Controllers | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets the module by identifier. | ||||
|         /// Gets the module by mongo identifier. | ||||
|         /// </summary> | ||||
|         [HttpPost] | ||||
|         [Route("GetById")] | ||||
| @@ -118,14 +118,13 @@ namespace Core.Thalos.Service.API.Controllers | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         //[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); | ||||
| @@ -144,8 +143,7 @@ namespace Core.Thalos.Service.API.Controllers | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         //[Permission("ModuleManagement.Write")] | ||||
|         [Permission("ModuleManagement.Write")] | ||||
|         public async Task<IActionResult> CreateModuleAsync([FromBody] CreateModuleRequest newModule, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             await createModuleHandler.ExecuteAsync(newModule, cancellationToken).ConfigureAwait(false); | ||||
| @@ -154,7 +152,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)] | ||||
| @@ -164,8 +162,7 @@ namespace Core.Thalos.Service.API.Controllers | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         //[Permission("ModuleManagement.Write")] | ||||
|         [Permission("ModuleManagement.Write")] | ||||
|         public async Task<IActionResult> UpdateModuleAsync([FromBody] UpdateModuleRequest request, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             await updateModuleHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
| @@ -173,6 +170,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> | ||||
| @@ -185,12 +201,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("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); | ||||
|  | ||||
|   | ||||
| @@ -1,9 +1,7 @@ | ||||
| using Asp.Versioning; | ||||
| using Core.Thalos.Adapters; | ||||
| using Core.Thalos.Adapters.Attributes; | ||||
| using Core.Thalos.Adapters.Common.Constants; | ||||
| 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; | ||||
| @@ -17,6 +15,7 @@ namespace Core.Thalos.Service.API.Controllers | ||||
|     [Route("api/v{api-version:apiVersion}/[controller]")] | ||||
|     [Produces("application/json")] | ||||
|     [ApiController] | ||||
|     [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|     public class PermissionController : ControllerBase | ||||
|     { | ||||
|         private readonly IComponentHandler<GetPermissionRequest> getPermissionHandler; | ||||
| @@ -24,6 +23,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; | ||||
|  | ||||
| @@ -36,12 +36,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; | ||||
| @@ -60,8 +62,7 @@ namespace Core.Thalos.Service.API.Controllers | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         //[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); | ||||
| @@ -91,8 +92,7 @@ namespace Core.Thalos.Service.API.Controllers | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         //[Permission("PermissionManagement.Read")] | ||||
|         [Permission("PermissionManagement.Read")] | ||||
|         public async Task<IActionResult> GetAllPermissionsByListAsync([FromBody] GetAllPermissionsByListRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|  | ||||
| @@ -107,7 +107,7 @@ namespace Core.Thalos.Service.API.Controllers | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets the permission by identifier. | ||||
|         /// Gets the permission by mongo identifier. | ||||
|         /// </summary> | ||||
|         [HttpPost] | ||||
|         [Route("GetById")] | ||||
| @@ -118,14 +118,13 @@ namespace Core.Thalos.Service.API.Controllers | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         //[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); | ||||
| @@ -144,8 +143,7 @@ namespace Core.Thalos.Service.API.Controllers | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         //[Permission("PermissionManagement.Write")] | ||||
|         [Permission("PermissionManagement.Write")] | ||||
|         public async Task<IActionResult> CreatePermissionAsync([FromBody] CreatePermissionRequest newPermission, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             await createPermissionHandler.ExecuteAsync(newPermission, cancellationToken).ConfigureAwait(false); | ||||
| @@ -154,7 +152,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)] | ||||
| @@ -164,8 +162,7 @@ namespace Core.Thalos.Service.API.Controllers | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         //[Permission("PermissionManagement.Write")] | ||||
|         [Permission("PermissionManagement.Write")] | ||||
|         public async Task<IActionResult> UpdatePermissionAsync([FromBody] UpdatePermissionRequest request, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             await updatePermissionHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
| @@ -173,6 +170,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> | ||||
| @@ -185,12 +201,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("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,8 +1,7 @@ | ||||
| using Asp.Versioning; | ||||
| using Core.Thalos.Adapters.Attributes; | ||||
| using Core.Thalos.Adapters.Common.Constants; | ||||
| 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; | ||||
| @@ -16,13 +15,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; | ||||
| @@ -36,6 +36,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, | ||||
| @@ -44,6 +45,7 @@ namespace Core.Thalos.Service.API.Controllers | ||||
|         { | ||||
|             this.createRoleHandler = createRoleHandler; | ||||
|             this.updateRoleHandler = updateRoleHandler; | ||||
|             this.deleteRoleHandler = deleteRoleHandler; | ||||
|             this.changeStatusRoleHandler = changeRoleStatusHandler; | ||||
|             this.getAllRolesHandler = getAllRolesHandler; | ||||
|             this.getRoleHandler = getRoleHandler; | ||||
| @@ -63,8 +65,7 @@ namespace Core.Thalos.Service.API.Controllers | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         //[Permission("RoleManagement.Read")] | ||||
|         [Permission("RoleManagement.Read")] | ||||
|         public async Task<IActionResult> GetAllRolesAsync(CancellationToken cancellationToken) | ||||
|         { | ||||
|             await getAllRolesHandler.ExecuteAsync(new GetAllRolesRequest { }, cancellationToken).ConfigureAwait(false); | ||||
| @@ -73,7 +74,7 @@ namespace Core.Thalos.Service.API.Controllers | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets the role by identifier. | ||||
|         /// Gets the role by mongo identifier. | ||||
|         /// </summary> | ||||
|         [HttpPost] | ||||
|         [Route("GetById")] | ||||
| @@ -84,11 +85,10 @@ namespace Core.Thalos.Service.API.Controllers | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         //[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); | ||||
|  | ||||
| @@ -106,8 +106,7 @@ namespace Core.Thalos.Service.API.Controllers | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         //[Permission("RoleManagement.Write")] | ||||
|         [Permission("RoleManagement.Write")] | ||||
|         public async Task<IActionResult> CreateRoleAsync([FromBody] CreateRoleRequest newRole, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             await createRoleHandler.ExecuteAsync(newRole, cancellationToken).ConfigureAwait(false); | ||||
| @@ -116,7 +115,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)] | ||||
| @@ -126,8 +125,7 @@ namespace Core.Thalos.Service.API.Controllers | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         //[Permission("RoleManagement.Write")] | ||||
|         [Permission("RoleManagement.Write")] | ||||
|         public async Task<IActionResult> UpdateRoleAsync([FromBody] UpdateRoleRequest entity, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             await updateRoleHandler.ExecuteAsync(entity, cancellationToken).ConfigureAwait(false); | ||||
| @@ -135,6 +133,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> | ||||
| @@ -147,11 +164,10 @@ namespace Core.Thalos.Service.API.Controllers | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         //[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); | ||||
|  | ||||
| @@ -170,11 +186,10 @@ namespace Core.Thalos.Service.API.Controllers | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         //[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); | ||||
|  | ||||
| @@ -193,12 +208,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("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); | ||||
|  | ||||
|   | ||||
							
								
								
									
										176
									
								
								Core.Thalos.Service.API/Controllers/TenantController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										176
									
								
								Core.Thalos.Service.API/Controllers/TenantController.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,176 @@ | ||||
| using Asp.Versioning; | ||||
| using Core.Thalos.Application.UseCases.Tenants.Input; | ||||
| using Core.Thalos.Application.UseCases.Tenants.Ports; | ||||
| using Core.Thalos.BuildingBlocks; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Microsoft.AspNetCore.Authorization; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
|  | ||||
| namespace Core.Thalos.Service.API.Controllers | ||||
| { | ||||
|     /// <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; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -1,9 +1,7 @@ | ||||
| using Asp.Versioning; | ||||
| using Core.Thalos.Adapters; | ||||
| using Core.Thalos.Adapters.Attributes; | ||||
| using Core.Thalos.Adapters.Common.Constants; | ||||
| using Core.Thalos.Application.UseCases.Users.Input; | ||||
| using Core.Thalos.Application.UseCases.Users.Ports; | ||||
| using Core.Thalos.BuildingBlocks; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Microsoft.AspNetCore.Authorization; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
| @@ -24,11 +22,8 @@ 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<AddCompanyToUserRequest> addCompanyToUserHandler; | ||||
|         private readonly IComponentHandler<RemoveCompanyFromUserRequest> removeCompanyFromUserHandler; | ||||
|         private readonly IComponentHandler<AddProjectToUserRequest> addProjectToUserHandler; | ||||
|         private readonly IComponentHandler<RemoveProjectFromUserRequest> removeProjectFromUserHandler; | ||||
|         private readonly IComponentHandler<LoginUserRequest> loginUserHandler; | ||||
|         private readonly IComponentHandler<LogoutUserRequest> logoutUserHandler; | ||||
|         private readonly IComponentHandler<ValidateUserExistenceRequest> validateUserHandler; | ||||
| @@ -44,11 +39,8 @@ namespace Core.Thalos.Service.API.Controllers | ||||
|             IComponentHandler<GetAllUsersRequest> getAllUsersHandler, | ||||
|             IComponentHandler<CreateUserRequest> createUserHandler, | ||||
|             IComponentHandler<UpdateUserRequest> updateUserHandler, | ||||
|             IComponentHandler<DeleteUserRequest> deleteUserHandler, | ||||
|             IComponentHandler<ChangeUserStatusRequest> changeUserStatusHandler, | ||||
|             IComponentHandler<AddCompanyToUserRequest> addCompanyToUserHandler, | ||||
|             IComponentHandler<RemoveCompanyFromUserRequest> removeCompanyFromUserHandler, | ||||
|             IComponentHandler<AddProjectToUserRequest> addProjectToUserHandler, | ||||
|             IComponentHandler<RemoveProjectFromUserRequest> removeProjectFromUserHandler, | ||||
|             IComponentHandler<LoginUserRequest> loginUserHandler, | ||||
|             IComponentHandler<LogoutUserRequest> logoutUserHandler, | ||||
|             IComponentHandler<ValidateUserExistenceRequest> validateUserHandler, | ||||
| @@ -58,14 +50,11 @@ namespace Core.Thalos.Service.API.Controllers | ||||
|         { | ||||
|             this.createUserHandler = createUserHandler; | ||||
|             this.updateUserHandler = updateUserHandler; | ||||
|             this.deleteUserHandler = deleteUserHandler; | ||||
|             this.ChangeUserStatusHandler = changeUserStatusHandler; | ||||
|             this.getAllUsersHandler = getAllUsersHandler; | ||||
|             this.getUserHandler = getUserHandler; | ||||
|             this.getUserByEmailHandler = getUserByEmailHandler; | ||||
|             this.addCompanyToUserHandler = addCompanyToUserHandler; | ||||
|             this.removeCompanyFromUserHandler = removeCompanyFromUserHandler; | ||||
|             this.addProjectToUserHandler = addProjectToUserHandler; | ||||
|             this.removeProjectFromUserHandler = removeProjectFromUserHandler; | ||||
|             this.loginUserHandler = loginUserHandler; | ||||
|             this.logoutUserHandler = logoutUserHandler; | ||||
|             this.validateUserHandler = validateUserHandler; | ||||
| @@ -84,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); | ||||
| @@ -94,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")] | ||||
| @@ -105,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); | ||||
|  | ||||
| @@ -128,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.AzureScheme}")] | ||||
|         [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"); } | ||||
| @@ -150,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); | ||||
| @@ -160,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)] | ||||
| @@ -170,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) | ||||
|         { | ||||
| @@ -180,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> | ||||
| @@ -191,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.AzureScheme}")] | ||||
|         [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"); } | ||||
| @@ -233,118 +243,17 @@ 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); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Adds a company to the user's list of companies. | ||||
|         /// </summary> | ||||
|         [HttpPost] | ||||
|         [Route("AddCompany")] | ||||
|         [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)] | ||||
|         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         //[Permission("UserManagement.Write")] | ||||
|         public async Task<IActionResult> AddCompanyToUserAsync([FromBody] AddCompanyToUserRequest request, | ||||
|                                                                CancellationToken cancellationToken) | ||||
|         { | ||||
|             if (string.IsNullOrEmpty(request.UserId)) { return BadRequest("Invalid user identifier"); } | ||||
|             if (string.IsNullOrEmpty(request.CompanyId)) { return BadRequest("Invalid company identifier"); } | ||||
|  | ||||
|             await addCompanyToUserHandler.ExecuteAsync(request, cancellationToken); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Removes a company from the user's list of companies. | ||||
|         /// </summary> | ||||
|         [HttpDelete] | ||||
|         [Route("RemoveCompany")] | ||||
|         [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)] | ||||
|         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         //[Permission("UserManagement.Write")] | ||||
|         public async Task<IActionResult> RemoveCompanyFromUserAsync([FromBody] RemoveCompanyFromUserRequest request, | ||||
|                                                                    CancellationToken cancellationToken) | ||||
|         { | ||||
|             if (string.IsNullOrEmpty(request.UserId)) { return BadRequest("Invalid user identifier"); } | ||||
|             if (string.IsNullOrEmpty(request.CompanyId)) { return BadRequest("Invalid company identifier"); } | ||||
|  | ||||
|             await removeCompanyFromUserHandler.ExecuteAsync(request, cancellationToken); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Adds a project to the user's list of projects. | ||||
|         /// </summary> | ||||
|         [HttpPost] | ||||
|         [Route("AddProject")] | ||||
|         [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)] | ||||
|         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         //[Permission("UserManagement.Write")] | ||||
|         public async Task<IActionResult> AddProjectToUserAsync([FromBody] AddProjectToUserRequest request, | ||||
|                                                               CancellationToken cancellationToken) | ||||
|         { | ||||
|             if (string.IsNullOrEmpty(request.UserId)) { return BadRequest("Invalid user identifier"); } | ||||
|             if (string.IsNullOrEmpty(request.ProjectId)) { return BadRequest("Invalid project identifier"); } | ||||
|  | ||||
|             await addProjectToUserHandler.ExecuteAsync(request, cancellationToken); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Removes a project from the user's list of projects. | ||||
|         /// </summary> | ||||
|         [HttpDelete] | ||||
|         [Route("RemoveProject")] | ||||
|         [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)] | ||||
|         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         //[Permission("UserManagement.Write")] | ||||
|         public async Task<IActionResult> RemoveProjectFromUserAsync([FromBody] RemoveProjectFromUserRequest request, | ||||
|                                                                    CancellationToken cancellationToken) | ||||
|         { | ||||
|  | ||||
|             if (string.IsNullOrEmpty(request.UserId)) { return BadRequest("Invalid user identifier"); } | ||||
|             if (string.IsNullOrEmpty(request.ProjectId)) { return BadRequest("Invalid project identifier"); } | ||||
|  | ||||
|             await removeProjectFromUserHandler.ExecuteAsync(request, cancellationToken); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Validates if a user exists on the database. | ||||
|         /// </summary> | ||||
| @@ -373,7 +282,7 @@ namespace Core.Thalos.Service.API.Controllers | ||||
|         [HttpPost] | ||||
|         [Route("GetTokenAdapter")] | ||||
|         [ProducesResponseType(typeof(TokenAdapter), StatusCodes.Status200OK)] | ||||
|         //[Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.AzureScheme}")] | ||||
|         [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"); } | ||||
|   | ||||
| @@ -8,7 +8,7 @@ | ||||
|   </PropertyGroup> | ||||
|  | ||||
|   <ItemGroup> | ||||
|     <PackageReference Include="Blueprint.Logging" Version="0.0.2" /> | ||||
|     <PackageReference Include="Core.Blueprint.Logging" Version="1.0.1" /> | ||||
|   </ItemGroup> | ||||
|  | ||||
|   <ItemGroup> | ||||
|   | ||||
| @@ -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,13 +37,10 @@ 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>(); | ||||
|             services.AddScoped<IComponentHandler<AddCompanyToUserRequest>, UserHandler>(); | ||||
|             services.AddScoped<IComponentHandler<RemoveCompanyFromUserRequest>, UserHandler>(); | ||||
|             services.AddScoped<IComponentHandler<AddProjectToUserRequest>, UserHandler>(); | ||||
|             services.AddScoped<IComponentHandler<RemoveProjectFromUserRequest>, UserHandler>(); | ||||
|             services.AddScoped<IComponentHandler<ValidateUserExistenceRequest>, UserHandler>(); | ||||
|             services.AddScoped<IComponentHandler<GetTokenAdapterRequest>, UserHandler>(); | ||||
|  | ||||
| @@ -62,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>(); | ||||
|  | ||||
| @@ -84,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>(); | ||||
| @@ -105,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>(); | ||||
| @@ -124,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; | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -1,99 +0,0 @@ | ||||
| using Asp.Versioning.ApiExplorer; | ||||
| using Microsoft.Extensions.Options; | ||||
| using Microsoft.OpenApi.Models; | ||||
| using Swashbuckle.AspNetCore.SwaggerGen; | ||||
| using Swashbuckle.AspNetCore.SwaggerUI; | ||||
|  | ||||
| namespace Core.Thalos.Service.API.Extensions | ||||
| { | ||||
|     public static class SwaggerExtensions | ||||
|     { | ||||
|         public static void AddSwagger(this IServiceCollection services, IConfiguration configuration) | ||||
|         { | ||||
|             services.AddEndpointsApiExplorer(); | ||||
|             AddSwaggerGen(services, configuration); | ||||
|             services.AddTransient<IConfigureOptions<SwaggerGenOptions>, ConfigureSwaggerOptions>(); | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Configures Swagger generation with OAuth2 security and XML comments. | ||||
|         /// </summary> | ||||
|         /// <param name="services">The <see cref="IServiceCollection"/> to add the services to.</param> | ||||
|         /// <param name="configuration">The <see cref="IConfiguration"/> containing Swagger and OAuth2 configuration settings.</param> | ||||
|         public static void AddSwaggerGen(this IServiceCollection services, IConfiguration configuration) | ||||
|         { | ||||
|             services.AddSwaggerGen(c => | ||||
|             { | ||||
|                 c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme | ||||
|                 { | ||||
|                     Description = "JWT Authorization header using the Bearer scheme", | ||||
|                     Name = "Authorization", | ||||
|                     In = ParameterLocation.Header, | ||||
|                     Type = SecuritySchemeType.Http, | ||||
|                     Scheme = "bearer", | ||||
|                     BearerFormat = "JWT" | ||||
|                 }); | ||||
|  | ||||
|                 c.AddSecurityRequirement(new OpenApiSecurityRequirement | ||||
|                 { | ||||
|                     { | ||||
|                         new OpenApiSecurityScheme | ||||
|                         { | ||||
|                             Reference = new OpenApiReference | ||||
|                             { | ||||
|                                 Type = ReferenceType.SecurityScheme, | ||||
|                                 Id = "Bearer" | ||||
|                             } | ||||
|                         }, | ||||
|                         Array.Empty<string>() | ||||
|                     } | ||||
|                 }); | ||||
|             }); | ||||
|         } | ||||
|         public static void ConfigureSwagger(this WebApplication app) | ||||
|         { | ||||
|             //Swagger Stuff Goes Here | ||||
|  | ||||
|             app.UseSwagger(); | ||||
|             app.UseSwaggerUI(options => | ||||
|             { | ||||
|                 foreach (var version in app.DescribeApiVersions().Select(version => version.GroupName)) | ||||
|                     options.SwaggerEndpoint($"/swagger/{version}/swagger.json", version); | ||||
|  | ||||
|                 options.DisplayRequestDuration(); | ||||
|                 options.EnableTryItOutByDefault(); | ||||
|                 options.DocExpansion(DocExpansion.None); | ||||
|             }); | ||||
|  | ||||
|             //  app.MapGet("/", () => Results.Redirect("/swagger/index.html")).WithTags(string.Empty); | ||||
|         } | ||||
|         public static IServiceCollection AddVersioning(this IServiceCollection services) | ||||
|         { | ||||
|             services.AddApiVersioning(options => options.ReportApiVersions = true) | ||||
|                    .AddApiExplorer(options => | ||||
|                    { | ||||
|                        options.GroupNameFormat = "'v'VVV"; | ||||
|                        options.SubstituteApiVersionInUrl = true; | ||||
|                    }); | ||||
|  | ||||
|             return services; | ||||
|         } | ||||
|     } | ||||
|     public class ConfigureSwaggerOptions(IApiVersionDescriptionProvider provider) : IConfigureOptions<SwaggerGenOptions> | ||||
|     { | ||||
|         private readonly IApiVersionDescriptionProvider _provider = provider; | ||||
|  | ||||
|         public void Configure(SwaggerGenOptions options) | ||||
|         { | ||||
|             foreach (var description in _provider.ApiVersionDescriptions) | ||||
|                 options.SwaggerDoc(description.GroupName, new() | ||||
|                 { | ||||
|                     Title = AppDomain.CurrentDomain.FriendlyName, | ||||
|                     Version = description.ApiVersion.ToString() | ||||
|                 }); | ||||
|  | ||||
|  | ||||
|             options.CustomSchemaIds(type => type.ToString().Replace("+", ".")); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -1,5 +1,7 @@ | ||||
| using Core.Blueprint.KeyVault.Configuration; | ||||
| using Core.Blueprint.Logging.Configuration; | ||||
| using Core.Thalos.Adapters.Extensions; | ||||
| using Core.Thalos.BuildingBlocks; | ||||
| using Core.Thalos.BuildingBlocks.Configuration; | ||||
| using Core.Thalos.External.ClientConfiguration; | ||||
| using Core.Thalos.Service.API.Extensions; | ||||
| using Microsoft.AspNetCore.HttpLogging; | ||||
| @@ -8,18 +10,21 @@ using System.Text.Json.Serialization; | ||||
|  | ||||
| var builder = WebApplication.CreateBuilder(args); | ||||
|  | ||||
| //var authSettings = AuthHelper.GetAuthSettings(builder, "thalos_service"); | ||||
|  | ||||
| //builder.Services.ConfigureAuthentication(builder.Configuration, authSettings); | ||||
|  | ||||
| builder.Services.AddLogs(builder); | ||||
|  | ||||
| builder.Services.AddEndpointsApiExplorer(); | ||||
| builder.Services.AddSwaggerGen(); | ||||
| builder.Configuration | ||||
|     .AddUserSecrets(Assembly.GetExecutingAssembly()) | ||||
|     .AddEnvironmentVariables(); | ||||
|  | ||||
| var services = builder.Services.AddKeyVault(builder.Configuration); | ||||
|  | ||||
| var authSettings = await AuthHelper.GetAuthSettings(builder.Services, builder, "thalos_common"); | ||||
|  | ||||
| builder.Services.ConfigureAuthentication(builder.Configuration, authSettings); | ||||
|  | ||||
| builder.Services.AddLogs(builder); | ||||
|  | ||||
| builder.Services.AddEndpointsApiExplorer(); | ||||
| builder.Services.AddSwaggerGen(builder.Configuration, "Core.Thalos.Service.API.xml", authSettings); | ||||
| builder.Services.AddVersioning(builder.Configuration); | ||||
| builder.Services.RegisterExternalLayer(builder.Configuration); | ||||
| builder.Services.AddServiceConfigurationLayer(); | ||||
| builder.Services.AddResponseCompression(); | ||||
| @@ -44,11 +49,6 @@ builder.Host.ConfigureServices((context, services) => | ||||
|         options.SerializerOptions.Converters.Add(new JsonStringEnumConverter()); | ||||
|     }); | ||||
|  | ||||
|     services | ||||
|         .AddEndpointsApiExplorer() | ||||
|         .AddVersioning() | ||||
|         .AddSwagger(builder.Configuration); | ||||
|  | ||||
|     services.AddHealthChecks(); | ||||
|     services.AddHttpLogging(options => options.LoggingFields = HttpLoggingFields.All); | ||||
|  | ||||
| @@ -66,20 +66,22 @@ builder.Host.ConfigureServices((context, services) => | ||||
|  | ||||
| var app = builder.Build(); | ||||
|  | ||||
| app.UseLogging(builder.Configuration); | ||||
| app.UseSwaggerUI(builder.Configuration, authSettings); | ||||
| app.ConfigureSwagger(builder.Configuration); | ||||
|  | ||||
| app.UseRouting(); | ||||
| app.UseSwagger(); | ||||
| app.UseSwaggerUI(); | ||||
| app.UseAuthentication(); | ||||
| app.UseAuthorization(); | ||||
| app.MapControllers(); | ||||
| app.UseCors(); | ||||
| app.ConfigureSwagger(); | ||||
| app.UseHttpsRedirection(); | ||||
| app.UseStaticFiles(); | ||||
| app.UseResponseCompression(); | ||||
| app.UseOutputCache(); | ||||
| app.UseResponseCaching(); | ||||
| app.UseLogging(builder.Configuration); | ||||
|  | ||||
| app.UseAuthentication(); | ||||
| app.UseAuthorization(); | ||||
|  | ||||
| app.MapControllers(); | ||||
| app.MapHealthChecks("/health"); | ||||
|  | ||||
| app.Run(); | ||||
|   | ||||
| @@ -8,5 +8,18 @@ | ||||
|   "AllowedHosts": "*", | ||||
|   "LocalGateways": { | ||||
|     "ThalosDAL": "https://localhost:7031/api" | ||||
|   }, | ||||
|   "ServiceSettings": { | ||||
|     "ApplicationName": "thalos", | ||||
|     "LayerName": "service" | ||||
|   }, | ||||
|   "Vault": { | ||||
|     "Address": "http://100.123.31.103:8200", | ||||
|     "Token": "hvs.e37LQvLuPhTd5ALS5QQ03Cwm", | ||||
|     "SecretMount": "secret" | ||||
|   }, | ||||
|   "IdentityProviders": { | ||||
|     "Google": true, | ||||
|     "Azure": true | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -5,8 +5,5 @@ | ||||
|       "Microsoft.AspNetCore": "Warning" | ||||
|     } | ||||
|   }, | ||||
|   "AllowedHosts": "*", | ||||
|   "Endpoints": { | ||||
|     "AppConfigurationURI": "https://sandbox-hci-usc-appcg.azconfig.io" | ||||
|   } | ||||
|   "AllowedHosts": "*" | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user