Add samples in mongo and sql layer

This commit is contained in:
Sergio Matias Urquin
2025-05-18 18:16:12 -06:00
parent 37db76d94a
commit b757f2a6c2
16 changed files with 122 additions and 127 deletions

View File

@@ -1,24 +1,23 @@
using Core.Blueprint.API.Controllers;
using Core.Blueprint.External.Clients.Blueprint;
using Core.Blueprint.External.Clients.Blueprint.Requests.SQL;
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.UserProject.API.Controllers
namespace Core.Blueprint.API.Controllers
{
/// <summary>
/// Handles all requests for user project.
/// Handles all requests for blueprint.
/// </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)
public class MongoSampleController(IBlueprintServiceClient blueprintServiceClient, ILogger<MongoSampleController> logger) : BaseController(logger)
{
/// <summary>
/// Creates a new user project.
/// Creates a new MongoSample.
/// </summary>
[HttpPost("Create")]
[ProducesResponseType(StatusCodes.Status200OK)]
@@ -27,31 +26,29 @@ namespace Core.UserProject.API.Controllers
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> CreateUserProjectService(CreateUserProjectRequest newUserProject, CancellationToken cancellationToken)
public async Task<IActionResult> CreateMongoSampleService(CreateMongoSampleRequest sample, CancellationToken cancellationToken)
{
try
{
logger.LogInformation($"{nameof(CreateUserProjectService)} - Request received - Payload: {JsonSerializer.Serialize(newUserProject)}");
logger.LogInformation($"{nameof(CreateMongoSampleService)} - Request received - Payload: {JsonSerializer.Serialize(sample)}");
if (newUserProject == null) return BadRequest("Invalid user project object");
if (sample == null) return BadRequest("Invalid sample object");
if (string.IsNullOrEmpty(newUserProject.ProjectCode)) return BadRequest("Invalid project code");
if (string.IsNullOrEmpty(sample.Name)) return BadRequest("Invalid sample name");
if (string.IsNullOrEmpty(newUserProject.ProjectDescription)) return BadRequest("Invalid project description");
if (string.IsNullOrEmpty(sample.Description)) return BadRequest("Invalid sample description");
if (string.IsNullOrEmpty(newUserProject.UserId)) return BadRequest("Invalid user identifier");
return await Handle(() => blueprintServiceClient.CreateUserProjectService(newUserProject, cancellationToken)).ConfigureAwait(false);
return await Handle(() => blueprintServiceClient.CreateMongoSampleService(sample, cancellationToken)).ConfigureAwait(false);
}
catch (Exception ex)
{
logger.LogError($"{nameof(CreateUserProjectService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(newUserProject)}");
logger.LogError($"{nameof(CreateMongoSampleService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(sample)}");
throw;
}
}
/// <summary>
/// Gets all user projects.
/// Gets all Mongo Samples.
/// </summary>
[HttpGet("GetAll")]
[ProducesResponseType(StatusCodes.Status200OK)]
@@ -60,23 +57,23 @@ namespace Core.UserProject.API.Controllers
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> GetAllUserProjectsService(CancellationToken cancellationToken)
public async Task<IActionResult> GetAllMongoSamplesService(CancellationToken cancellationToken)
{
try
{
logger.LogInformation($"{nameof(GetAllUserProjectsService)} - Request received - Payload: ");
logger.LogInformation($"{nameof(GetAllMongoSamplesService)} - Request received - Payload: ");
return await Handle(() => blueprintServiceClient.GetAllUserProjectsService(cancellationToken)).ConfigureAwait(false);
return await Handle(() => blueprintServiceClient.GetAllMongoSamplesService(cancellationToken)).ConfigureAwait(false);
}
catch (Exception ex)
{
logger.LogError($"{nameof(GetAllUserProjectsService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload");
logger.LogError($"{nameof(GetAllMongoSamplesService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload");
throw;
}
}
/// <summary>
/// Gets the user project by identifier.
/// Gets the Mongo Sample by identifier.
/// </summary>
[HttpPost("GetById")]
[ProducesResponseType(StatusCodes.Status200OK)]
@@ -85,25 +82,25 @@ namespace Core.UserProject.API.Controllers
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> GetUserProjectByIdService(GetUserProjectRequest request, CancellationToken cancellationToken)
public async Task<IActionResult> GetMongoSampleByIdService(GetMongoSampleRequest request, CancellationToken cancellationToken)
{
try
{
logger.LogInformation($"{nameof(GetUserProjectByIdService)} - Request received - Payload: {JsonSerializer.Serialize(request)}");
logger.LogInformation($"{nameof(GetMongoSampleByIdService)} - Request received - Payload: {JsonSerializer.Serialize(request)}");
if (request.Id <= 0) return BadRequest("Invalid user project identifier");
if (string.IsNullOrEmpty(request._Id)) return BadRequest("Invalid MongoSample identifier");
return await Handle(() => blueprintServiceClient.GetUserProjectByIdService(request, cancellationToken)).ConfigureAwait(false);
return await Handle(() => blueprintServiceClient.GetMongoSampleByIdService(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)}");
logger.LogError($"{nameof(GetMongoSampleByIdService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}");
throw;
}
}
/// <summary>
/// Updates a full user project by identifier.
/// Updates a full Mongo Sample by identifier.
/// </summary>
[HttpPut("Update")]
[ProducesResponseType(StatusCodes.Status200OK)]
@@ -112,31 +109,29 @@ namespace Core.UserProject.API.Controllers
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> UpdateUserProjectService(UpdateUserProjectRequest request, CancellationToken cancellationToken)
public async Task<IActionResult> UpdateMongoSampleService(UpdateMongoSampleRequest newSample, CancellationToken cancellationToken)
{
try
{
logger.LogInformation($"{nameof(UpdateUserProjectService)} - Request received - Payload: {JsonSerializer.Serialize(request)}");
logger.LogInformation($"{nameof(UpdateMongoSampleService)} - Request received - Payload: {JsonSerializer.Serialize(newSample)}");
if (request == null) return BadRequest("Invalid user project object");
if (newSample == null) return BadRequest("Invalid sample object");
if (string.IsNullOrEmpty(request.ProjectCode)) return BadRequest("Invalid user project code");
if (string.IsNullOrEmpty(newSample.Name)) return BadRequest("Invalid sample name");
if (string.IsNullOrEmpty(request.ProjectDescription)) return BadRequest("Invalid user project description");
if (string.IsNullOrEmpty(newSample.Description)) return BadRequest("Invalid sample description");
if (string.IsNullOrEmpty(request.UserId)) return BadRequest("Invalid user identifier");
return await Handle(() => blueprintServiceClient.UpdateUserProjectService(request, cancellationToken)).ConfigureAwait(false);
return await Handle(() => blueprintServiceClient.UpdateMongoSampleService(newSample, cancellationToken)).ConfigureAwait(false);
}
catch (Exception ex)
{
logger.LogError($"{nameof(UpdateUserProjectService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}");
logger.LogError($"{nameof(UpdateMongoSampleService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(newSample)}");
throw;
}
}
/// <summary>
/// Deletes the user project by identifier.
/// Deletes the Mongo Sample by identifier.
/// </summary>
[HttpPost("Delete")]
[ProducesResponseType(StatusCodes.Status200OK)]
@@ -145,19 +140,19 @@ namespace Core.UserProject.API.Controllers
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> DeleteUserProjectService(DeleteUserProjectRequest request, CancellationToken cancellationToken)
public async Task<IActionResult> DeleteMongoSampleService(DeleteMongoSampleRequest request, CancellationToken cancellationToken)
{
try
{
logger.LogInformation($"{nameof(DeleteUserProjectService)} - Request received - Payload: {JsonSerializer.Serialize(request)}");
logger.LogInformation($"{nameof(DeleteMongoSampleService)} - Request received - Payload: {JsonSerializer.Serialize(request)}");
if (request.Id <= 0) return BadRequest("Invalid user project identifier");
if (string.IsNullOrEmpty(request._Id)) return BadRequest("Invalid sample identifier");
return await Handle(() => blueprintServiceClient.DeleteUserProjectService(request, cancellationToken)).ConfigureAwait(false);
return await Handle(() => blueprintServiceClient.DeleteMongoSampleService(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)}");
logger.LogError($"{nameof(DeleteMongoSampleService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}");
throw;
}
}

View File

@@ -1,23 +1,24 @@
using Core.Blueprint.External.Clients.Blueprint;
using Core.Blueprint.External.Clients.Blueprint.Requests.Mongo;
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.Blueprint.API.Controllers
namespace Core.SqlSample.API.Controllers
{
/// <summary>
/// Handles all requests for blueprint.
/// Handles all requests for sql sample.
/// </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)
public class SqlSampleController(IBlueprintServiceClient blueprintServiceClient, ILogger<SqlSampleController> logger) : BaseController(logger)
{
/// <summary>
/// Creates a new blueprint.
/// Creates a new sql sample.
/// </summary>
[HttpPost("Create")]
[ProducesResponseType(StatusCodes.Status200OK)]
@@ -26,29 +27,30 @@ namespace Core.Blueprint.API.Controllers
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> CreateBlueprintService(CreateBlueprintRequest newBlueprint, CancellationToken cancellationToken)
public async Task<IActionResult> CreateSqlSampleService(CreateSqlSampleRequest sample, CancellationToken cancellationToken)
{
try
{
logger.LogInformation($"{nameof(CreateBlueprintService)} - Request received - Payload: {JsonSerializer.Serialize(newBlueprint)}");
logger.LogInformation($"{nameof(CreateSqlSampleService)} - Request received - Payload: {JsonSerializer.Serialize(sample)}");
if (newBlueprint == null) return BadRequest("Invalid blueprint object");
if (sample == null) return BadRequest("Invalid sql sample object");
if (string.IsNullOrEmpty(newBlueprint.Name)) return BadRequest("Invalid blueprint name");
if (string.IsNullOrEmpty(sample.Name)) return BadRequest("Invalid sample name");
if (string.IsNullOrEmpty(newBlueprint.Description)) return BadRequest("Invalid blueprint description");
if (string.IsNullOrEmpty(sample.Description)) return BadRequest("Invalid sample description");
return await Handle(() => blueprintServiceClient.CreateBlueprintService(newBlueprint, cancellationToken)).ConfigureAwait(false);
return await Handle(() => blueprintServiceClient.CreateSqlSampleService(sample, cancellationToken)).ConfigureAwait(false);
}
catch (Exception ex)
{
logger.LogError($"{nameof(CreateBlueprintService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(newBlueprint)}");
logger.LogError($"{nameof(CreateSqlSampleService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(sample)}");
throw;
}
}
/// <summary>
/// Gets all blueprints.
/// Gets all sql samples.
/// </summary>
[HttpGet("GetAll")]
[ProducesResponseType(StatusCodes.Status200OK)]
@@ -57,23 +59,23 @@ namespace Core.Blueprint.API.Controllers
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> GetAllBlueprintsService(CancellationToken cancellationToken)
public async Task<IActionResult> GetAllSqlSamplesService(CancellationToken cancellationToken)
{
try
{
logger.LogInformation($"{nameof(GetAllBlueprintsService)} - Request received - Payload: ");
logger.LogInformation($"{nameof(GetAllSqlSamplesService)} - Request received - Payload: ");
return await Handle(() => blueprintServiceClient.GetAllBlueprintsService(cancellationToken)).ConfigureAwait(false);
return await Handle(() => blueprintServiceClient.GetAllSqlSamplesService(cancellationToken)).ConfigureAwait(false);
}
catch (Exception ex)
{
logger.LogError($"{nameof(GetAllBlueprintsService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload");
logger.LogError($"{nameof(GetAllSqlSamplesService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload");
throw;
}
}
/// <summary>
/// Gets the blueprint by identifier.
/// Gets the sql sample by identifier.
/// </summary>
[HttpPost("GetById")]
[ProducesResponseType(StatusCodes.Status200OK)]
@@ -82,25 +84,25 @@ namespace Core.Blueprint.API.Controllers
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> GetBlueprintByIdService(GetBlueprintRequest request, CancellationToken cancellationToken)
public async Task<IActionResult> GetSqlSampleByIdService(GetSqlSampleRequest request, CancellationToken cancellationToken)
{
try
{
logger.LogInformation($"{nameof(GetBlueprintByIdService)} - Request received - Payload: {JsonSerializer.Serialize(request)}");
logger.LogInformation($"{nameof(GetSqlSampleByIdService)} - Request received - Payload: {JsonSerializer.Serialize(request)}");
if (string.IsNullOrEmpty(request._Id)) return BadRequest("Invalid blueprint identifier");
if (request.Id <= 0) return BadRequest("Invalid sql sample identifier");
return await Handle(() => blueprintServiceClient.GetBlueprintByIdService(request, cancellationToken)).ConfigureAwait(false);
return await Handle(() => blueprintServiceClient.GetSqlSampleByIdService(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)}");
logger.LogError($"{nameof(GetSqlSampleByIdService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}");
throw;
}
}
/// <summary>
/// Updates a full blueprint by identifier.
/// Updates a full sql sample by identifier.
/// </summary>
[HttpPut("Update")]
[ProducesResponseType(StatusCodes.Status200OK)]
@@ -109,29 +111,30 @@ namespace Core.Blueprint.API.Controllers
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> UpdateBlueprintService(UpdateBlueprintRequest newBlueprint, CancellationToken cancellationToken)
public async Task<IActionResult> UpdateSqlSampleService(UpdateSqlSampleRequest request, CancellationToken cancellationToken)
{
try
{
logger.LogInformation($"{nameof(UpdateBlueprintService)} - Request received - Payload: {JsonSerializer.Serialize(newBlueprint)}");
logger.LogInformation($"{nameof(UpdateSqlSampleService)} - Request received - Payload: {JsonSerializer.Serialize(request)}");
if (newBlueprint == null) return BadRequest("Invalid blueprint object");
if (request == null) return BadRequest("Invalid sql sample object");
if (string.IsNullOrEmpty(newBlueprint.Name)) return BadRequest("Invalid blueprint name");
if (string.IsNullOrEmpty(request.Name)) return BadRequest("Invalid sql sample name");
if (string.IsNullOrEmpty(newBlueprint.Description)) return BadRequest("Invalid blueprint description");
if (string.IsNullOrEmpty(request.Description)) return BadRequest("Invalid sql sample description");
return await Handle(() => blueprintServiceClient.UpdateBlueprintService(newBlueprint, cancellationToken)).ConfigureAwait(false);
return await Handle(() => blueprintServiceClient.UpdateSqlSampleService(request, cancellationToken)).ConfigureAwait(false);
}
catch (Exception ex)
{
logger.LogError($"{nameof(UpdateBlueprintService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(newBlueprint)}");
logger.LogError($"{nameof(UpdateSqlSampleService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}");
throw;
}
}
/// <summary>
/// Deletes the blueprint by identifier.
/// Deletes the sql sample by identifier.
/// </summary>
[HttpPost("Delete")]
[ProducesResponseType(StatusCodes.Status200OK)]
@@ -140,19 +143,19 @@ namespace Core.Blueprint.API.Controllers
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> DeleteBlueprintService(DeleteBlueprintRequest request, CancellationToken cancellationToken)
public async Task<IActionResult> DeleteSqlSampleService(DeleteSqlSampleRequest request, CancellationToken cancellationToken)
{
try
{
logger.LogInformation($"{nameof(DeleteBlueprintService)} - Request received - Payload: {JsonSerializer.Serialize(request)}");
logger.LogInformation($"{nameof(DeleteSqlSampleService)} - Request received - Payload: {JsonSerializer.Serialize(request)}");
if (string.IsNullOrEmpty(request._Id)) return BadRequest("Invalid blueprint identifier");
if (request.Id <= 0) return BadRequest("Invalid sql sample identifier");
return await Handle(() => blueprintServiceClient.DeleteBlueprintService(request, cancellationToken)).ConfigureAwait(false);
return await Handle(() => blueprintServiceClient.DeleteSqlSampleService(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)}");
logger.LogError($"{nameof(DeleteSqlSampleService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}");
throw;
}
}