Add project files.
This commit is contained in:
		| @@ -0,0 +1,22 @@ | ||||
| using Core.Blueprint.Service.Domain.Entities; | ||||
| using Core.Blueprint.Service.UseCases.GetSampleItems.Ports; | ||||
| using Core.Blueprint.Service.UseCases.GetSecret.Ports; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| using System.Threading.Tasks; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.GetSecret.Adapter | ||||
| { | ||||
|     public class GetSecretPort : BasePresenter, IGetSecretPort | ||||
|     { | ||||
|  | ||||
|         public void Success(SecretEntity output) | ||||
|         { | ||||
|             ViewModel = new OkObjectResult(output); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,50 @@ | ||||
| using Core.Blueprint.Service.Domain.Entities; | ||||
| using Core.Blueprint.Service.External.Clients.SecretClient; | ||||
| using Core.Blueprint.Service.UseCases.GetSampleItems.Input; | ||||
| using Core.Blueprint.Service.UseCases.GetSampleItems.Ports; | ||||
| using Core.Blueprint.Service.UseCases.GetSecret.Input; | ||||
| using Core.Blueprint.Service.UseCases.GetSecret.Ports; | ||||
| using FluentValidation; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.ComponentModel.DataAnnotations; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| using System.Threading.Tasks; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.GetSecret | ||||
| { | ||||
|     public class GetSecretHandler(IGetSecretPort port, IValidator<GetSecretRequest> validator, ISecretService secretService) : IComponentHandler<GetSecretRequest> | ||||
|     { | ||||
|         private readonly IGetSecretPort _port = port; | ||||
|         private readonly IValidator<GetSecretRequest> _validator = validator; | ||||
|         private readonly ISecretService _secretService = secretService; | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(GetSecretRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 if (!command.IsValid(_validator)) | ||||
|                 { | ||||
|                     _port.ValidationErrors(command.Notifications); | ||||
|                 } | ||||
|  | ||||
|                 var result = await _secretService.GetSecretAsync(command.Secret); | ||||
|  | ||||
|                 if (result is null || string.IsNullOrWhiteSpace(result.Value)) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 _port.BusinessError(ex.Message); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,19 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| using System.Threading.Tasks; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.GetSecret.Input | ||||
| { | ||||
|     public class GetSecretRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string? Secret { get; set; } | ||||
|  | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return true; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,15 @@ | ||||
| using Core.Blueprint.Service.Domain.Dtos; | ||||
| using Core.Blueprint.Service.Domain.Entities; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| using System.Threading.Tasks; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.GetSecret.Ports | ||||
| { | ||||
|     public interface IGetSecretPort : IBasePort, ICommandSuccessPort<SecretEntity>, INoContentPort, IBusinessErrorPort, ITimeoutPort, IValidationErrorPort | ||||
|     { | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,21 @@ | ||||
| using Core.Blueprint.Service.UseCases.GetSampleItems.Input; | ||||
| using Core.Blueprint.Service.UseCases.GetSecret.Input; | ||||
| using FluentValidation; | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Diagnostics.CodeAnalysis; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| using System.Threading.Tasks; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.GetSecret.Validator | ||||
| { | ||||
|     [ExcludeFromCodeCoverage] | ||||
|     public class GetSecretValidator : AbstractValidator<GetSecretRequest> | ||||
|     { | ||||
|         public GetSecretValidator() | ||||
|         { | ||||
|             RuleFor(i => i.Secret).NotNull().NotEmpty().WithMessage("Is required."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Sergio Matias Urquin
					Sergio Matias Urquin