Merge branch 'feature/configure-authentication' into development

This commit is contained in:
Sergio Matias Urquin 2025-07-27 19:33:30 -06:00
commit f3d63ca0e3
44 changed files with 81 additions and 495 deletions

View File

@ -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;

View File

@ -1,4 +1,4 @@
using Core.Thalos.Adapters.Common.Enums;
using Core.Blueprint.Mongo;
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.Application.UseCases.Modules.Input

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -1,4 +1,4 @@
using Core.Thalos.Adapters;
using Core.Thalos.BuildingBlocks;
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.Application.UseCases.Modules.Ports

View File

@ -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;

View File

@ -1,4 +1,4 @@
using Core.Thalos.Adapters.Common.Enums;
using Core.Blueprint.Mongo;
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.Application.UseCases.Permissions.Input

View File

@ -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

View File

@ -1,5 +1,4 @@
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
@ -10,7 +9,7 @@ namespace Core.Thalos.Application.UseCases.Permissions.Input
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;

View File

@ -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;

View File

@ -1,4 +1,4 @@
using Core.Thalos.Adapters;
using Core.Thalos.BuildingBlocks;
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.Application.UseCases.Permissions.Ports

View File

@ -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;

View File

@ -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

View File

@ -1,4 +1,4 @@
using Core.Thalos.Adapters.Common.Enums;
using Core.Blueprint.Mongo;
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.Application.UseCases.Roles.Input

View File

@ -1,4 +1,4 @@
using Core.Thalos.Adapters.Common.Enums;
using Core.Thalos.BuildingBlocks;
using Lib.Architecture.BuildingBlocks;
using System.Text.Json.Serialization;

View File

@ -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

View File

@ -1,4 +1,4 @@
using Core.Thalos.Adapters.Common.Enums;
using Core.Thalos.BuildingBlocks;
using Lib.Architecture.BuildingBlocks;
using System.Text.Json.Serialization;
@ -14,7 +14,7 @@ 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()
{

View File

@ -1,4 +1,4 @@
using Core.Thalos.Adapters;
using Core.Thalos.BuildingBlocks;
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.Application.UseCases.Roles.Ports

View File

@ -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;

View File

@ -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;

View File

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

View File

@ -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;
}
}
}

View File

@ -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;
}
}
}

View File

@ -1,4 +1,4 @@
using Core.Thalos.Adapters.Common.Enums;
using Core.Blueprint.Mongo;
using Lib.Architecture.BuildingBlocks;
namespace Core.Thalos.Application.UseCases.Users.Input

View File

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

View File

@ -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;
}
}
}

View File

@ -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;
}
}
}

View File

@ -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

View File

@ -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;
@ -15,10 +15,6 @@ namespace Core.Thalos.Application.UseCases.Users
IComponentHandler<GetUserRequest>,
IComponentHandler<GetUserByEmailRequest>,
IComponentHandler<CreateUserRequest>,
IComponentHandler<AddProjectToUserRequest>,
IComponentHandler<RemoveProjectFromUserRequest>,
IComponentHandler<AddCompanyToUserRequest>,
IComponentHandler<RemoveCompanyFromUserRequest>,
IComponentHandler<LoginUserRequest>,
IComponentHandler<LogoutUserRequest>,
IComponentHandler<ValidateUserExistenceRequest>,
@ -177,8 +173,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);
@ -217,8 +211,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.UpdateUserAsync(request, request.Id, cancellationToken).ConfigureAwait(false);
@ -281,94 +273,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

View File

@ -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;
@ -35,23 +32,11 @@ 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);
@ -65,7 +50,7 @@ namespace Core.Thalos.External.Clients
Task<RoleAdapter> UpdateRoleAsync([FromBody] RoleAdapter entity, [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);
@ -89,7 +74,7 @@ namespace Core.Thalos.External.Clients
Task<PermissionAdapter> UpdatePermissionAsync([FromBody] PermissionAdapter entity, [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);
@ -107,6 +92,6 @@ namespace Core.Thalos.External.Clients
Task<ModuleAdapter> UpdateModuleAsync([FromBody] ModuleAdapter entity, [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);
}
}

View File

@ -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

View File

@ -1,4 +1,4 @@
using Core.Thalos.Adapters.Common.Constants;
using Core.Thalos.BuildingBlocks;
namespace Core.Thalos.External.Clients.Requests
{

View File

@ -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

View File

@ -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; }
}
}

