Add project files.
This commit is contained in:
@@ -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