43 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			43 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using Core.Blueprint.Service.External.Clients.SampleItemClient;
 | |
| using Core.Blueprint.Service.UseCases.GetOneSampleItem.Input;
 | |
| using Core.Blueprint.Service.UseCases.GetOneSampleItem.Ports;
 | |
| using FluentValidation;
 | |
| using Lib.Architecture.BuildingBlocks;
 | |
| 
 | |
| namespace Core.Blueprint.Service.UseCases.GetOneSampleItem
 | |
| {
 | |
|     public class GetOneSampleItemHandler(IGetOneSampleItemPort port, IValidator<GetOneSampleItemRequest> validator, ISampleItemClientService clientService) : IComponentHandler<GetOneSampleItemRequest>
 | |
|     {
 | |
|         private readonly IGetOneSampleItemPort _port = port;
 | |
|         private readonly IValidator<GetOneSampleItemRequest> _validator = validator;
 | |
|         private readonly ISampleItemClientService _clientService = clientService;
 | |
| 
 | |
|         public async ValueTask ExecuteAsync(GetOneSampleItemRequest command, CancellationToken cancellationToken = default)
 | |
|         {
 | |
|             try
 | |
|             {
 | |
|                 if (!command.IsValid(_validator))
 | |
|                 {
 | |
|                     _port.ValidationErrors(command.Notifications);
 | |
|                     return;
 | |
|                 }
 | |
| 
 | |
|                 var result = await _clientService.GetSampleItemAsync(command.Id);
 | |
| 
 | |
|                 if (result == null)
 | |
|                 {
 | |
|                     _port.NoContentSuccess();
 | |
|                     return;
 | |
|                 }
 | |
| 
 | |
|                 _port.Success(result);
 | |
|             }
 | |
|             catch(Exception ex)
 | |
|             {
 | |
|                 _port.BusinessError(ex.Message);
 | |
|             }
 | |
| 
 | |
|         }
 | |
|     }
 | |
| }
 | 