View File

@ -7,8 +7,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Core.Blueprint.Storage" Version="1.0.0" />
<PackageReference Include="Core.Thalos.BuildingBlocks" Version="1.0.5" />
<PackageReference Include="Core.Blueprint.Storage" Version="1.0.1" />
<PackageReference Include="Core.Thalos.BuildingBlocks" Version="1.0.8" />
<PackageReference Include="Lib.Architecture.BuildingBlocks" Version="1.0.0" />
<PackageReference Include="Refit" Version="8.0.0" />
</ItemGroup>

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;
@ -25,10 +23,6 @@ namespace Core.Thalos.Service.API.Controllers
private readonly IComponentHandler<CreateUserRequest> createUserHandler;
private readonly IComponentHandler<UpdateUserRequest> updateUserHandler;
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;
@ -45,10 +39,6 @@ namespace Core.Thalos.Service.API.Controllers
IComponentHandler<CreateUserRequest> createUserHandler,
IComponentHandler<UpdateUserRequest> updateUserHandler,
IComponentHandler<ChangeUserStatusRequest> changeUserStatusHandler,
IComponentHandler<AddCompanyToUserRequest> addCompanyToUserHandler,
IComponentHandler<RemoveCompanyFromUserRequest> removeCompanyFromUserHandler,
IComponentHandler<AddProjectToUserRequest> addProjectToUserHandler,
IComponentHandler<RemoveProjectFromUserRequest> removeProjectFromUserHandler,
IComponentHandler<LoginUserRequest> loginUserHandler,
IComponentHandler<LogoutUserRequest> logoutUserHandler,
IComponentHandler<ValidateUserExistenceRequest> validateUserHandler,
@ -62,10 +52,6 @@ namespace Core.Thalos.Service.API.Controllers
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;
@ -244,107 +230,6 @@ namespace Core.Thalos.Service.API.Controllers
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>

View File

@ -35,10 +35,6 @@ namespace Core.Thalos.Service.API.Extensions
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>();

View File

@ -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("+", "."));
}
}
}

View File

@ -1,6 +1,7 @@
using Core.Blueprint.KeyVault.Configuration;
using Core.Blueprint.Logging.Configuration;
using Core.Thalos.Adapters.Extensions;
using Core.Thalos.BuildingBlocks.Authentication.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;
@ -9,16 +10,21 @@ using System.Text.Json.Serialization;
var builder = WebApplication.CreateBuilder(args);
builder.Services.ConfigureAuthentication(builder.Configuration);
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();
@ -43,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);
@ -65,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();

View File

@ -9,17 +9,17 @@
"LocalGateways": {
"ThalosDAL": "https://localhost:7031/api"
},
"Authentication": {
"Google": {
"ClientId": "128345072002-mtfdgpcur44o9tbd7q6e0bb9qnp2crfp.apps.googleusercontent.com",
"ClientSecret": "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",
"ApplicationName": "Thalos",
"RedirectUri": "https://localhost:7239/api/v1/Authentication/callback"
}
"ServiceSettings": {
"ApplicationName": "thalos",
"LayerName": "service"
},
"JwtIssuerOptions": {
"Audience": "https://localhost:7239/",
"Issuer": "webApi"
"Vault": {
"Address": "http://100.123.31.103:8200",
"Token": "hvs.e37LQvLuPhTd5ALS5QQ03Cwm",
"SecretMount": "secret"
},
"SecretKey": "iNivDmHLpUA223sqsfhqGbMRdRj1PVkH1"
"IdentityProviders": {
"Google": true,
"Azure": true
}
}