Add project files.
This commit is contained in:
		| @@ -0,0 +1,15 @@ | ||||
| using Core.Blueprint.Service.Domain.Entities; | ||||
| using Core.Blueprint.Service.UseCases.GetOneSampleItem.Ports; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.GetOneSampleItem.Adapter | ||||
| { | ||||
|     public class GetOneSampleItemPort : BasePresenter, IGetOneSampleItemPort | ||||
|     { | ||||
|         public void Success(SqlSampleItemEntity output) | ||||
|         { | ||||
|             ViewModel = new OkObjectResult(output); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,42 @@ | ||||
| using Core.Blueprint.Service.External.Clients.SampleItemClient; | ||||
| using Core.Blueprint.Service.UseCases.GetOneSampleItem.Input; | ||||
| using Core.Blueprint.Service.UseCases.GetOneSampleItem.Ports; | ||||
| using FluentValidation; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.GetOneSampleItem | ||||
| { | ||||
|     public class GetOneSampleItemHandler(IGetOneSampleItemPort port, IValidator<GetOneSampleItemRequest> validator, ISampleItemClientService clientService) : IComponentHandler<GetOneSampleItemRequest> | ||||
|     { | ||||
|         private readonly IGetOneSampleItemPort _port = port; | ||||
|         private readonly IValidator<GetOneSampleItemRequest> _validator = validator; | ||||
|         private readonly ISampleItemClientService _clientService = clientService; | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(GetOneSampleItemRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 if (!command.IsValid(_validator)) | ||||
|                 { | ||||
|                     _port.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 var result = await _clientService.GetSampleItemAsync(command.Id); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch(Exception ex) | ||||
|             { | ||||
|                 _port.BusinessError(ex.Message); | ||||
|             } | ||||
|  | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,17 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.GetOneSampleItem.Input | ||||
| { | ||||
|     public class GetOneSampleItemRequest : Notificator, ICommand | ||||
|     { | ||||
|         public GetOneSampleItemRequest(string id) | ||||
|         { | ||||
|             Id = id; | ||||
|         } | ||||
|         public string Id { get; set; } = string.Empty; | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return true; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,9 @@ | ||||
| using Core.Blueprint.Service.Domain.Entities; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.GetOneSampleItem.Ports | ||||
| { | ||||
|     public interface IGetOneSampleItemPort : IBasePort, ICommandSuccessPort<SqlSampleItemEntity>, INoContentPort, IBusinessErrorPort, ITimeoutPort, IValidationErrorPort | ||||
|     { | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,15 @@ | ||||
| using Core.Blueprint.Service.UseCases.GetOneSampleItem.Input; | ||||
| using FluentValidation; | ||||
| using System.Diagnostics.CodeAnalysis; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.GetOneSampleItem.Validator | ||||
| { | ||||
|     [ExcludeFromCodeCoverage] | ||||
|     public class GetOneSampleItemValidator : AbstractValidator<GetOneSampleItemRequest> | ||||
|     { | ||||
|         public GetOneSampleItemValidator() | ||||
|         { | ||||
|             RuleFor(i => i.Id).NotNull().NotEmpty().WithMessage("Is required."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Sergio Matias Urquin
					Sergio Matias Urquin