Add project files.
This commit is contained in:
		| @@ -0,0 +1,15 @@ | ||||
| using Core.Blueprint.Service.Domain.Entities; | ||||
| using Core.Blueprint.Service.UseCases.GetSampleItems.Ports; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.GetSampleItems.Adapter | ||||
| { | ||||
|     public class GetSampleItemsPort : BasePresenter, IGetSampleItemsPort | ||||
|     { | ||||
|         public void Success(List<SqlSampleItemEntity> output) | ||||
|         { | ||||
|             ViewModel = new OkObjectResult(output); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,42 @@ | ||||
| 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<GetSampleItemsRequest> validator, ISampleItemClientService clientService) : IComponentHandler<GetSampleItemsRequest> | ||||
|     { | ||||
|         private readonly IGetSampleItemsPort _port = port; | ||||
|         private readonly IValidator<GetSampleItemsRequest> _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); | ||||
|             } | ||||
|  | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,15 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.GetSampleItems.Input | ||||
| { | ||||
|     public class GetSampleItemsRequest : Notificator, ICommand | ||||
|     { | ||||
|         public Guid Id { get; set; } | ||||
|         public string TestName { get; set; } | ||||
|         public int 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.GetSampleItems.Ports | ||||
| { | ||||
|     public interface IGetSampleItemsPort : IBasePort, ICommandSuccessPort<List<SqlSampleItemEntity>>, INoContentPort, IBusinessErrorPort, ITimeoutPort, IValidationErrorPort | ||||
|     { | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,16 @@ | ||||
| using Core.Blueprint.Service.UseCases.GetSampleItems.Input; | ||||
| using FluentValidation; | ||||
| using System.Diagnostics.CodeAnalysis; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.GetSampleItems.Validator | ||||
| { | ||||
|     [ExcludeFromCodeCoverage] | ||||
|     public class GetSampleItemValidator : AbstractValidator<GetSampleItemsRequest> | ||||
|     { | ||||
|         public GetSampleItemValidator() | ||||
|         { | ||||
|             RuleFor(i => i.NumValue).GreaterThanOrEqualTo(0).LessThanOrEqualTo(100).WithMessage("Should be between 0 and 100."); | ||||
|             RuleFor(i => i.TestName).NotNull().NotEmpty().WithMessage("Is required."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Sergio Matias Urquin
					Sergio Matias Urquin