Add samples in mongo and sql layer
This commit is contained in:
		
							
								
								
									
										160
									
								
								Core.Blueprint.API/Controllers/MongoSampleController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										160
									
								
								Core.Blueprint.API/Controllers/MongoSampleController.cs
									
									
									
									
									
										Normal 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 MongoSampleController(IBlueprintServiceClient blueprintServiceClient, ILogger<MongoSampleController> logger) : BaseController(logger) | ||||
|     { | ||||
|         /// <summary> | ||||
|         /// Creates a new MongoSample. | ||||
|         /// </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> CreateMongoSampleService(CreateMongoSampleRequest sample, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 logger.LogInformation($"{nameof(CreateMongoSampleService)} - Request received - Payload: {JsonSerializer.Serialize(sample)}"); | ||||
|  | ||||
|                 if (sample == null) return BadRequest("Invalid sample object"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(sample.Name)) return BadRequest("Invalid sample name"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(sample.Description)) return BadRequest("Invalid sample description"); | ||||
|  | ||||
|                 return await Handle(() => blueprintServiceClient.CreateMongoSampleService(sample, cancellationToken)).ConfigureAwait(false); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError($"{nameof(CreateMongoSampleService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(sample)}"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets all Mongo Samples. | ||||
|         /// </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> GetAllMongoSamplesService(CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 logger.LogInformation($"{nameof(GetAllMongoSamplesService)} - Request received - Payload: "); | ||||
|  | ||||
|                 return await Handle(() => blueprintServiceClient.GetAllMongoSamplesService(cancellationToken)).ConfigureAwait(false); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError($"{nameof(GetAllMongoSamplesService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets the Mongo Sample 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> GetMongoSampleByIdService(GetMongoSampleRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 logger.LogInformation($"{nameof(GetMongoSampleByIdService)} - Request received - Payload: {JsonSerializer.Serialize(request)}"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(request._Id)) return BadRequest("Invalid MongoSample identifier"); | ||||
|  | ||||
|                 return await Handle(() => blueprintServiceClient.GetMongoSampleByIdService(request, cancellationToken)).ConfigureAwait(false); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError($"{nameof(GetMongoSampleByIdService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Updates a full Mongo Sample 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> UpdateMongoSampleService(UpdateMongoSampleRequest newSample, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 logger.LogInformation($"{nameof(UpdateMongoSampleService)} - Request received - Payload: {JsonSerializer.Serialize(newSample)}"); | ||||
|  | ||||
|                 if (newSample == null) return BadRequest("Invalid sample object"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(newSample.Name)) return BadRequest("Invalid sample name"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(newSample.Description)) return BadRequest("Invalid sample description"); | ||||
|  | ||||
|                 return await Handle(() => blueprintServiceClient.UpdateMongoSampleService(newSample, cancellationToken)).ConfigureAwait(false); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError($"{nameof(UpdateMongoSampleService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(newSample)}"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Deletes the Mongo Sample 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> DeleteMongoSampleService(DeleteMongoSampleRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 logger.LogInformation($"{nameof(DeleteMongoSampleService)} - Request received - Payload: {JsonSerializer.Serialize(request)}"); | ||||
|  | ||||
|                 if (string.IsNullOrEmpty(request._Id)) return BadRequest("Invalid sample identifier"); | ||||
|  | ||||
|                 return await Handle(() => blueprintServiceClient.DeleteMongoSampleService(request, cancellationToken)).ConfigureAwait(false); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError($"{nameof(DeleteMongoSampleService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Sergio Matias Urquin
					Sergio Matias Urquin