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 validator, ISampleItemClientService clientService) : IComponentHandler { private readonly IUpdateSampleItemPort _port = port; private readonly IValidator _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); } } } }