43 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			43 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using Core.Blueprint.Service.External.Clients.SampleItemClient;
 | |
| using Core.Blueprint.Service.UseCases.GetSampleItems.Ports;
 | |
| using Core.Blueprint.Service.UseCases.GetSampleItems.Input;
 | |
| using FluentValidation;
 | |
| using Lib.Architecture.BuildingBlocks;
 | |
| 
 | |
| namespace Core.Blueprint.Service.UseCases.GetSampleItems
 | |
| {
 | |
|     public class GetSampleItemsHandler(IGetSampleItemsPort port, IValidator<GetSampleItemsRequest> validator, ISampleItemClientService clientService) : IComponentHandler<GetSampleItemsRequest>
 | |
|     {
 | |
|         private readonly IGetSampleItemsPort _port = port;
 | |
|         private readonly IValidator<GetSampleItemsRequest> _validator = validator;
 | |
|         private readonly ISampleItemClientService _clientService = clientService;
 | |
| 
 | |
|         public async ValueTask ExecuteAsync(GetSampleItemsRequest command, CancellationToken cancellationToken = default)
 | |
|         {
 | |
|             try
 | |
|             {
 | |
|                 if (!command.IsValid(_validator))
 | |
|                 {
 | |
|                     _port.ValidationErrors(command.Notifications);
 | |
|                 }
 | |
| 
 | |
|                 var result = await _clientService.GetSampleItemsAsync();
 | |
| 
 | |
|                 if (!result.Any())
 | |
|                 {
 | |
|                     _port.NoContentSuccess();
 | |
|                     return;
 | |
|                 }
 | |
| 
 | |
| 
 | |
|                 _port.Success(result.Where(item => item.StatusCode != 'D').ToList());
 | |
|             }
 | |
|             catch(Exception ex)
 | |
|             {
 | |
|                 _port.BusinessError(ex.Message);
 | |
|             }
 | |
| 
 | |
|         }
 | |
|     }
 | |
| }
 | 
