Add project files.
This commit is contained in:
		
							
								
								
									
										130
									
								
								Core.Blueprint.API/Controllers/BlobStorageController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										130
									
								
								Core.Blueprint.API/Controllers/BlobStorageController.cs
									
									
									
									
									
										Normal 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; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Sergio Matias Urquin
					Sergio Matias Urquin