43 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			43 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using Core.Blueprint.Service.External.Clients.SampleImageClient;
 | |
| using Core.Blueprint.Service.UseCases.GetUploadImageUrl.Input;
 | |
| using Core.Blueprint.Service.UseCases.GetUploadImageUrl.Ports;
 | |
| using FluentValidation;
 | |
| using Lib.Architecture.BuildingBlocks;
 | |
| 
 | |
| namespace Core.Blueprint.Service.UseCases.GetUploadImageUrl
 | |
| {
 | |
|     public class GetUploadUrlHandler(IGetUploadUrlPort port, IValidator<GetUploadUrlRequest> validator, ISampleImageClientService clientService) : IComponentHandler<GetUploadUrlRequest>
 | |
|     {
 | |
|         private readonly IGetUploadUrlPort _port = port;
 | |
|         private readonly IValidator<GetUploadUrlRequest> _validator = validator;
 | |
|         private readonly ISampleImageClientService _clientService = clientService;
 | |
| 
 | |
|         public async ValueTask ExecuteAsync(GetUploadUrlRequest command, CancellationToken cancellationToken = default)
 | |
|         {
 | |
|             try
 | |
|             {
 | |
|                 if (!command.IsValid(_validator))
 | |
|                 {
 | |
|                     _port.ValidationErrors(command.Notifications);
 | |
|                     return;
 | |
|                 }
 | |
| 
 | |
|                 var result = await _clientService.GetUploadUrl();
 | |
| 
 | |
|                 if (result == null)
 | |
|                 {
 | |
|                     _port.NoContentSuccess();
 | |
|                     return;
 | |
|                 }
 | |
| 
 | |
|                 _port.Success(result);
 | |
|             }
 | |
|             catch(Exception ex)
 | |
|             {
 | |
|                 _port.BusinessError(ex.Message);
 | |
|             }
 | |
| 
 | |
|         }
 | |
|     }
 | |
| }
 | 
