46 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			46 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using Core.Blueprint.Service.Domain.Entities;
 | |
| using Core.Blueprint.Service.External.Clients.SampleItemClient;
 | |
| using Core.Blueprint.Service.UseCases.UpdateSampleItem.Input;
 | |
| using Core.Blueprint.Service.UseCases.UpdateSampleItem.Ports;
 | |
| using FluentValidation;
 | |
| using Lib.Architecture.BuildingBlocks;
 | |
| 
 | |
| namespace Core.Blueprint.Service.UseCases.UpdateSampleItem
 | |
| {
 | |
|     public class UpdateSampleItemHandler(IUpdateSampleItemPort port, IValidator<UpdateSampleItemRequest> validator, ISampleItemClientService clientService) : IComponentHandler<UpdateSampleItemRequest>
 | |
|     {
 | |
|         private readonly IUpdateSampleItemPort _port = port;
 | |
|         private readonly IValidator<UpdateSampleItemRequest> _validator = validator;
 | |
|         private readonly ISampleItemClientService _clientService = clientService;
 | |
| 
 | |
|         public async ValueTask ExecuteAsync(UpdateSampleItemRequest command, CancellationToken cancellationToken = default)
 | |
|         {
 | |
|             try
 | |
|             {
 | |
|                 if (!command.IsValid(_validator))
 | |
|                 {
 | |
|                     _port.ValidationErrors(command.Notifications);
 | |
|                     return;
 | |
|                 }
 | |
| 
 | |
|                 var result = await _clientService.UpdateSampleItemAsync(command.Id,
 | |
| 
 | |
|                     new SqlSampleItemEntity { Id = command.Id, TestName = command.TestName, NumValue = command.NumValue, StatusCode = command.StatusCode });
 | |
| 
 | |
|                 if (result == null)
 | |
|                 {
 | |
|                     _port.NoContentSuccess();
 | |
|                     return;
 | |
|                 }
 | |
| 
 | |
|                 _port.Success(result);
 | |
|             }
 | |
|             catch (Exception ex)
 | |
|             {
 | |
|                 _port.BusinessError(ex.Message);
 | |
|             }
 | |
| 
 | |
|         }
 | |
|     }
 | |
| }
 | 
