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