Create general structures in Mongo and SQL

This commit is contained in:
Sergio Matias Urquin
2025-05-18 15:49:46 -06:00
parent 144a6c14c0
commit c7953250fc
51 changed files with 370 additions and 365 deletions

View File

@@ -3,15 +3,15 @@ using Core.Blueprint.Service.External.Clients.Adapters;
using Lib.Architecture.BuildingBlocks;
using Microsoft.AspNetCore.Mvc;
namespace Core.Blueprint.Application.UsesCases.MongoStorage.Adapter
namespace Core.Blueprint.Application.UsesCases.Mongo.Adapter
{
public class MongoPort : BasePresenter, IMongoPort
{
public void Success(BlueprintAdapter output)
public void Success(MongoSampleAdapter output)
{
ViewModel = new OkObjectResult(output);
}
public void Success(List<BlueprintAdapter> output)
public void Success(List<MongoSampleAdapter> output)
{
ViewModel = new OkObjectResult(output);
}

View File

@@ -2,7 +2,7 @@
namespace Core.Blueprint.Application.UsesCases.Mongo.Input
{
public class CreateBlueprintRequest : Notificator, ICommand
public class CreateMongoSampleRequest : Notificator, ICommand
{
public string Name { get; set; } = null!;

View File

@@ -2,7 +2,7 @@
namespace Core.Blueprint.Application.UsesCases.Mongo.Input
{
public class DeleteBlueprintRequest : Notificator, ICommand
public class DeleteMongoSampleRequest : Notificator, ICommand
{
public string _Id { get; set; }

View File

@@ -2,7 +2,7 @@
namespace Core.Blueprint.Application.UsesCases.Mongo.Input
{
public class GetAllBlueprintsRequest : Notificator, ICommand
public class GetAllMongoSamplesRequest : Notificator, ICommand
{
public bool Validate()
{

View File

@@ -2,7 +2,7 @@
namespace Core.Blueprint.Application.UsesCases.Mongo.Input
{
public class GetBlueprintRequest : Notificator, ICommand
public class GetMongoSampleRequest : Notificator, ICommand
{
public string _Id { get; set; }

View File

@@ -3,7 +3,7 @@ using Lib.Architecture.BuildingBlocks;
namespace Core.Blueprint.Application.UsesCases.Mongo.Input
{
public class UpdateBlueprintRequest : Notificator, ICommand
public class UpdateMongoSampleRequest : Notificator, ICommand
{
public string Name { get; set; } = null!;
public string? Description { get; set; }

View File

@@ -7,57 +7,57 @@ using FluentValidation;
using Lib.Architecture.BuildingBlocks;
using Lib.Architecture.BuildingBlocks.Helpers;
namespace Core.Cerberos.Application.UseCases.Blueprints
namespace Core.Blueprint.Application.UsesCases.Mongo
{
public class MongoHandler :
IComponentHandler<CreateBlueprintRequest>,
IComponentHandler<GetBlueprintRequest>,
IComponentHandler<GetAllBlueprintsRequest>,
IComponentHandler<UpdateBlueprintRequest>,
IComponentHandler<DeleteBlueprintRequest>
IComponentHandler<CreateMongoSampleRequest>,
IComponentHandler<GetMongoSampleRequest>,
IComponentHandler<GetAllMongoSamplesRequest>,
IComponentHandler<UpdateMongoSampleRequest>,
IComponentHandler<DeleteMongoSampleRequest>
{
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;
private readonly IValidator<CreateMongoSampleRequest> _createSampleValidator;
private readonly IValidator<GetMongoSampleRequest> _getSampleValidator;
private readonly IValidator<UpdateMongoSampleRequest> _updateSampleValidator;
private readonly IValidator<DeleteMongoSampleRequest> _deleteSampleValidator;
private readonly IBlueprintServiceClient _blueprintServiceClient;
public MongoHandler(
IMongoPort port,
IValidator<CreateBlueprintRequest> createBlueprintValidator,
IValidator<GetBlueprintRequest> getBlueprintValidator,
IValidator<UpdateBlueprintRequest> updateBlueprintValidator,
IValidator<DeleteBlueprintRequest> deleteBlueprintValidator,
IBlueprintServiceClient mongoDALService)
IValidator<CreateMongoSampleRequest> createSampleValidator,
IValidator<GetMongoSampleRequest> getSampleValidator,
IValidator<UpdateMongoSampleRequest> updateSampleValidator,
IValidator<DeleteMongoSampleRequest> deleteSampleValidator,
IBlueprintServiceClient blueprintServiceClient)
{
_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));
_createSampleValidator = createSampleValidator ?? throw new ArgumentNullException(nameof(createSampleValidator));
_getSampleValidator = getSampleValidator ?? throw new ArgumentNullException(nameof(getSampleValidator));
_updateSampleValidator = updateSampleValidator ?? throw new ArgumentNullException(nameof(updateSampleValidator));
_deleteSampleValidator = deleteSampleValidator ?? throw new ArgumentNullException(nameof(deleteSampleValidator));
_blueprintServiceClient = blueprintServiceClient ?? throw new ArgumentNullException(nameof(blueprintServiceClient));
}
public async ValueTask ExecuteAsync(CreateBlueprintRequest command, CancellationToken cancellationToken = default)
public async ValueTask ExecuteAsync(CreateMongoSampleRequest command, CancellationToken cancellationToken = default)
{
try
{
ArgumentNullException.ThrowIfNull(command);
if (!command.IsValid(_createBlueprintValidator))
if (!command.IsValid(_createSampleValidator))
{
_port.ValidationErrors(command.Notifications);
return;
}
var request = new BlueprintRequest
var request = new MongoSampleRequest
{
Name = command.Name,
Description = command.Description,
};
var result = await _mongoDALService.CreateBlueprintAsync(request, cancellationToken).ConfigureAwait(false);
var result = await _blueprintServiceClient.CreateMongoSampleAsync(request, cancellationToken).ConfigureAwait(false);
if (result == null)
{
@@ -73,13 +73,13 @@ namespace Core.Cerberos.Application.UseCases.Blueprints
}
}
public async ValueTask ExecuteAsync(GetAllBlueprintsRequest command, CancellationToken cancellationToken = default)
public async ValueTask ExecuteAsync(GetAllMongoSamplesRequest command, CancellationToken cancellationToken = default)
{
try
{
ArgumentNullException.ThrowIfNull(command);
var _result = await _mongoDALService.GetAllBlueprintsAsync().ConfigureAwait(false);
var _result = await _blueprintServiceClient.GetAllMongoSamplesAsync().ConfigureAwait(false);
if (!_result.Any())
{
_port.NoContentSuccess();
@@ -93,19 +93,19 @@ namespace Core.Cerberos.Application.UseCases.Blueprints
}
}
public async ValueTask ExecuteAsync(GetBlueprintRequest command, CancellationToken cancellationToken = default)
public async ValueTask ExecuteAsync(GetMongoSampleRequest command, CancellationToken cancellationToken = default)
{
try
{
ArgumentNullException.ThrowIfNull(command);
if (!command.IsValid(_getBlueprintValidator))
if (!command.IsValid(_getSampleValidator))
{
_port.ValidationErrors(command.Notifications);
return;
}
var result = await _mongoDALService.GetBlueprintByIdAsync(command._Id, cancellationToken).ConfigureAwait(false);
var result = await _blueprintServiceClient.GetMongoSampleByIdAsync(command._Id, cancellationToken).ConfigureAwait(false);
if (result == null)
{
@@ -122,19 +122,19 @@ namespace Core.Cerberos.Application.UseCases.Blueprints
}
public async ValueTask ExecuteAsync(UpdateBlueprintRequest command, CancellationToken cancellationToken = default)
public async ValueTask ExecuteAsync(UpdateMongoSampleRequest command, CancellationToken cancellationToken = default)
{
try
{
ArgumentNullException.ThrowIfNull(command);
if (!command.IsValid(_updateBlueprintValidator))
if (!command.IsValid(_updateSampleValidator))
{
_port.ValidationErrors(command.Notifications);
return;
}
var request = new BlueprintAdapter
var request = new MongoSampleAdapter
{
Id = command.Id,
_Id = command._Id,
@@ -149,7 +149,7 @@ namespace Core.Cerberos.Application.UseCases.Blueprints
string _id = command._Id;
var result = await _mongoDALService.UpdateBlueprintAsync(_id, request, cancellationToken).ConfigureAwait(false);
var result = await _blueprintServiceClient.UpdateMongoSampleAsync(_id, request, cancellationToken).ConfigureAwait(false);
if (result == null)
{
@@ -166,19 +166,19 @@ namespace Core.Cerberos.Application.UseCases.Blueprints
}
public async ValueTask ExecuteAsync(DeleteBlueprintRequest command, CancellationToken cancellationToken = default)
public async ValueTask ExecuteAsync(DeleteMongoSampleRequest command, CancellationToken cancellationToken = default)
{
try
{
ArgumentNullException.ThrowIfNull(command);
if (!command.IsValid(_deleteBlueprintValidator))
if (!command.IsValid(_deleteSampleValidator))
{
_port.ValidationErrors(command.Notifications);
return;
}
var result = await _mongoDALService.DeleteBlueprintAsync(command._Id, cancellationToken).ConfigureAwait(false);
var result = await _blueprintServiceClient.DeleteMongoSampleAsync(command._Id, cancellationToken).ConfigureAwait(false);
if (result == null)
{

View File

@@ -4,8 +4,8 @@ using Lib.Architecture.BuildingBlocks;
namespace Core.Blueprint.Application.UsesCases.Mongo.Ports
{
public interface IMongoPort : IBasePort,
ICommandSuccessPort<BlueprintAdapter>,
ICommandSuccessPort<List<BlueprintAdapter>>,
ICommandSuccessPort<MongoSampleAdapter>,
ICommandSuccessPort<List<MongoSampleAdapter>>,
INoContentPort, IBusinessErrorPort, ITimeoutPort, IValidationErrorPort,
INotFoundPort, IForbiddenPort, IUnauthorizedPort, IInternalServerErrorPort,
IBadRequestPort

View File

@@ -1,13 +0,0 @@
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.");
}
}
}

View File

@@ -0,0 +1,13 @@
using Core.Blueprint.Application.UsesCases.Mongo.Input;
using FluentValidation;
namespace Core.Cerberos.Application.UseCases.Mongo.Validator
{
public class CreateMongoSampleValidator : AbstractValidator<CreateMongoSampleRequest>
{
public CreateMongoSampleValidator()
{
RuleFor(i => i.Name).NotEmpty().NotNull().OverridePropertyName(x => x.Name).WithName("Sample Name").WithMessage("Sample Name is Obligatory.");
}
}
}

View File

@@ -1,13 +0,0 @@
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.");
}
}
}

View File

@@ -0,0 +1,13 @@
using Core.Blueprint.Application.UsesCases.Mongo.Input;
using FluentValidation;
namespace Core.Cerberos.Application.UseCases.Mongo.Validator
{
public class DeleteMongoSampleValidator : AbstractValidator<DeleteMongoSampleRequest>
{
public DeleteMongoSampleValidator()
{
RuleFor(i => i._Id).NotEmpty().NotNull().OverridePropertyName(x => x._Id).WithName("Sample Identifier").WithMessage("Sample Identifier is Obligatory.");
}
}
}

View File

@@ -1,13 +0,0 @@
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.");
}
}
}

View File

@@ -0,0 +1,13 @@
using Core.Blueprint.Application.UsesCases.Mongo.Input;
using FluentValidation;
namespace Core.Cerberos.Application.UseCases.Mongo.Validator
{
public class GetMongoSampleValidator : AbstractValidator<GetMongoSampleRequest>
{
public GetMongoSampleValidator()
{
RuleFor(i => i._Id).NotEmpty().NotNull().OverridePropertyName(x => x._Id).WithName("Sample Identifier").WithMessage("Sample Identifier is Obligatory.");
}
}
}

View File

@@ -1,17 +0,0 @@
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.");
}
}
}

View File

@@ -0,0 +1,17 @@
using Core.Blueprint.Application.UsesCases.Mongo.Input;
using FluentValidation;
namespace Core.Cerberos.Application.UseCases.Mongo.Validator
{
public class UpdateMongoSampleValidator : AbstractValidator<UpdateMongoSampleRequest>
{
public UpdateMongoSampleValidator()
{
RuleFor(i => i._Id).NotEmpty().NotNull().OverridePropertyName(x => x._Id).WithName("Sample Identifier").WithMessage("Sample Identifier is Obligatory.");
RuleFor(i => i._Id).NotEmpty().NotNull().OverridePropertyName(x => x.Id).WithName("Sample GUID").WithMessage("Sample GUID is Obligatory.");
RuleFor(i => i.Name).NotEmpty().NotNull().OverridePropertyName(x => x.Name).WithName("Sample Name").WithMessage("Sample Name is Obligatory.");
RuleFor(i => i.Status).NotNull().OverridePropertyName(x => x.Status).WithName("Sample Status").WithMessage("Sample Status is Obligatory.");
RuleFor(i => i.CreatedAt).NotNull().OverridePropertyName(x => x.CreatedAt).WithName("Sample CreatedAt").WithMessage("Sample CreatedAt is Obligatory.");
}
}
}