using Core.Blueprint.Service.Domain.Dtos; using Core.Blueprint.Service.External.Clients.SampleImageClient; using Core.Blueprint.Service.UseCases.GetSampleImage.Input; using Core.Blueprint.Service.UseCases.GetSampleImage.Ports; using FluentValidation; using Lib.Architecture.BuildingBlocks; namespace Core.Blueprint.Service.UseCases.GetSampleImage { public class GetSampleImageHandler(IGetSampleImagePort port, IValidator validator, ISampleImageClientService clientService) : IComponentHandler { private readonly IGetSampleImagePort _port = port; private readonly IValidator _validator = validator; private readonly ISampleImageClientService _clientService = clientService; public async ValueTask ExecuteAsync(GetSampleImageRequest command, CancellationToken cancellationToken = default) { try { if (!command.IsValid(_validator)) { _port.ValidationErrors(command.Notifications); return; } var result = await _clientService.GetFirstImageUrl(); if (result == null) { _port.NoContentSuccess(); return; } _port.Success(result); } catch(Exception ex) { _port.BusinessError(ex.Message); } } } }