Add project files.

This commit is contained in:
Sergio Matias Urquin
2025-04-29 18:37:40 -06:00
parent ef5b7ed2ca
commit dacb004ae9
43 changed files with 1432 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
using Lib.Architecture.BuildingBlocks.Presentation.Adapters;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Refit;
namespace Core.Blueprint.API.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class BaseController(ILogger<BaseController> logger) : ControllerBase
{
private readonly ILogger<BaseController> _logger = logger;
protected Guid TrackingId => (Guid)(HttpContext.Items["TrackingId"] ?? Guid.NewGuid());
protected async Task<IActionResult> Handle<T>(Func<Task<ApiResponse<T>>> apiCall) where T : class
{
var response = await apiCall().ConfigureAwait(false);
_logger.LogInformation($"{TrackingId} - {response.RequestMessage?.Method} {response.RequestMessage?.RequestUri} - Status: {response.StatusCode}");
return FromAPIResponse(response);
}
private IActionResult FromAPIResponse<T>(ApiResponse<T> response) where T : class
{
if (response.IsSuccessful)
return StatusCode((int)response.StatusCode, response.Content);
else
{
dynamic errorContent = string.Empty;
try
{
errorContent = JsonConvert.DeserializeObject<string>(response.Error?.Content ?? string.Empty) ?? string.Empty;
}
catch (Exception)
{
errorContent = JsonConvert.DeserializeObject<HttpError>(response.Error?.Content);
if (errorContent?.Error?.ErrorCode is null && errorContent?.Error?.Message is null && errorContent?.Error?.Target is null)
errorContent = JsonConvert.DeserializeObject<GenericErrorResponse>(response.Error?.Content);
}
return StatusCode((int)response.StatusCode, errorContent);
}
}
}
}

View File

