Add project files.
This commit is contained in:
@@ -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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user