Add project files.
This commit is contained in:
		| @@ -0,0 +1,90 @@ | ||||
| using Core.Blueprint.Service.External.Clients; | ||||
| using Core.Blueprint.Service.External.Clients.BluePrintService; | ||||
| using Refit; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.BluePrint | ||||
| { | ||||
|     public interface IBlueprintService | ||||
|     { | ||||
|         Task<IEnumerable<MongoBlueprintCollection>> GetBlueprintsAsync(); | ||||
|         Task<MongoBlueprintCollection> GetBlueprintAsync(string id); | ||||
|         Task<MongoBlueprintCollection> CreateBlueprintAsync(MongoBlueprintCollection blueprint); | ||||
|         Task UpdateBlueprintAsync(string id, MongoBlueprintCollection blueprint); | ||||
|         Task DeleteBlueprintAsync(string id); | ||||
|  | ||||
|     } | ||||
|     public class BlueprintService: IBlueprintService | ||||
|     { | ||||
|         private readonly IBluePrintServiceClient _blueprintApi; | ||||
|  | ||||
|         public BlueprintService(IBluePrintServiceClient client) | ||||
|         { | ||||
|             _blueprintApi = client; | ||||
|         } | ||||
|  | ||||
|         public async Task<IEnumerable<MongoBlueprintCollection>> GetBlueprintsAsync() | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 return await _blueprintApi.GetBlueprintsAsync(); | ||||
|             } | ||||
|             catch (ApiException ex) | ||||
|             { | ||||
|                 Console.WriteLine($"Error fetching blueprints: {ex.Message}"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async Task<MongoBlueprintCollection> GetBlueprintAsync(string id) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 return await _blueprintApi.GetBlueprintAsync(id); | ||||
|             } | ||||
|             catch (ApiException ex) | ||||
|             { | ||||
|                 Console.WriteLine($"Error fetching blueprint with ID {id}: {ex.Message}"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async Task<MongoBlueprintCollection> CreateBlueprintAsync(MongoBlueprintCollection blueprint) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 return await _blueprintApi.CreateBlueprintAsync(blueprint); | ||||
|             } | ||||
|             catch (ApiException ex) | ||||
|             { | ||||
|                 Console.WriteLine($"Error creating blueprint: {ex.Message}"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async Task UpdateBlueprintAsync(string id, MongoBlueprintCollection blueprint) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 await _blueprintApi.UpdateBlueprintAsync(id, blueprint); | ||||
|             } | ||||
|             catch (ApiException ex) | ||||
|             { | ||||
|                 Console.WriteLine($"Error updating blueprint with ID {id}: {ex.Message}"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async Task DeleteBlueprintAsync(string id) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 await _blueprintApi.DeleteBlueprintAsync(id); | ||||
|             } | ||||
|             catch (ApiException ex) | ||||
|             { | ||||
|                 Console.WriteLine($"Error deleting blueprint with ID {id}: {ex.Message}"); | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,74 @@ | ||||
| using Core.Blueprint.Service.UseCases.CreateSampleItem; | ||||
| using Core.Blueprint.Service.UseCases.CreateSampleItem.Adapter; | ||||
| using Core.Blueprint.Service.UseCases.CreateSampleItem.Input; | ||||
| using Core.Blueprint.Service.UseCases.CreateSampleItem.Ports; | ||||
| using Core.Blueprint.Service.UseCases.CreateSampleItem.Validator; | ||||
| using Core.Blueprint.Service.UseCases.DeleteSampleItem; | ||||
| using Core.Blueprint.Service.UseCases.DeleteSampleItem.Adapter; | ||||
| using Core.Blueprint.Service.UseCases.DeleteSampleItem.Input; | ||||
| using Core.Blueprint.Service.UseCases.DeleteSampleItem.Ports; | ||||
| using Core.Blueprint.Service.UseCases.DeleteSampleItem.Validator; | ||||
| using Core.Blueprint.Service.UseCases.GetOneSampleItem; | ||||
| using Core.Blueprint.Service.UseCases.GetOneSampleItem.Adapter; | ||||
| using Core.Blueprint.Service.UseCases.GetOneSampleItem.Input; | ||||
| using Core.Blueprint.Service.UseCases.GetOneSampleItem.Ports; | ||||
| using Core.Blueprint.Service.UseCases.GetOneSampleItem.Validator; | ||||
| using Core.Blueprint.Service.UseCases.GetSampleImage; | ||||
| using Core.Blueprint.Service.UseCases.GetSampleImage.Adapter; | ||||
| using Core.Blueprint.Service.UseCases.GetSampleImage.Input; | ||||
| using Core.Blueprint.Service.UseCases.GetSampleImage.Ports; | ||||
| using Core.Blueprint.Service.UseCases.GetSampleImage.Validator; | ||||
| using Core.Blueprint.Service.UseCases.GetSampleItems; | ||||
| using Core.Blueprint.Service.UseCases.GetSampleItems.Adapter; | ||||
| using Core.Blueprint.Service.UseCases.GetSampleItems.Input; | ||||
| using Core.Blueprint.Service.UseCases.GetSampleItems.Ports; | ||||
| using Core.Blueprint.Service.UseCases.GetSampleItems.Validator; | ||||
| using Core.Blueprint.Service.UseCases.GetUploadImageUrl; | ||||
| using Core.Blueprint.Service.UseCases.GetUploadImageUrl.Adapter; | ||||
| using Core.Blueprint.Service.UseCases.GetUploadImageUrl.Input; | ||||
| using Core.Blueprint.Service.UseCases.GetUploadImageUrl.Ports; | ||||
| using Core.Blueprint.Service.UseCases.GetUploadImageUrl.Validator; | ||||
| using Core.Blueprint.Service.UseCases.UpdateSampleItem; | ||||
| using Core.Blueprint.Service.UseCases.UpdateSampleItem.Adapter; | ||||
| using Core.Blueprint.Service.UseCases.UpdateSampleItem.Input; | ||||
| using Core.Blueprint.Service.UseCases.UpdateSampleItem.Ports; | ||||
| using Core.Blueprint.Service.UseCases.UpdateSampleItem.Validator; | ||||
| using FluentValidation; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Microsoft.Extensions.DependencyInjection; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.Configuration | ||||
| { | ||||
|     public static class UseCasesConfiguration | ||||
|     { | ||||
|         public static IServiceCollection AddUseCasesLayer(this IServiceCollection services) | ||||
|         { | ||||
|             services | ||||
|                 .AddScoped<IGetSampleItemsPort, GetSampleItemsPort>() | ||||
|                 .AddScoped<IGetOneSampleItemPort, GetOneSampleItemPort>() | ||||
|                 .AddScoped<ICreateSampleItemPort, CreateSampleItemPort>() | ||||
|                 .AddScoped<IUpdateSampleItemPort, UpdateSampleItemPort>() | ||||
|                 .AddScoped<IDeleteSampleItemPort, DeleteSampleItemPort>() | ||||
|                 .AddScoped<IGetSampleImagePort, GetSampleImagePort>() | ||||
|                 .AddScoped<IGetUploadUrlPort, GetUploadUrlPort>() | ||||
|  | ||||
|                 .AddScoped<IValidator<GetSampleItemsRequest>, GetSampleItemValidator>() | ||||
|                 .AddScoped<IValidator<GetOneSampleItemRequest>, GetOneSampleItemValidator>() | ||||
|                 .AddScoped<IValidator<CreateSampleItemRequest>, CreateSampleItemValidator>() | ||||
|                 .AddScoped<IValidator<UpdateSampleItemRequest>, UpdateSampleItemValidator>() | ||||
|                 .AddScoped<IValidator<DeleteSampleItemRequest>, DeleteSampleItemValidator>() | ||||
|                 .AddScoped<IValidator<GetSampleImageRequest>, GetSampleImageValidator>() | ||||
|                 .AddScoped<IValidator<GetUploadUrlRequest>, GetUploadUrlValidator>() | ||||
|  | ||||
|                 .AddScoped<IComponentHandler<GetSampleItemsRequest>, GetSampleItemsHandler>() | ||||
|                 .AddScoped<IComponentHandler<GetOneSampleItemRequest>, GetOneSampleItemHandler>() | ||||
|                 .AddScoped<IComponentHandler<CreateSampleItemRequest>, CreateSampleItemHandler>() | ||||
|                 .AddScoped<IComponentHandler<UpdateSampleItemRequest>, UpdateSampleItemHandler>() | ||||
|                 .AddScoped<IComponentHandler<DeleteSampleItemRequest>, DeleteSampleItemHandler>() | ||||
|                 .AddScoped<IComponentHandler<GetSampleImageRequest>, GetSampleImageHandler>() | ||||
|                 .AddScoped<IComponentHandler<GetUploadUrlRequest>, GetUploadUrlHandler>(); | ||||
|  | ||||
|             return services; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,18 @@ | ||||
| <Project Sdk="Microsoft.NET.Sdk"> | ||||
|  | ||||
|   <PropertyGroup> | ||||
|     <TargetFramework>net8.0</TargetFramework> | ||||
|     <ImplicitUsings>enable</ImplicitUsings> | ||||
|     <Nullable>enable</Nullable> | ||||
|   </PropertyGroup> | ||||
|  | ||||
|   <ItemGroup> | ||||
|     <PackageReference Include="Lib.Architecture.BuildingBlocks" Version="0.9.0-alpha0001" /> | ||||
|   </ItemGroup> | ||||
|  | ||||
|   <ItemGroup> | ||||
|     <ProjectReference Include="..\Core.Blueprint.Service.Domain\Core.Blueprint.Service.Domain.csproj" /> | ||||
|     <ProjectReference Include="..\Core.Blueprint.Service.External\Core.Blueprint.Service.External.csproj" /> | ||||
|   </ItemGroup> | ||||
|  | ||||
| </Project> | ||||
| @@ -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() | ||||
|         { | ||||
|              | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,15 @@ | ||||
| using Core.Blueprint.Service.Domain.Entities; | ||||
| using Core.Blueprint.Service.UseCases.CreateSampleItem.Ports; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.CreateSampleItem.Adapter | ||||
| { | ||||
|     public class CreateSampleItemPort : BasePresenter, ICreateSampleItemPort | ||||
|     { | ||||
|         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.CreateSampleItem | ||||
| { | ||||
|     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.CreateSampleItem.Input | ||||
| { | ||||
|     public class CreateSampleItemRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string TestName { get; set; } = string.Empty; | ||||
|         public int NumValue { get; set; } = 0; | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return true; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,9 @@ | ||||
| using Core.Blueprint.Service.Domain.Entities; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.CreateSampleItem.Ports | ||||
| { | ||||
|     public interface ICreateSampleItemPort : IBasePort, ICommandSuccessPort<SqlSampleItemEntity>, INoContentPort, IBusinessErrorPort, ITimeoutPort, IValidationErrorPort | ||||
|     { | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,16 @@ | ||||
| using Core.Blueprint.Service.UseCases.CreateSampleItem.Input; | ||||
| using FluentValidation; | ||||
| using System.Diagnostics.CodeAnalysis; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.CreateSampleItem.Validator | ||||
| { | ||||
|     [ExcludeFromCodeCoverage] | ||||
|     public class CreateSampleItemValidator : AbstractValidator<CreateSampleItemRequest> | ||||
|     { | ||||
|         public CreateSampleItemValidator() | ||||
|         { | ||||
|             RuleFor(i => i.TestName).NotNull().NotEmpty().WithMessage("Is required."); | ||||
|             RuleFor(i => i.NumValue).GreaterThanOrEqualTo(1).LessThanOrEqualTo(100).WithMessage("Should be between 1-100."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,15 @@ | ||||
| using Core.Blueprint.Service.Domain.Entities; | ||||
| using Core.Blueprint.Service.UseCases.DeleteSampleItem.Ports; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.DeleteSampleItem.Adapter | ||||
| { | ||||
|     public class DeleteSampleItemPort : BasePresenter, IDeleteSampleItemPort | ||||
|     { | ||||
|         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.DeleteSampleItem.Input; | ||||
| using Core.Blueprint.Service.UseCases.DeleteSampleItem.Ports; | ||||
| using FluentValidation; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.DeleteSampleItem | ||||
| { | ||||
|     public class DeleteSampleItemHandler(IDeleteSampleItemPort port, IValidator<DeleteSampleItemRequest> validator, ISampleItemClientService clientService) : IComponentHandler<DeleteSampleItemRequest> | ||||
|     { | ||||
|         private readonly IDeleteSampleItemPort _port = port; | ||||
|         private readonly IValidator<DeleteSampleItemRequest> _validator = validator; | ||||
|         private readonly ISampleItemClientService _clientService = clientService; | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(DeleteSampleItemRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 if (!command.IsValid(_validator)) | ||||
|                 { | ||||
|                     _port.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|                 var entity = await _clientService.GetSampleItemAsync(command.Id); | ||||
|                 if (entity == null) | ||||
|                 { | ||||
|                     _port.BusinessError("Not Found"); | ||||
|                     return; | ||||
|                 } | ||||
|                 entity.StatusCode = 'D'; | ||||
|                 await _clientService.UpdateSampleItemAsync(command.Id, entity); | ||||
|  | ||||
|                 _port.NoContentSuccess(); | ||||
|             } | ||||
|             catch(Exception ex) | ||||
|             { | ||||
|                 _port.BusinessError(ex.Message); | ||||
|             } | ||||
|  | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,13 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.DeleteSampleItem.Input | ||||
| { | ||||
|     public class DeleteSampleItemRequest : Notificator, ICommand | ||||
|     { | ||||
|         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.DeleteSampleItem.Ports | ||||
| { | ||||
|     public interface IDeleteSampleItemPort : IBasePort, ICommandSuccessPort<SqlSampleItemEntity>, INoContentPort, IBusinessErrorPort, ITimeoutPort, IValidationErrorPort | ||||
|     { | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,15 @@ | ||||
| using Core.Blueprint.Service.UseCases.DeleteSampleItem.Input; | ||||
| using FluentValidation; | ||||
| using System.Diagnostics.CodeAnalysis; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.DeleteSampleItem.Validator | ||||
| { | ||||
|     [ExcludeFromCodeCoverage] | ||||
|     public class DeleteSampleItemValidator : AbstractValidator<DeleteSampleItemRequest> | ||||
|     { | ||||
|         public DeleteSampleItemValidator() | ||||
|         { | ||||
|             RuleFor(i => i.Id).NotNull().NotEmpty().WithMessage("Is required."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -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."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,15 @@ | ||||
| using Core.Blueprint.Service.Domain.Dtos; | ||||
| using Core.Blueprint.Service.UseCases.GetSampleImage.Ports; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.GetSampleImage.Adapter | ||||
| { | ||||
|     public class GetSampleImagePort : BasePresenter, IGetSampleImagePort | ||||
|     { | ||||
|         public void Success(SampleImageUrlDto output) | ||||
|         { | ||||
|             ViewModel = new OkObjectResult(output); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,43 @@ | ||||
| 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<GetSampleImageRequest> validator, ISampleImageClientService clientService) : IComponentHandler<GetSampleImageRequest> | ||||
|     { | ||||
|         private readonly IGetSampleImagePort _port = port; | ||||
|         private readonly IValidator<GetSampleImageRequest> _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); | ||||
|             } | ||||
|  | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,12 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.GetSampleImage.Input | ||||
| { | ||||
|     public class GetSampleImageRequest : Notificator, ICommand | ||||
|     { | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return true; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,10 @@ | ||||
| using Core.Blueprint.Service.Domain.Dtos; | ||||
| using Core.Blueprint.Service.Domain.Entities; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.GetSampleImage.Ports | ||||
| { | ||||
|     public interface IGetSampleImagePort : IBasePort, ICommandSuccessPort<SampleImageUrlDto>, INoContentPort, IBusinessErrorPort, ITimeoutPort, IValidationErrorPort | ||||
|     { | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,15 @@ | ||||
| using Core.Blueprint.Service.UseCases.GetSampleImage.Input; | ||||
| using FluentValidation; | ||||
| using System.Diagnostics.CodeAnalysis; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.GetSampleImage.Validator | ||||
| { | ||||
|     [ExcludeFromCodeCoverage] | ||||
|     public class GetSampleImageValidator : AbstractValidator<GetSampleImageRequest> | ||||
|     { | ||||
|         public GetSampleImageValidator() | ||||
|         { | ||||
|              | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -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."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,22 @@ | ||||
| using Core.Blueprint.Service.Domain.Entities; | ||||
| using Core.Blueprint.Service.UseCases.GetSampleItems.Ports; | ||||
| using Core.Blueprint.Service.UseCases.GetSecret.Ports; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| using System.Threading.Tasks; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.GetSecret.Adapter | ||||
| { | ||||
|     public class GetSecretPort : BasePresenter, IGetSecretPort | ||||
|     { | ||||
|  | ||||
|         public void Success(SecretEntity output) | ||||
|         { | ||||
|             ViewModel = new OkObjectResult(output); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,50 @@ | ||||
| using Core.Blueprint.Service.Domain.Entities; | ||||
| using Core.Blueprint.Service.External.Clients.SecretClient; | ||||
| using Core.Blueprint.Service.UseCases.GetSampleItems.Input; | ||||
| using Core.Blueprint.Service.UseCases.GetSampleItems.Ports; | ||||
| using Core.Blueprint.Service.UseCases.GetSecret.Input; | ||||
| using Core.Blueprint.Service.UseCases.GetSecret.Ports; | ||||
| using FluentValidation; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.ComponentModel.DataAnnotations; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| using System.Threading.Tasks; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.GetSecret | ||||
| { | ||||
|     public class GetSecretHandler(IGetSecretPort port, IValidator<GetSecretRequest> validator, ISecretService secretService) : IComponentHandler<GetSecretRequest> | ||||
|     { | ||||
|         private readonly IGetSecretPort _port = port; | ||||
|         private readonly IValidator<GetSecretRequest> _validator = validator; | ||||
|         private readonly ISecretService _secretService = secretService; | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(GetSecretRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 if (!command.IsValid(_validator)) | ||||
|                 { | ||||
|                     _port.ValidationErrors(command.Notifications); | ||||
|                 } | ||||
|  | ||||
|                 var result = await _secretService.GetSecretAsync(command.Secret); | ||||
|  | ||||
|                 if (result is null || string.IsNullOrWhiteSpace(result.Value)) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 _port.BusinessError(ex.Message); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,19 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| using System.Threading.Tasks; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.GetSecret.Input | ||||
| { | ||||
|     public class GetSecretRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string? Secret { get; set; } | ||||
|  | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return true; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,15 @@ | ||||
| using Core.Blueprint.Service.Domain.Dtos; | ||||
| using Core.Blueprint.Service.Domain.Entities; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| using System.Threading.Tasks; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.GetSecret.Ports | ||||
| { | ||||
|     public interface IGetSecretPort : IBasePort, ICommandSuccessPort<SecretEntity>, INoContentPort, IBusinessErrorPort, ITimeoutPort, IValidationErrorPort | ||||
|     { | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,21 @@ | ||||
| using Core.Blueprint.Service.UseCases.GetSampleItems.Input; | ||||
| using Core.Blueprint.Service.UseCases.GetSecret.Input; | ||||
| using FluentValidation; | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Diagnostics.CodeAnalysis; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| using System.Threading.Tasks; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.GetSecret.Validator | ||||
| { | ||||
|     [ExcludeFromCodeCoverage] | ||||
|     public class GetSecretValidator : AbstractValidator<GetSecretRequest> | ||||
|     { | ||||
|         public GetSecretValidator() | ||||
|         { | ||||
|             RuleFor(i => i.Secret).NotNull().NotEmpty().WithMessage("Is required."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,16 @@ | ||||
| using Core.Blueprint.Service.Domain.Dtos; | ||||
| using Core.Blueprint.Service.UseCases.GetSampleImage.Ports; | ||||
| using Core.Blueprint.Service.UseCases.GetUploadImageUrl.Ports; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.GetUploadImageUrl.Adapter | ||||
| { | ||||
|     public class GetUploadUrlPort : BasePresenter, IGetUploadUrlPort | ||||
|     { | ||||
|         public void Success(SampleImageUrlDto output) | ||||
|         { | ||||
|             ViewModel = new OkObjectResult(output); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,42 @@ | ||||
| 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); | ||||
|             } | ||||
|  | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,12 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.GetUploadImageUrl.Input | ||||
| { | ||||
|     public class GetUploadUrlRequest : Notificator, ICommand | ||||
|     { | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return true; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,10 @@ | ||||
| using Core.Blueprint.Service.Domain.Dtos; | ||||
| using Core.Blueprint.Service.Domain.Entities; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.GetUploadImageUrl.Ports | ||||
| { | ||||
|     public interface IGetUploadUrlPort : IBasePort, ICommandSuccessPort<SampleImageUrlDto>, INoContentPort, IBusinessErrorPort, ITimeoutPort, IValidationErrorPort | ||||
|     { | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,16 @@ | ||||
| using Core.Blueprint.Service.UseCases.GetSampleImage.Input; | ||||
| using Core.Blueprint.Service.UseCases.GetUploadImageUrl.Input; | ||||
| using FluentValidation; | ||||
| using System.Diagnostics.CodeAnalysis; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.GetUploadImageUrl.Validator | ||||
| { | ||||
|     [ExcludeFromCodeCoverage] | ||||
|     public class GetUploadUrlValidator : AbstractValidator<GetUploadUrlRequest> | ||||
|     { | ||||
|         public GetUploadUrlValidator() | ||||
|         { | ||||
|              | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,15 @@ | ||||
| using Core.Blueprint.Service.Domain.Entities; | ||||
| using Core.Blueprint.Service.UseCases.UpdateSampleItem.Ports; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.UpdateSampleItem.Adapter | ||||
| { | ||||
|     public class UpdateSampleItemPort : BasePresenter, IUpdateSampleItemPort | ||||
|     { | ||||
|         public void Success(SqlSampleItemEntity output) | ||||
|         { | ||||
|             ViewModel = new OkObjectResult(output); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,17 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.UpdateSampleItem.Input | ||||
| { | ||||
|     public class UpdateSampleItemRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Id { get; set; } = string.Empty; | ||||
|         public string TestName { get; set; } = string.Empty; | ||||
|         public int NumValue { get; set; } = 0; | ||||
|         public char StatusCode { get; set; } = 'P'; | ||||
|  | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return true; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,9 @@ | ||||
| using Core.Blueprint.Service.Domain.Entities; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.UpdateSampleItem.Ports | ||||
| { | ||||
|     public interface IUpdateSampleItemPort : IBasePort, ICommandSuccessPort<SqlSampleItemEntity>, INoContentPort, IBusinessErrorPort, ITimeoutPort, IValidationErrorPort | ||||
|     { | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,45 @@ | ||||
| using Core.Blueprint.Service.Domain.Entities; | ||||
| using Core.Blueprint.Service.External.Clients.SampleItemClient; | ||||
| using Core.Blueprint.Service.UseCases.UpdateSampleItem.Input; | ||||
| using Core.Blueprint.Service.UseCases.UpdateSampleItem.Ports; | ||||
| using FluentValidation; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.UpdateSampleItem | ||||
| { | ||||
|     public class UpdateSampleItemHandler(IUpdateSampleItemPort port, IValidator<UpdateSampleItemRequest> validator, ISampleItemClientService clientService) : IComponentHandler<UpdateSampleItemRequest> | ||||
|     { | ||||
|         private readonly IUpdateSampleItemPort _port = port; | ||||
|         private readonly IValidator<UpdateSampleItemRequest> _validator = validator; | ||||
|         private readonly ISampleItemClientService _clientService = clientService; | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(UpdateSampleItemRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 if (!command.IsValid(_validator)) | ||||
|                 { | ||||
|                     _port.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 var result = await _clientService.UpdateSampleItemAsync(command.Id, | ||||
|  | ||||
|                     new SqlSampleItemEntity { Id = command.Id, TestName = command.TestName, NumValue = command.NumValue, StatusCode = command.StatusCode }); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 _port.BusinessError(ex.Message); | ||||
|             } | ||||
|  | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,16 @@ | ||||
| using Core.Blueprint.Service.UseCases.UpdateSampleItem.Input; | ||||
| using FluentValidation; | ||||
| using System.Diagnostics.CodeAnalysis; | ||||
|  | ||||
| namespace Core.Blueprint.Service.UseCases.UpdateSampleItem.Validator | ||||
| { | ||||
|     [ExcludeFromCodeCoverage] | ||||
|     public class UpdateSampleItemValidator : AbstractValidator<UpdateSampleItemRequest> | ||||
|     { | ||||
|         public UpdateSampleItemValidator() | ||||
|         { | ||||
|             RuleFor(i => i.TestName).NotNull().NotEmpty().WithMessage("Is required."); | ||||
|             RuleFor(i => i.NumValue).GreaterThanOrEqualTo(1).LessThanOrEqualTo(100).WithMessage("Should be between 1-100."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Sergio Matias Urquin
					Sergio Matias Urquin