@@ -0,0 +1,130 @@
using Core.Blueprint.API.Controllers;
using Core.Blueprint.External.Clients.Blueprint;
using Core.Blueprint.External.Clients.Blueprint.Requests.BlobStorage;
using Lib.Architecture.BuildingBlocks;
using Microsoft.AspNetCore.Mvc;
using System.Text.Json;
namespace Core.Blob.API.Controllers
{
/// <summary>
/// Handles all requests for blob.
/// </summary>
[ApiVersion("1.0")]
//[Route("api/v{version:apiVersion}/[controller]")]
[Consumes("application/json")]
[Produces("application/json")]
[ApiController]
public class BlobStorageController(IBlueprintServiceClient blueprintServiceClient, ILogger<BlobStorageController> logger) : BaseController(logger)
{
/// <summary>
/// Uploads a new blob.
/// </summary>
[HttpPost("UploadBlob")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> UploadBlobService(UploadBlobRequest newBlob, CancellationToken cancellationToken)
{
try
{
logger.LogInformation($"{nameof(UploadBlobService)} - Request received - Payload: {JsonSerializer.Serialize(newBlob)}");
if (newBlob == null) return BadRequest("Invalid blob object");
if (string.IsNullOrEmpty(newBlob.BlobName)) return BadRequest("Invalid blob name");
if (newBlob.BlobContent is null) return BadRequest("Invalid blob content");
return await Handle(() => blueprintServiceClient.UploadBlobService(newBlob, cancellationToken)).ConfigureAwait(false);
}
catch (Exception ex)
{
logger.LogError($"{nameof(UploadBlobService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(newBlob)}");
throw;
}
}
/// <summary>
/// Gets all blobs into the container.
/// </summary>
[HttpGet("GetBlobList")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> GetBlobListService([FromQuery] string? prefix, CancellationToken cancellationToken)
{
try
{
logger.LogInformation($"{nameof(GetBlobListService)} - Request received - Payload: ");
return await Handle(() => blueprintServiceClient.GetBlobListAsync(prefix, cancellationToken)).ConfigureAwait(false);
}
catch (Exception ex)
{
logger.LogError($"{nameof(GetBlobListService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload");
throw;
}
}
/// <summary>
/// Donwloads a blob by name.
/// </summary>
[HttpPost("DownloadBlob")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> DownloadBlobService(DownloadBlobRequest request, CancellationToken cancellationToken)
{
try
{
logger.LogInformation($"{nameof(DownloadBlobService)} - Request received - Payload: {JsonSerializer.Serialize(request)}");
if (string.IsNullOrEmpty(request.BlobName)) return BadRequest("Invalid blob name");
return await Handle(() => blueprintServiceClient.DownloadBlobAsync(request, cancellationToken)).ConfigureAwait(false);
}
catch (Exception ex)
{
logger.LogError($"{nameof(DownloadBlobService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}");
throw;
}
}
/// <summary>
/// Deletes the blob 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)]
public async Task<IActionResult> DeleteBlobService([FromBody] DeleteBlobRequest request, CancellationToken cancellationToken)
{
try
{
logger.LogInformation($"{nameof(DeleteBlobService)} - Request received - Payload: {JsonSerializer.Serialize(request)}");
if (string.IsNullOrEmpty(request.BlobName)) return BadRequest("Invalid blob name");
return await Handle(() => blueprintServiceClient.DeleteBlobService(request, cancellationToken)).ConfigureAwait(false);
}
catch (Exception ex)
{
logger.LogError($"{nameof(DeleteBlobService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}");
throw;
}
}
}
}

View File

@@ -0,0 +1,136 @@
using Core.Blueprint.API.Controllers;
using Core.Blueprint.External.Clients.Blueprint;
using Core.Blueprint.External.Clients.Blueprint.Requests.KeyVault;
using Lib.Architecture.BuildingBlocks;
using Microsoft.AspNetCore.Mvc;
using System.Text.Json;
namespace Core.Secret.API.Controllers
{
/// <summary>
/// Handles all requests for secret.
/// </summary>
[ApiVersion("1.0")]
//[Route("api/v{version:apiVersion}/[controller]")]
[Consumes("application/json")]
[Produces("application/json")]
[ApiController]
public class KeyVaultController(IBlueprintServiceClient blueprintServiceClient, ILogger<KeyVaultController> logger) : BaseController(logger)
{
/// <summary>
/// Creates a new secret.
/// </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)]
public async Task<IActionResult> CreateSecretService(CreateSecretRequest newSecret, CancellationToken cancellationToken)
{
try
{
logger.LogInformation($"{nameof(CreateSecretService)} - Request received - Payload: {JsonSerializer.Serialize(newSecret)}");
if (newSecret == null) return BadRequest("Invalid secret object");
if (string.IsNullOrEmpty(newSecret.Name)) return BadRequest("Invalid secret name");
if (string.IsNullOrEmpty(newSecret.Value)) return BadRequest("Invalid secret description");
return await Handle(() => blueprintServiceClient.CreateSecretService(newSecret, cancellationToken)).ConfigureAwait(false);
}
catch (Exception ex)
{
logger.LogError($"{nameof(CreateSecretService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(newSecret)}");
throw;
}
}
/// <summary>
/// Gets the secret by identifier.
/// </summary>
[HttpPost("GetSecretByName")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> GetSecretByNameService(GetSecretRequest request, CancellationToken cancellationToken)
{
try
{
logger.LogInformation($"{nameof(GetSecretByNameService)} - Request received - Payload: {JsonSerializer.Serialize(request)}");
if (string.IsNullOrEmpty(request.Name)) return BadRequest("Invalid secret name");
return await Handle(() => blueprintServiceClient.GetSecretByNameService(request, cancellationToken)).ConfigureAwait(false);
}
catch (Exception ex)
{
logger.LogError($"{nameof(GetSecretByNameService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}");
throw;
}
}
/// <summary>
/// Updates a full secret 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)]
public async Task<IActionResult> UpdateSecretService(UpdateSecretRequest newSecret, CancellationToken cancellationToken)
{
try
{
logger.LogInformation($"{nameof(UpdateSecretService)} - Request received - Payload: {JsonSerializer.Serialize(newSecret)}");
if (newSecret == null) return BadRequest("Invalid secret object");
if (string.IsNullOrEmpty(newSecret.Name)) return BadRequest("Invalid secret name");
if (string.IsNullOrEmpty(newSecret.Value)) return BadRequest("Invalid secret value");
return await Handle(() => blueprintServiceClient.UpdateSecretService(newSecret, cancellationToken)).ConfigureAwait(false);
}
catch (Exception ex)
{
logger.LogError($"{nameof(UpdateSecretService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(newSecret)}");
throw;
}
}
/// <summary>
/// Deletes the secret by identifier.
/// </summary>
[HttpPost("Delete")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> DeleteSecretService(DeleteSecretRequest request, CancellationToken cancellationToken)
{
try
{
logger.LogInformation($"{nameof(DeleteSecretService)} - Request received - Payload: {JsonSerializer.Serialize(request)}");
if (string.IsNullOrEmpty(request.Name)) return BadRequest("Invalid secret name");
return await Handle(() => blueprintServiceClient.DeleteSecretService(request, cancellationToken)).ConfigureAwait(false);
}
catch (Exception ex)
{
logger.LogError($"{nameof(DeleteSecretService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}");
throw;
}
}
}
}

View File

@@ -0,0 +1,160 @@
using Core.Blueprint.External.Clients.Blueprint;
using Core.Blueprint.External.Clients.Blueprint.Requests.Mongo;
using Lib.Architecture.BuildingBlocks;
using Microsoft.AspNetCore.Mvc;
using System.Text.Json;
namespace Core.Blueprint.API.Controllers
{
/// <summary>
/// Handles all requests for blueprint.
/// </summary>
[ApiVersion("1.0")]
//[Route("api/v{version:apiVersion}/[controller]")]
[Consumes("application/json")]
[Produces("application/json")]
[ApiController]
public class MongoBlueprintController(IBlueprintServiceClient blueprintServiceClient, ILogger<MongoBlueprintController> logger) : BaseController(logger)
{
/// <summary>
/// Creates a new blueprint.
/// </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)]
public async Task<IActionResult> CreateBlueprintService(CreateBlueprintRequest newBlueprint, CancellationToken cancellationToken)
{
try
{
logger.LogInformation($"{nameof(CreateBlueprintService)} - Request received - Payload: {JsonSerializer.Serialize(newBlueprint)}");
if (newBlueprint == null) return BadRequest("Invalid blueprint object");
if (string.IsNullOrEmpty(newBlueprint.Name)) return BadRequest("Invalid blueprint name");
if (string.IsNullOrEmpty(newBlueprint.Description)) return BadRequest("Invalid blueprint description");
return await Handle(() => blueprintServiceClient.CreateBlueprintService(newBlueprint, cancellationToken)).ConfigureAwait(false);
}
catch (Exception ex)
{
logger.LogError($"{nameof(CreateBlueprintService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(newBlueprint)}");
throw;
}
}
/// <summary>
/// Gets all blueprints.
/// </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)]
public async Task<IActionResult> GetAllBlueprintsService(CancellationToken cancellationToken)
{
try
{
logger.LogInformation($"{nameof(GetAllBlueprintsService)} - Request received - Payload: ");
return await Handle(() => blueprintServiceClient.GetAllBlueprintsService(cancellationToken)).ConfigureAwait(false);
}
catch (Exception ex)
{
logger.LogError($"{nameof(GetAllBlueprintsService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload");
throw;
}
}
/// <summary>
/// Gets the blueprint 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)]
public async Task<IActionResult> GetBlueprintByIdService(GetBlueprintRequest request, CancellationToken cancellationToken)
{
try
{
logger.LogInformation($"{nameof(GetBlueprintByIdService)} - Request received - Payload: {JsonSerializer.Serialize(request)}");
if (string.IsNullOrEmpty(request._Id)) return BadRequest("Invalid blueprint identifier");
return await Handle(() => blueprintServiceClient.GetBlueprintByIdService(request, cancellationToken)).ConfigureAwait(false);
}
catch (Exception ex)
{
logger.LogError($"{nameof(GetBlueprintByIdService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}");
throw;
}
}
/// <summary>
/// Updates a full blueprint 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)]
public async Task<IActionResult> UpdateBlueprintService(UpdateBlueprintRequest newBlueprint, CancellationToken cancellationToken)
{
try
{
logger.LogInformation($"{nameof(UpdateBlueprintService)} - Request received - Payload: {JsonSerializer.Serialize(newBlueprint)}");
if (newBlueprint == null) return BadRequest("Invalid blueprint object");
if (string.IsNullOrEmpty(newBlueprint.Name)) return BadRequest("Invalid blueprint name");
if (string.IsNullOrEmpty(newBlueprint.Description)) return BadRequest("Invalid blueprint description");
return await Handle(() => blueprintServiceClient.UpdateBlueprintService(newBlueprint, cancellationToken)).ConfigureAwait(false);
}
catch (Exception ex)
{
logger.LogError($"{nameof(UpdateBlueprintService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(newBlueprint)}");
throw;
}
}
/// <summary>
/// Deletes the blueprint by identifier.
/// </summary>
[HttpPost("Delete")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> DeleteBlueprintService(DeleteBlueprintRequest request, CancellationToken cancellationToken)
{
try
{
logger.LogInformation($"{nameof(DeleteBlueprintService)} - Request received - Payload: {JsonSerializer.Serialize(request)}");
if (string.IsNullOrEmpty(request._Id)) return BadRequest("Invalid blueprint identifier");
return await Handle(() => blueprintServiceClient.DeleteBlueprintService(request, cancellationToken)).ConfigureAwait(false);
}
catch (Exception ex)
{
logger.LogError($"{nameof(DeleteBlueprintService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}");
throw;
}
}
}
}

View File

@@ -0,0 +1,165 @@
using Core.Blueprint.API.Controllers;
using Core.Blueprint.External.Clients.Blueprint;
using Core.Blueprint.External.Clients.Blueprint.Requests.SQL;
using Lib.Architecture.BuildingBlocks;
using Microsoft.AspNetCore.Mvc;
using System.Text.Json;
namespace Core.UserProject.API.Controllers
{
/// <summary>
/// Handles all requests for user project.
/// </summary>
[ApiVersion("1.0")]
//[Route("api/v{version:apiVersion}/[controller]")]
[Consumes("application/json")]
[Produces("application/json")]
[ApiController]
public class SQLUserProjectController(IBlueprintServiceClient blueprintServiceClient, ILogger<SQLUserProjectController> logger) : BaseController(logger)
{
/// <summary>
/// Creates a new user project.
/// </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)]
public async Task<IActionResult> CreateUserProjectService(CreateUserProjectRequest newUserProject, CancellationToken cancellationToken)
{
try
{
logger.LogInformation($"{nameof(CreateUserProjectService)} - Request received - Payload: {JsonSerializer.Serialize(newUserProject)}");
if (newUserProject == null) return BadRequest("Invalid user project object");
if (string.IsNullOrEmpty(newUserProject.ProjectCode)) return BadRequest("Invalid project code");
if (string.IsNullOrEmpty(newUserProject.ProjectDescription)) return BadRequest("Invalid project description");
if (string.IsNullOrEmpty(newUserProject.UserId)) return BadRequest("Invalid user identifier");
return await Handle(() => blueprintServiceClient.CreateUserProjectService(newUserProject, cancellationToken)).ConfigureAwait(false);
}
catch (Exception ex)
{
logger.LogError($"{nameof(CreateUserProjectService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(newUserProject)}");
throw;
}
}
/// <summary>
/// Gets all user projects.
/// </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)]
public async Task<IActionResult> GetAllUserProjectsService(CancellationToken cancellationToken)
{
try
{
logger.LogInformation($"{nameof(GetAllUserProjectsService)} - Request received - Payload: ");
return await Handle(() => blueprintServiceClient.GetAllUserProjectsService(cancellationToken)).ConfigureAwait(false);
}
catch (Exception ex)
{
logger.LogError($"{nameof(GetAllUserProjectsService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload");
throw;
}
}
/// <summary>
/// Gets the user project 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)]
public async Task<IActionResult> GetUserProjectByIdService(GetUserProjectRequest request, CancellationToken cancellationToken)
{
try
{
logger.LogInformation($"{nameof(GetUserProjectByIdService)} - Request received - Payload: {JsonSerializer.Serialize(request)}");
if (request.Id <= 0) return BadRequest("Invalid user project identifier");
return await Handle(() => blueprintServiceClient.GetUserProjectByIdService(request, cancellationToken)).ConfigureAwait(false);
}
catch (Exception ex)
{
logger.LogError($"{nameof(GetUserProjectByIdService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}");
throw;
}
}
/// <summary>
/// Updates a full user project 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)]
public async Task<IActionResult> UpdateUserProjectService(UpdateUserProjectRequest request, CancellationToken cancellationToken)
{
try
{
logger.LogInformation($"{nameof(UpdateUserProjectService)} - Request received - Payload: {JsonSerializer.Serialize(request)}");
if (request == null) return BadRequest("Invalid user project object");
if (string.IsNullOrEmpty(request.ProjectCode)) return BadRequest("Invalid user project code");
if (string.IsNullOrEmpty(request.ProjectDescription)) return BadRequest("Invalid user project description");
if (string.IsNullOrEmpty(request.UserId)) return BadRequest("Invalid user identifier");
return await Handle(() => blueprintServiceClient.UpdateUserProjectService(request, cancellationToken)).ConfigureAwait(false);
}
catch (Exception ex)
{
logger.LogError($"{nameof(UpdateUserProjectService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}");
throw;
}
}
/// <summary>
/// Deletes the user project by identifier.
/// </summary>
[HttpPost("Delete")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> DeleteUserProjectService(DeleteUserProjectRequest request, CancellationToken cancellationToken)
{
try
{
logger.LogInformation($"{nameof(DeleteUserProjectService)} - Request received - Payload: {JsonSerializer.Serialize(request)}");
if (request.Id <= 0) return BadRequest("Invalid user project identifier");
return await Handle(() => blueprintServiceClient.DeleteUserProjectService(request, cancellationToken)).ConfigureAwait(false);
}
catch (Exception ex)
{
logger.LogError($"{nameof(DeleteUserProjectService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}");
throw;
}
}
}
}