Add tenant services and delete services

This commit is contained in:
2025-08-07 18:37:26 -06:00
parent 6a055bc3db
commit 69e21e276c
30 changed files with 385 additions and 30 deletions

View File

@@ -93,7 +93,7 @@ namespace Core.Thalos.BFF.Api.Controllers
[HttpGet]
[Route(Routes.RefreshToken)]
[ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)]
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
public async Task<IActionResult> RefreshCustomTokenAsync(CancellationToken cancellationToken)
{
var tokenAdapter = new TokenAdapter();

View File

@@ -21,7 +21,7 @@ namespace Core.Thalos.BFF.Api.Controllers
public class ModuleController(IThalosServiceClient thalosServiceClient, ILogger<ModuleController> logger) : BaseController(logger)
{
/// <summary>
/// Gets all the modules.
/// Gets all modules.
/// </summary>
[HttpGet("GetAll")]
[ProducesResponseType(StatusCodes.Status200OK)]
@@ -47,7 +47,7 @@ namespace Core.Thalos.BFF.Api.Controllers
}
/// <summary>
/// Gets all the modules by module identifiers.
/// Gets all modules by module identifiers.
/// </summary>
/// <param name="request">The request containing the list of module identifiers.</param>
/// <param name="cancellationToken">Cancellation token for the asynchronous operation.</param>
@@ -137,7 +137,7 @@ namespace Core.Thalos.BFF.Api.Controllers
{
logger.LogInformation($"{nameof(GetModuleByIdService)} - Request received - Payload: {JsonSerializer.Serialize(request)}");
if (string.IsNullOrEmpty(request.Id)) return BadRequest("Invalid module identifier");
if (string.IsNullOrEmpty(request._Id)) return BadRequest("Invalid module identifier");
return await Handle(() => thalosServiceClient.GetModuleByIdService(request, cancellationToken)).ConfigureAwait(false);
}
@@ -201,7 +201,7 @@ namespace Core.Thalos.BFF.Api.Controllers
{
logger.LogInformation($"{nameof(ChangeModuleStatusService)} - Request received - Payload: {JsonSerializer.Serialize(request)}");
if (string.IsNullOrEmpty(request.Id)) { return BadRequest("Invalid module identifier"); }
if (string.IsNullOrEmpty(request._Id)) { return BadRequest("Invalid module identifier"); }
return await Handle(() => thalosServiceClient.ChangeModuleStatusService(request, cancellationToken)).ConfigureAwait(false);
}

View File

@@ -5,7 +5,6 @@ using Lib.Architecture.BuildingBlocks;
using LSA.Dashboard.External.Clients.Dashboard;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Graph;
using System.Text.Json;
namespace Core.Thalos.BFF.Api.Controllers
@@ -22,7 +21,7 @@ namespace Core.Thalos.BFF.Api.Controllers
public class PermissionController(IThalosServiceClient thalosServiceClient, ILogger<PermissionController> logger) : BaseController(logger)
{
/// <summary>
/// Gets all the permissions.
/// Gets all permissions.
/// </summary>
[HttpGet("GetAll")]
[ProducesResponseType(StatusCodes.Status200OK)]
@@ -48,7 +47,7 @@ namespace Core.Thalos.BFF.Api.Controllers
}
/// <summary>
/// Gets all the permissions by permission identifiers.
/// Gets all permissions by permission identifiers.
/// </summary>
/// <param name="request">The request containing the list of permission identifiers.</param>
/// <param name="cancellationToken">Cancellation token for the asynchronous operation.</param>
@@ -136,7 +135,7 @@ namespace Core.Thalos.BFF.Api.Controllers
{
logger.LogInformation($"{nameof(GetPermissionByIdService)} - Request received - Payload: {JsonSerializer.Serialize(request)}");
if (string.IsNullOrEmpty(request.Id)) return BadRequest("Invalid permission identifier");
if (string.IsNullOrEmpty(request._Id)) return BadRequest("Invalid permission identifier");
return await Handle(() => thalosServiceClient.GetPermissionByIdService(request, cancellationToken)).ConfigureAwait(false);
}
@@ -198,7 +197,7 @@ namespace Core.Thalos.BFF.Api.Controllers
{
logger.LogInformation($"{nameof(ChangePermissionStatusService)} - Request received - Payload: {JsonSerializer.Serialize(request)}");
if (string.IsNullOrEmpty(request.Id)) { return BadRequest("Invalid permission identifier"); }
if (string.IsNullOrEmpty(request._Id)) { return BadRequest("Invalid permission identifier"); }
return await Handle(() => thalosServiceClient.ChangePermissionStatusService(request, cancellationToken)).ConfigureAwait(false);
}

View File

@@ -21,7 +21,7 @@ namespace Core.Thalos.BFF.Api.Controllers
public class RoleController(IThalosServiceClient thalosServiceClient, ILogger<RoleController> logger) : BaseController(logger)
{
/// <summary>
/// Gets all the roles.
/// Gets all roles.
/// </summary>
[HttpGet("GetAll")]
[ProducesResponseType(StatusCodes.Status200OK)]
@@ -101,7 +101,7 @@ namespace Core.Thalos.BFF.Api.Controllers
{
logger.LogInformation($"{nameof(GetRoleByIdService)} - Request received - Payload: {JsonSerializer.Serialize(request)}");
if (string.IsNullOrEmpty(request.Id)) return BadRequest("Invalid role identifier");
if (string.IsNullOrEmpty(request._Id)) return BadRequest("Invalid role identifier");
return await Handle(() => thalosServiceClient.GetRoleByIdService(request, cancellationToken)).ConfigureAwait(false);
}
@@ -133,7 +133,7 @@ namespace Core.Thalos.BFF.Api.Controllers
if (string.IsNullOrEmpty(request.Name)) return BadRequest("Invalid role name");
if (string.IsNullOrEmpty(request.Id)) return BadRequest("Invalid role identifier");
if (string.IsNullOrEmpty(request._Id)) return BadRequest("Invalid role identifier");
if (string.IsNullOrEmpty(request.Description)) return BadRequest("Invalid role description");
@@ -172,7 +172,7 @@ namespace Core.Thalos.BFF.Api.Controllers
{
logger.LogInformation($"{nameof(ChangeRoleStatusService)} - Request received - Payload: {JsonSerializer.Serialize(request)}");
if (string.IsNullOrEmpty(request.Id)) { return BadRequest("Invalid role identifier"); }
if (string.IsNullOrEmpty(request._Id)) { return BadRequest("Invalid role identifier"); }
return await Handle(() => thalosServiceClient.ChangeRoleStatusService(request, cancellationToken)).ConfigureAwait(false);
}

View File

@@ -0,0 +1,196 @@
using Asp.Versioning;
using Core.Thalos.BuildingBlocks;
using Core.Thalos.External.Clients.Thalos.Requests.Tenants;
using Lib.Architecture.BuildingBlocks;
using LSA.Dashboard.External.Clients.Dashboard;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Text.Json;
namespace Core.Thalos.BFF.Api.Controllers
{
/// <summary>
/// Handles all requests for Tenant authentication.
/// </summary>
[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/[controller]")]
[Consumes("application/json")]
[Produces("application/json")]
[ApiController]
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
public class TenantController(IThalosServiceClient thalosServiceClient, ILogger<TenantController> logger) : BaseController(logger)
{
/// <summary>
/// Gets all Tenants.
/// </summary>
[HttpGet("GetAll")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
[Permission("TenantManagement.Read, RoleManagement.Read")]
public async Task<IActionResult> GetAllTenantsService(CancellationToken cancellationToken)
{
try
{
logger.LogInformation($"{nameof(GetAllTenantsService)} - Request received - Payload: ");
return await Handle(() => thalosServiceClient.GetAllTenantsService(new GetAllTenantsRequest { }, cancellationToken)).ConfigureAwait(false);
}
catch (Exception ex)
{
logger.LogError($"{nameof(GetAllTenantsService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload");
throw;
}
}
/// <summary>
/// Creates a new Tenant.
/// </summary>
[HttpPost("Create")]
[ProducesResponseType(StatusCodes.Status200OK)]
[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> CreateTenantService(CreateTenantRequest newTenant, CancellationToken cancellationToken)
{
try
{
logger.LogInformation($"{nameof(CreateTenantService)} - Request received - Payload: {JsonSerializer.Serialize(newTenant)}");
if (newTenant == null) return BadRequest("Invalid Tenant object");
if (string.IsNullOrEmpty(newTenant.Name)) return BadRequest("Invalid Tenant name");
return await Handle(() => thalosServiceClient.CreateTenantService(newTenant, cancellationToken)).ConfigureAwait(false);
}
catch (Exception ex)
{
logger.LogError($"{nameof(CreateTenantService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(newTenant)}");
throw;
}
}
/// <summary>
/// Gets the Tenant by identifier.
/// </summary>
[HttpPost("GetById")]
[ProducesResponseType(StatusCodes.Status200OK)]
[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> GetTenantByIdService(GetTenantRequest request, CancellationToken cancellationToken)
{
try
{
logger.LogInformation($"{nameof(GetTenantByIdService)} - Request received - Payload: {JsonSerializer.Serialize(request)}");
if (string.IsNullOrEmpty(request._Id)) return BadRequest("Invalid Tenant identifier");
return await Handle(() => thalosServiceClient.GetTenantByIdService(request, cancellationToken)).ConfigureAwait(false);
}
catch (Exception ex)
{
logger.LogError($"{nameof(GetTenantByIdService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}");
throw;
}
}
/// <summary>
/// Updates a full Tenant by identifier.
/// </summary>
[HttpPut("Update")]
[ProducesResponseType(StatusCodes.Status200OK)]
[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> UpdateTenantService(UpdateTenantRequest newTenant, CancellationToken cancellationToken)
{
try
{
logger.LogInformation($"{nameof(UpdateTenantService)} - Request received - Payload: {JsonSerializer.Serialize(newTenant)}");
if (newTenant == null) return BadRequest("Invalid Tenant object");
if (string.IsNullOrEmpty(newTenant.Name)) return BadRequest("Invalid Tenant name");
return await Handle(() => thalosServiceClient.UpdateTenantService(newTenant, cancellationToken)).ConfigureAwait(false);
}
catch (Exception ex)
{
logger.LogError($"{nameof(UpdateTenantService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(newTenant)}");
throw;
}
}
/// <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> ChangeTenantStatusService([FromBody] ChangeTenantStatusRequest request, CancellationToken cancellationToken)
{
try
{
logger.LogInformation($"{nameof(ChangeTenantStatusService)} - Request received - Payload: {JsonSerializer.Serialize(request)}");
if (string.IsNullOrEmpty(request._Id)) { return BadRequest("Invalid Tenant identifier"); }
return await Handle(() => thalosServiceClient.ChangeTenantStatusService(request, cancellationToken)).ConfigureAwait(false);
}
catch (Exception ex)
{
logger.LogError($"{nameof(ChangeTenantStatusService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}");
throw;
}
}
/// <summary>
/// Deletes the Tenant by identifier.
/// </summary>
[HttpDelete("Delete")]
[ProducesResponseType(StatusCodes.Status200OK)]
[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> DeleteTenantByIdService(DeleteTenantRequest request, CancellationToken cancellationToken)
{
try
{
logger.LogInformation($"{nameof(DeleteTenantByIdService)} - Request received - Payload: {JsonSerializer.Serialize(request)}");
if (string.IsNullOrEmpty(request._Id)) return BadRequest("Invalid Tenant identifier");
return await Handle(() => thalosServiceClient.DeleteTenantByIdService(request, cancellationToken)).ConfigureAwait(false);
}
catch (Exception ex)
{
logger.LogError($"{nameof(DeleteTenantByIdService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}");
throw;
}
}
}
}

View File

@@ -21,7 +21,7 @@ namespace Core.Thalos.BFF.Api.Controllers
public class UserController(IThalosServiceClient thalosServiceClient, ILogger<UserController> logger) : BaseController(logger)
{
/// <summary>
/// Gets all the users.
/// Gets all users.
/// </summary>
[HttpGet("GetAll")]
[ProducesResponseType(StatusCodes.Status200OK)]
@@ -102,7 +102,7 @@ namespace Core.Thalos.BFF.Api.Controllers
{
logger.LogInformation($"{nameof(GetUserByIdService)} - Request received - Payload: {JsonSerializer.Serialize(request)}");
if (string.IsNullOrEmpty(request.Id)) return BadRequest("Invalid user identifier");
if (string.IsNullOrEmpty(request._Id)) return BadRequest("Invalid user identifier");
return await Handle(() => thalosServiceClient.GetUserByIdService(request, cancellationToken)).ConfigureAwait(false);
}
@@ -257,7 +257,7 @@ namespace Core.Thalos.BFF.Api.Controllers
{
logger.LogInformation($"{nameof(ChangeUserStatusService)} - Request received - Payload: {JsonSerializer.Serialize(request)}");
if (string.IsNullOrEmpty(request.Id)) { return BadRequest("Invalid user identifier"); }
if (string.IsNullOrEmpty(request._Id)) { return BadRequest("Invalid user identifier"); }
return await Handle(() => thalosServiceClient.ChangeUserStatusService(request, cancellationToken)).ConfigureAwait(false);
}