43 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			43 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using Core.Blueprint.Service.External.Clients.SampleItemClient;
 | |
| using Core.Blueprint.Service.UseCases.DeleteSampleItem.Input;
 | |
| using Core.Blueprint.Service.UseCases.DeleteSampleItem.Ports;
 | |
| using FluentValidation;
 | |
| using Lib.Architecture.BuildingBlocks;
 | |
| 
 | |
| namespace Core.Blueprint.Service.UseCases.DeleteSampleItem
 | |
| {
 | |
|     public class DeleteSampleItemHandler(IDeleteSampleItemPort port, IValidator<DeleteSampleItemRequest> validator, ISampleItemClientService clientService) : IComponentHandler<DeleteSampleItemRequest>
 | |
|     {
 | |
|         private readonly IDeleteSampleItemPort _port = port;
 | |
|         private readonly IValidator<DeleteSampleItemRequest> _validator = validator;
 | |
|         private readonly ISampleItemClientService _clientService = clientService;
 | |
| 
 | |
|         public async ValueTask ExecuteAsync(DeleteSampleItemRequest command, CancellationToken cancellationToken = default)
 | |
|         {
 | |
|             try
 | |
|             {
 | |
|                 if (!command.IsValid(_validator))
 | |
|                 {
 | |
|                     _port.ValidationErrors(command.Notifications);
 | |
|                     return;
 | |
|                 }
 | |
|                 var entity = await _clientService.GetSampleItemAsync(command.Id);
 | |
|                 if (entity == null)
 | |
|                 {
 | |
|                     _port.BusinessError("Not Found");
 | |
|                     return;
 | |
|                 }
 | |
|                 entity.StatusCode = 'D';
 | |
|                 await _clientService.UpdateSampleItemAsync(command.Id, entity);
 | |
| 
 | |
|                 _port.NoContentSuccess();
 | |
|             }
 | |
|             catch(Exception ex)
 | |
|             {
 | |
|                 _port.BusinessError(ex.Message);
 | |
|             }
 | |
| 
 | |
|         }
 | |
|     }
 | |
| }
 | 
