Add tenant services

This commit is contained in:
2025-08-03 15:19:16 -06:00
parent 7c92a7e791
commit 0eadd6e217
18 changed files with 1134 additions and 514 deletions

View File

@@ -27,11 +27,11 @@ namespace LSA.Core.Thalos.API.Controllers
public class PermissionController(IPermissionProvider service) : ControllerBase
{
/// <summary>
/// Gets all the permissions.
/// Gets all permissions.
/// </summary>
/// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
/// <returns>The <see cref="IEnumerable{PermissionAdapter}"/> found entities.</returns>
/// <response code="200">The roles found.</response>
/// <response code="404">The roles not found error.</response>
/// <response code="200">The permissions found.</response>
/// <response code="500">The service internal error.</response>
[HttpGet]
[Consumes(MimeTypes.ApplicationJson)]
@@ -48,9 +48,10 @@ namespace LSA.Core.Thalos.API.Controllers
/// Gets all the permissions by permission identifiers.
/// </summary>
/// <param name="permissions">The list of permission identifiers.</param>
/// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
/// <returns>The <see cref="IEnumerable{PermissionAdapter}"/> found entities.</returns>
/// <response code="200">The permissions found.</response>
/// <response code="404">The permissions not found error.</response>
/// <response code="400">Bad request if list is null or empty.</response>
/// <response code="500">The service internal error.</response>
[HttpPost]
[Route(Routes.GetPermissionList)]
@@ -70,12 +71,13 @@ namespace LSA.Core.Thalos.API.Controllers
}
/// <summary>
/// Gets the permission by identifier.
/// Gets the permission by mongo identifier.
/// </summary>
/// <param name="id">The permission identifier.</param>
/// <param name="_id">The permission mongo identifier.</param>
/// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
/// <returns>The <see cref="PermissionAdapter"/> found entity.</returns>
/// <response code="200">The permission found.</response>
/// <response code="404">The permission not found error.</response>
/// <response code="404">The permission not found.</response>
/// <response code="500">The service internal error.</response>
[HttpGet]
[Route(Routes.Id)]
@@ -83,9 +85,9 @@ namespace LSA.Core.Thalos.API.Controllers
[Produces(MimeTypes.ApplicationJson)]
[ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)]
[Permission("PermissionManagement.Read")]
public async Task<IActionResult> GetPermissionByIdAsync([FromRoute] string id, CancellationToken cancellationToken)
public async Task<IActionResult> GetPermissionByIdAsync([FromRoute] string _id, CancellationToken cancellationToken)
{
var result = await service.GetPermissionById(id, cancellationToken).ConfigureAwait(false);
var result = await service.GetPermissionById(_id, cancellationToken).ConfigureAwait(false);
if (result == null)
{
@@ -99,10 +101,11 @@ namespace LSA.Core.Thalos.API.Controllers
/// Creates a new permission.
/// </summary>
/// <param name="newPermission">The permission to be added.</param>
/// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
/// <returns>The <see cref="PermissionAdapter"/> created entity.</returns>
/// <response code="201">The permission created.</response>
/// <response code="422">The permission could not be created.</response>
/// <response code="500">The service internal e|ror.</response>
/// <response code="500">Internal server error.</response>
[HttpPost]
[ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status201Created)]
[Permission("PermissionManagement.Write")]
@@ -113,24 +116,25 @@ namespace LSA.Core.Thalos.API.Controllers
}
/// <summary>
/// Updates a full permission by identifier.
/// Updates a full permission by mongo identifier.
/// </summary>
/// <param name="_id">The permission mongo identifier.</param>
/// <param name="entity">The permission to update.</param>
/// <param name="id">The permission identifier.</param>
/// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
/// <returns>The <see cref="PermissionAdapter"/> updated entity.</returns>
/// <response code="200">The permission updated.</response>
/// <response code="404">The permission not found.</response>
/// <response code="400">Bad request if ID mismatch.</response>
/// <response code="422">The permission could not be updated.</response>
/// <response code="500">The service internal error.</response>
/// <response code="500">Internal server error.</response>
[HttpPut]
[Route(Routes.Id)]
[Consumes(MimeTypes.ApplicationJson)]
[Produces(MimeTypes.ApplicationJson)]
[ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)]
[Permission("PermissionManagement.Write")]
public async Task<IActionResult> UpdatePermissionAsync([FromRoute] string id, PermissionAdapter entity, CancellationToken cancellationToken)
public async Task<IActionResult> UpdatePermissionAsync([FromRoute] string _id, [FromBody] PermissionAdapter entity, CancellationToken cancellationToken)
{
if (id != entity.Id?.ToString())
if (_id != entity._Id)
{
return BadRequest("Permission ID mismatch");
}
@@ -143,22 +147,44 @@ namespace LSA.Core.Thalos.API.Controllers
/// <summary>
/// Changes the status of the permission.
/// </summary>
/// <param name="id">The permission identifier.</param>
/// <param name="_id">The permission mongo identifier.</param>
/// <param name="newStatus">The new status of the permission.</param>
/// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
/// <returns>The <see cref="PermissionAdapter"/> updated entity.</returns>
/// <response code="200">The permission updates.</response>
/// <response code="404">The permission not found.</response>
/// <response code="422">The permission could not be deleted.</response>
/// <response code="500">The service internal error.</response>
/// <response code="200">The permission status was updated.</response>
/// <response code="500">Internal server error.</response>
[HttpPatch]
[Route(Routes.ChangeStatus)]
[Consumes(MimeTypes.ApplicationJson)]
[Produces(MimeTypes.ApplicationJson)]
[ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)]
[Permission("PermissionManagement.Write")]
public async Task<IActionResult> ChangePermissionStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken)
public async Task<IActionResult> ChangePermissionStatus([FromRoute] string _id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken)
{
var result = await service.ChangePermissionStatus(id, newStatus, cancellationToken).ConfigureAwait(false);
var result = await service.ChangePermissionStatus(_id, newStatus, cancellationToken).ConfigureAwait(false);
return Ok(result);
}
/// <summary>
/// Deletes a permission by its mongo identifier.
/// </summary>
/// <param name="_id">The permission mongo identifier.</param>
/// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
/// <returns>The deleted <see cref="PermissionAdapter"/> entity.</returns>
/// <response code="200">The permission was successfully deleted.</response>
/// <response code="404">The permission was not found.</response>
/// <response code="500">Internal server error occurred.</response>
[HttpDelete]
[Route(Routes.Id)]
[ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)]
[Permission("PermissionManagement.Write")]
public async Task<IActionResult> DeletePermissionAsync([FromRoute] string _id, CancellationToken cancellationToken)
{
var result = await service.DeletePermission(_id, cancellationToken).ConfigureAwait(false);
if (result is null)
return NotFound("Permission not found.");
return Ok(result);
}
}