Add project files.
This commit is contained in:
		| @@ -0,0 +1,15 @@ | ||||
| using Core.Blueprint.Service.Domain.Entities; | ||||
| using Core.Blueprint.Service.UseCases.CreateSampleImage.Ports; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.CreateSampleImage.Adapter | ||||
| { | ||||
|     public class CreateSampleImagePort : BasePresenter, ICreateSampleImagePort | ||||
|     { | ||||
|         public void Success(SqlSampleItemEntity output) | ||||
|         { | ||||
|             ViewModel = new OkObjectResult(output); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,44 @@ | ||||
| using Core.Blueprint.Service.Domain.Entities; | ||||
| using Core.Blueprint.Service.External.Clients.SampleItemClient; | ||||
| using Core.Blueprint.Service.UseCases.CreateSampleItem.Input; | ||||
| using Core.Blueprint.Service.UseCases.CreateSampleItem.Ports; | ||||
| using FluentValidation; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.CreateSampleImage | ||||
| { | ||||
|     public class CreateSampleItemHandler(ICreateSampleItemPort port, IValidator<CreateSampleItemRequest> validator, ISampleItemClientService clientService) : IComponentHandler<CreateSampleItemRequest> | ||||
|     { | ||||
|         private readonly ICreateSampleItemPort _port = port; | ||||
|         private readonly IValidator<CreateSampleItemRequest> _validator = validator; | ||||
|         private readonly ISampleItemClientService _clientService = clientService; | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(CreateSampleItemRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 if (!command.IsValid(_validator)) | ||||
|                 { | ||||
|                     _port.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 var result = await _clientService.CreateSampleItemAsync( | ||||
|                     new SqlSampleItemEntity { TestName = command.TestName, NumValue = command.NumValue }); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch(Exception ex) | ||||
|             { | ||||
|                 _port.BusinessError(ex.Message); | ||||
|             } | ||||
|  | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,14 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.CreateSampleImage.Input | ||||
| { | ||||
|     public class CreateSampleImageRequest : Notificator, ICommand | ||||
|     { | ||||
|         public Guid? Id; | ||||
|         public byte[] NumValue { get; set; } = []; | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return true; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,9 @@ | ||||
| using Core.Blueprint.Service.Domain.Entities; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.CreateSampleImage.Ports | ||||
| { | ||||
|     public interface ICreateSampleImagePort : IBasePort, ICommandSuccessPort<SqlSampleItemEntity>, INoContentPort, IBusinessErrorPort, ITimeoutPort, IValidationErrorPort | ||||
|     { | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,15 @@ | ||||
| using Core.Blueprint.Service.UseCases.CreateSampleItem.Input; | ||||
| using FluentValidation; | ||||
| using System.Diagnostics.CodeAnalysis; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.CreateSampleImage.Validator | ||||
| { | ||||
|     [ExcludeFromCodeCoverage] | ||||
|     public class CreateSampleImageValidator : AbstractValidator<CreateSampleItemRequest> | ||||
|     { | ||||
|         public CreateSampleImageValidator() | ||||
|         { | ||||
|              | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Sergio Matias Urquin
					Sergio Matias Urquin