51 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			51 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| 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);
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| }
 | 
