Add project files.
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
using Core.Blueprint.Application.UsesCases.Mongo.Ports;
|
||||
using Core.Blueprint.Service.External.Clients.Adapters;
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Core.Blueprint.Application.UsesCases.MongoStorage.Adapter
|
||||
{
|
||||
public class MongoPort : BasePresenter, IMongoPort
|
||||
{
|
||||
public void Success(BlueprintAdapter output)
|
||||
{
|
||||
ViewModel = new OkObjectResult(output);
|
||||
}
|
||||
public void Success(List<BlueprintAdapter> output)
|
||||
{
|
||||
ViewModel = new OkObjectResult(output);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
|
||||
namespace Core.Blueprint.Application.UsesCases.Mongo.Input
|
||||
{
|
||||
public class CreateBlueprintRequest : Notificator, ICommand
|
||||
{
|
||||
public string Name { get; set; } = null!;
|
||||
|
||||
public string? Description { get; set; }
|
||||
|
||||
public bool Validate()
|
||||
{
|
||||
return Name != null && Name != string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
|
||||
namespace Core.Blueprint.Application.UsesCases.Mongo.Input
|
||||
{
|
||||
public class DeleteBlueprintRequest : Notificator, ICommand
|
||||
{
|
||||
public string _Id { get; set; }
|
||||
|
||||
public bool Validate()
|
||||
{
|
||||
return _Id != null && _Id != string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
|
||||
namespace Core.Blueprint.Application.UsesCases.Mongo.Input
|
||||
{
|
||||
public class GetAllBlueprintsRequest : Notificator, ICommand
|
||||
{
|
||||
public bool Validate()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
|
||||
namespace Core.Blueprint.Application.UsesCases.Mongo.Input
|
||||
{
|
||||
public class GetBlueprintRequest : Notificator, ICommand
|
||||
{
|
||||
public string _Id { get; set; }
|
||||
|
||||
public bool Validate()
|
||||
{
|
||||
return _Id != null && _Id != string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using Core.Blueprint.Service.External.Clients.Adapters;
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
|
||||
namespace Core.Blueprint.Application.UsesCases.Mongo.Input
|
||||
{
|
||||
public class UpdateBlueprintRequest : Notificator, ICommand
|
||||
{
|
||||
public string Name { get; set; } = null!;
|
||||
public string? Description { get; set; }
|
||||
public string _Id { get; set; } = null!;
|
||||
public string Id { get; init; } = null!;
|
||||
public DateTime CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTime? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
public StatusEnum Status { get; set; }
|
||||
public bool Validate()
|
||||
{
|
||||
return _Id != null && _Id != string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
197
Core.Blueprint.Application/UsesCases/Mongo/MongoHandler.cs
Normal file
197
Core.Blueprint.Application/UsesCases/Mongo/MongoHandler.cs
Normal file
@@ -0,0 +1,197 @@
|
||||
using Core.Blueprint.Application.UsesCases.Mongo.Input;
|
||||
using Core.Blueprint.Application.UsesCases.Mongo.Ports;
|
||||
using Core.Blueprint.Service.External.Clients;
|
||||
using Core.Blueprint.Service.External.Clients.Adapters;
|
||||
using Core.Blueprint.Service.External.Clients.Requests;
|
||||
using FluentValidation;
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
using Lib.Architecture.BuildingBlocks.Helpers;
|
||||
|
||||
namespace Core.Cerberos.Application.UseCases.Blueprints
|
||||
{
|
||||
public class MongoHandler :
|
||||
IComponentHandler<CreateBlueprintRequest>,
|
||||
IComponentHandler<GetBlueprintRequest>,
|
||||
IComponentHandler<GetAllBlueprintsRequest>,
|
||||
IComponentHandler<UpdateBlueprintRequest>,
|
||||
IComponentHandler<DeleteBlueprintRequest>
|
||||
{
|
||||
private readonly IMongoPort _port;
|
||||
private readonly IValidator<CreateBlueprintRequest> _createBlueprintValidator;
|
||||
private readonly IValidator<GetBlueprintRequest> _getBlueprintValidator;
|
||||
private readonly IValidator<UpdateBlueprintRequest> _updateBlueprintValidator;
|
||||
private readonly IValidator<DeleteBlueprintRequest> _deleteBlueprintValidator;
|
||||
private readonly IBlueprintServiceClient _mongoDALService;
|
||||
|
||||
public MongoHandler(
|
||||
IMongoPort port,
|
||||
IValidator<CreateBlueprintRequest> createBlueprintValidator,
|
||||
IValidator<GetBlueprintRequest> getBlueprintValidator,
|
||||
IValidator<UpdateBlueprintRequest> updateBlueprintValidator,
|
||||
IValidator<DeleteBlueprintRequest> deleteBlueprintValidator,
|
||||
IBlueprintServiceClient mongoDALService)
|
||||
{
|
||||
_port = port ?? throw new ArgumentNullException(nameof(port));
|
||||
_createBlueprintValidator = createBlueprintValidator ?? throw new ArgumentNullException(nameof(createBlueprintValidator));
|
||||
_getBlueprintValidator = getBlueprintValidator ?? throw new ArgumentNullException(nameof(getBlueprintValidator));
|
||||
_updateBlueprintValidator = updateBlueprintValidator ?? throw new ArgumentNullException(nameof(updateBlueprintValidator));
|
||||
_deleteBlueprintValidator = deleteBlueprintValidator ?? throw new ArgumentNullException(nameof(deleteBlueprintValidator));
|
||||
_mongoDALService = mongoDALService ?? throw new ArgumentNullException(nameof(mongoDALService));
|
||||
}
|
||||
|
||||
public async ValueTask ExecuteAsync(CreateBlueprintRequest command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(command);
|
||||
|
||||
if (!command.IsValid(_createBlueprintValidator))
|
||||
{
|
||||
_port.ValidationErrors(command.Notifications);
|
||||
return;
|
||||
}
|
||||
|
||||
var request = new BlueprintRequest
|
||||
{
|
||||
Name = command.Name,
|
||||
Description = command.Description,
|
||||
};
|
||||
|
||||
var result = await _mongoDALService.CreateBlueprintAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
_port.NoContentSuccess();
|
||||
return;
|
||||
}
|
||||
|
||||
_port.Success(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ApiResponseHelper.EvaluatePort(ex, _port);
|
||||
}
|
||||
}
|
||||
|
||||
public async ValueTask ExecuteAsync(GetAllBlueprintsRequest command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(command);
|
||||
|
||||
var _result = await _mongoDALService.GetAllBlueprintsAsync().ConfigureAwait(false);
|
||||
if (!_result.Any())
|
||||
{
|
||||
_port.NoContentSuccess();
|
||||
return;
|
||||
}
|
||||
_port.Success(_result.ToList());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ApiResponseHelper.EvaluatePort(ex, _port);
|
||||
}
|
||||
}
|
||||
|
||||
public async ValueTask ExecuteAsync(GetBlueprintRequest command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(command);
|
||||
|
||||
if (!command.IsValid(_getBlueprintValidator))
|
||||
{
|
||||
_port.ValidationErrors(command.Notifications);
|
||||
return;
|
||||
}
|
||||
|
||||
var result = await _mongoDALService.GetBlueprintByIdAsync(command._Id, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
_port.NoContentSuccess();
|
||||
return;
|
||||
}
|
||||
|
||||
_port.Success(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ApiResponseHelper.EvaluatePort(ex, _port);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async ValueTask ExecuteAsync(UpdateBlueprintRequest command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(command);
|
||||
|
||||
if (!command.IsValid(_updateBlueprintValidator))
|
||||
{
|
||||
_port.ValidationErrors(command.Notifications);
|
||||
return;
|
||||
}
|
||||
|
||||
var request = new BlueprintAdapter
|
||||
{
|
||||
Id = command.Id,
|
||||
_Id = command._Id,
|
||||
Name = command.Name,
|
||||
Description = command.Description,
|
||||
CreatedAt = command.CreatedAt,
|
||||
CreatedBy = command.CreatedBy,
|
||||
UpdatedAt = command.UpdatedAt,
|
||||
UpdatedBy = command.UpdatedBy,
|
||||
Status = command.Status
|
||||
};
|
||||
|
||||
string _id = command._Id;
|
||||
|
||||
var result = await _mongoDALService.UpdateBlueprintAsync(_id, request, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
_port.NoContentSuccess();
|
||||
return;
|
||||
}
|
||||
|
||||
_port.Success(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ApiResponseHelper.EvaluatePort(ex, _port);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async ValueTask ExecuteAsync(DeleteBlueprintRequest command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(command);
|
||||
|
||||
if (!command.IsValid(_deleteBlueprintValidator))
|
||||
{
|
||||
_port.ValidationErrors(command.Notifications);
|
||||
return;
|
||||
}
|
||||
|
||||
var result = await _mongoDALService.DeleteBlueprintAsync(command._Id, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
_port.NoContentSuccess();
|
||||
return;
|
||||
}
|
||||
|
||||
_port.Success(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ApiResponseHelper.EvaluatePort(ex, _port);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Core.Blueprint.Service.External.Clients.Adapters;
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
|
||||
namespace Core.Blueprint.Application.UsesCases.Mongo.Ports
|
||||
{
|
||||
public interface IMongoPort : IBasePort,
|
||||
ICommandSuccessPort<BlueprintAdapter>,
|
||||
ICommandSuccessPort<List<BlueprintAdapter>>,
|
||||
INoContentPort, IBusinessErrorPort, ITimeoutPort, IValidationErrorPort,
|
||||
INotFoundPort, IForbiddenPort, IUnauthorizedPort, IInternalServerErrorPort,
|
||||
IBadRequestPort
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Core.Blueprint.Application.UsesCases.Mongo.Input;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Core.Cerberos.Application.UseCases.Blueprints.Validator
|
||||
{
|
||||
public class CreateBlueprintValidator : AbstractValidator<CreateBlueprintRequest>
|
||||
{
|
||||
public CreateBlueprintValidator()
|
||||
{
|
||||
RuleFor(i => i.Name).NotEmpty().NotNull().OverridePropertyName(x => x.Name).WithName("Blueprint Name").WithMessage("Blueprint Name is Obligatory.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Core.Blueprint.Application.UsesCases.Mongo.Input;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Core.Cerberos.Application.UseCases.Blueprints.Validator
|
||||
{
|
||||
public class DeleteBlueprintValidator : AbstractValidator<DeleteBlueprintRequest>
|
||||
{
|
||||
public DeleteBlueprintValidator()
|
||||
{
|
||||
RuleFor(i => i._Id).NotEmpty().NotNull().OverridePropertyName(x => x._Id).WithName("Blueprint Mongo Identifier").WithMessage("Blueprint Mongo Identifier is Obligatory.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Core.Blueprint.Application.UsesCases.Mongo.Input;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Core.Cerberos.Application.UseCases.Blueprints.Validator
|
||||
{
|
||||
public class GetBlueprintValidator : AbstractValidator<GetBlueprintRequest>
|
||||
{
|
||||
public GetBlueprintValidator()
|
||||
{
|
||||
RuleFor(i => i._Id).NotEmpty().NotNull().OverridePropertyName(x => x._Id).WithName("Blueprint Mongo Identifier").WithMessage("Blueprint Mongo Identifier is Obligatory.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using Core.Blueprint.Application.UsesCases.Mongo.Input;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Core.Cerberos.Application.UseCases.Blueprints.Validator
|
||||
{
|
||||
public class UpdateBlueprintValidator : AbstractValidator<UpdateBlueprintRequest>
|
||||
{
|
||||
public UpdateBlueprintValidator()
|
||||
{
|
||||
RuleFor(i => i._Id).NotEmpty().NotNull().OverridePropertyName(x => x._Id).WithName("Blueprint Mongo Identifier").WithMessage("Blueprint Mongo Identifier is Obligatory.");
|
||||
RuleFor(i => i._Id).NotEmpty().NotNull().OverridePropertyName(x => x.Id).WithName("Blueprint GUID").WithMessage("Blueprint GUID is Obligatory.");
|
||||
RuleFor(i => i.Name).NotEmpty().NotNull().OverridePropertyName(x => x.Name).WithName("Blueprint Name").WithMessage("Blueprint Name is Obligatory.");
|
||||
RuleFor(i => i.Status).NotNull().OverridePropertyName(x => x.Status).WithName("Blueprint Status").WithMessage("Blueprint Status is Obligatory.");
|
||||
RuleFor(i => i.CreatedAt).NotNull().OverridePropertyName(x => x.CreatedAt).WithName("Blueprint CreatedAt").WithMessage("Blueprint CreatedAt is Obligatory.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user