Add project files.
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
using Core.Blueprint.Application.UsesCases.BlobStorage.Ports;
|
||||
using Core.Blueprint.Storage;
|
||||
using Core.Blueprint.Storage.Adapters;
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Core.Blueprint.Application.UsesCases.BlobStorage.Adapter
|
||||
{
|
||||
public class StoragePort : BasePresenter, IStoragePort
|
||||
{
|
||||
public void Success(List<BlobFileAdapter> output)
|
||||
{
|
||||
ViewModel = new OkObjectResult(output);
|
||||
}
|
||||
public void Success(BlobFileAdapter output)
|
||||
{
|
||||
ViewModel = new OkObjectResult(output);
|
||||
}
|
||||
|
||||
public void Success(BlobDownloadUriAdapter output)
|
||||
{
|
||||
ViewModel = new OkObjectResult(output);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
|
||||
namespace Core.Blueprint.Application.UsesCases.KeyVault.Input
|
||||
{
|
||||
public class DeleteBlobRequest : Notificator, ICommand
|
||||
{
|
||||
public string BlobName { get; set; }
|
||||
|
||||
public bool Validate()
|
||||
{
|
||||
return !string.IsNullOrEmpty(BlobName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
|
||||
namespace Core.Blueprint.Application.UsesCases.KeyVault.Input
|
||||
{
|
||||
public class DownloadBlobRequest : Notificator, ICommand
|
||||
{
|
||||
public string BlobName { get; set; } = null!;
|
||||
public bool Validate()
|
||||
{
|
||||
return !string.IsNullOrEmpty(BlobName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
|
||||
namespace Core.Blueprint.Application.UsesCases.KeyVault.Input
|
||||
{
|
||||
public class GetBlobListRequest : Notificator, ICommand
|
||||
{
|
||||
public string? Prefix { get; set; }
|
||||
public bool Validate()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
|
||||
namespace Core.Blueprint.Application.UsesCases.KeyVault.Input
|
||||
{
|
||||
public class UploadBlobRequest : Notificator, ICommand
|
||||
{
|
||||
public string BlobName { get; set; } = null!;
|
||||
|
||||
public byte[] File { get; set; } = null!;
|
||||
|
||||
public bool Validate()
|
||||
{
|
||||
return !string.IsNullOrEmpty(BlobName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using Core.Blueprint.Storage;
|
||||
using Core.Blueprint.Storage.Adapters;
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
|
||||
namespace Core.Blueprint.Application.UsesCases.BlobStorage.Ports
|
||||
{
|
||||
public interface IStoragePort : IBasePort,
|
||||
ICommandSuccessPort<List<BlobFileAdapter>>,
|
||||
ICommandSuccessPort<BlobFileAdapter>,
|
||||
ICommandSuccessPort<BlobDownloadUriAdapter>,
|
||||
INoContentPort, IBusinessErrorPort, ITimeoutPort, IValidationErrorPort,
|
||||
INotFoundPort, IForbiddenPort, IUnauthorizedPort, IInternalServerErrorPort,
|
||||
IBadRequestPort
|
||||
{
|
||||
}
|
||||
}
|
||||
160
Core.Blueprint.Application/UsesCases/BlobStorage/Storage.cs
Normal file
160
Core.Blueprint.Application/UsesCases/BlobStorage/Storage.cs
Normal file
@@ -0,0 +1,160 @@
|
||||
using Core.Blueprint.Application.UsesCases.KeyVault.Input;
|
||||
using Core.Blueprint.Application.UsesCases.KeyVault.Ports;
|
||||
using Core.Blueprint.KeyVault;
|
||||
using Core.Blueprint.Service.External.Clients;
|
||||
using FluentValidation;
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
using Lib.Architecture.BuildingBlocks.Helpers;
|
||||
|
||||
namespace Core.Cerberos.Application.UseCases.KeyVault
|
||||
{
|
||||
public class Storage :
|
||||
IComponentHandler<CreateBlobRequest>,
|
||||
IComponentHandler<GetBlobListRequest>,
|
||||
IComponentHandler<UpdateBlobRequest>,
|
||||
IComponentHandler<DeleteBlobRequest>
|
||||
{
|
||||
private readonly IKeyVaultPort _port;
|
||||
private readonly IValidator<CreateBlobRequest> _createKeyVaultValidator;
|
||||
private readonly IValidator<GetBlobListRequest> _getKeyVaultValidator;
|
||||
private readonly IValidator<UpdateBlobRequest> _updateKeyVaultValidator;
|
||||
private readonly IValidator<DeleteBlobRequest> _deleteKeyVaultValidator;
|
||||
private readonly IBlueprintServiceClient _keyVaultDALService;
|
||||
|
||||
public Storage(
|
||||
IKeyVaultPort port,
|
||||
IValidator<CreateBlobRequest> createKeyVaultValidator,
|
||||
IValidator<GetBlobListRequest> getKeyVaultValidator,
|
||||
IValidator<UpdateBlobRequest> updateKeyVaultValidator,
|
||||
IValidator<DeleteBlobRequest> deleteKeyVaultValidator,
|
||||
IBlueprintServiceClient keyVaultDALService)
|
||||
{
|
||||
_port = port ?? throw new ArgumentNullException(nameof(port));
|
||||
_createKeyVaultValidator = createKeyVaultValidator ?? throw new ArgumentNullException(nameof(createKeyVaultValidator));
|
||||
_getKeyVaultValidator = getKeyVaultValidator ?? throw new ArgumentNullException(nameof(getKeyVaultValidator));
|
||||
_updateKeyVaultValidator = updateKeyVaultValidator ?? throw new ArgumentNullException(nameof(updateKeyVaultValidator));
|
||||
_deleteKeyVaultValidator = deleteKeyVaultValidator ?? throw new ArgumentNullException(nameof(deleteKeyVaultValidator));
|
||||
_keyVaultDALService = keyVaultDALService ?? throw new ArgumentNullException(nameof(keyVaultDALService));
|
||||
}
|
||||
|
||||
public async ValueTask ExecuteAsync(CreateBlobRequest command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(command);
|
||||
|
||||
if (!command.IsValid(_createKeyVaultValidator))
|
||||
{
|
||||
_port.ValidationErrors(command.Notifications);
|
||||
return;
|
||||
}
|
||||
|
||||
var request = new KeyVaultRequest
|
||||
{
|
||||
Name = command.Name,
|
||||
Value = command.Value,
|
||||
};
|
||||
|
||||
var result = await _keyVaultDALService.CreateSecretAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
_port.NoContentSuccess();
|
||||
return;
|
||||
}
|
||||
|
||||
_port.Success(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ApiResponseHelper.EvaluatePort(ex, _port);
|
||||
}
|
||||
}
|
||||
|
||||
public async ValueTask ExecuteAsync(GetBlobListRequest command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(command);
|
||||
|
||||
var result = await _keyVaultDALService.GetSecretByNameAsync("", cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
_port.NoContentSuccess();
|
||||
return;
|
||||
}
|
||||
|
||||
_port.Success(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ApiResponseHelper.EvaluatePort(ex, _port);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async ValueTask ExecuteAsync(UpdateBlobRequest command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(command);
|
||||
|
||||
if (!command.IsValid(_updateKeyVaultValidator))
|
||||
{
|
||||
_port.ValidationErrors(command.Notifications);
|
||||
return;
|
||||
}
|
||||
|
||||
var request = new KeyVaultRequest
|
||||
{
|
||||
Name = command.Name,
|
||||
Value = command.Value,
|
||||
};
|
||||
|
||||
var result = await _keyVaultDALService.UpdateSecretAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
_port.NoContentSuccess();
|
||||
return;
|
||||
}
|
||||
|
||||
_port.Success(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ApiResponseHelper.EvaluatePort(ex, _port);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async ValueTask ExecuteAsync(DeleteBlobRequest command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(command);
|
||||
|
||||
if (!command.IsValid(_deleteKeyVaultValidator))
|
||||
{
|
||||
_port.ValidationErrors(command.Notifications);
|
||||
return;
|
||||
}
|
||||
|
||||
var result = await _keyVaultDALService.DeleteSecretAsync(command.Name, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
_port.NoContentSuccess();
|
||||
return;
|
||||
}
|
||||
|
||||
_port.Success(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ApiResponseHelper.EvaluatePort(ex, _port);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
using Core.Blueprint.Application.UsesCases.BlobStorage.Ports;
|
||||
using Core.Blueprint.Application.UsesCases.KeyVault.Input;
|
||||
using Core.Blueprint.Service.External.Clients;
|
||||
using Core.Blueprint.Storage;
|
||||
using FluentValidation;
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
using Lib.Architecture.BuildingBlocks.Helpers;
|
||||
|
||||
namespace Core.Cerberos.Application.UseCases.KeyVault
|
||||
{
|
||||
public class StorageHandler :
|
||||
IComponentHandler<UploadBlobRequest>,
|
||||
IComponentHandler<GetBlobListRequest>,
|
||||
IComponentHandler<DownloadBlobRequest>,
|
||||
IComponentHandler<DeleteBlobRequest>
|
||||
{
|
||||
private readonly IStoragePort _port;
|
||||
private readonly IValidator<UploadBlobRequest> _uploadBlobValidator;
|
||||
private readonly IValidator<DownloadBlobRequest> _downloadBlobValidator;
|
||||
private readonly IValidator<DeleteBlobRequest> _deleteBlobValidator;
|
||||
private readonly IBlueprintServiceClient _storageDALService;
|
||||
|
||||
public StorageHandler(
|
||||
IStoragePort port,
|
||||
IValidator<UploadBlobRequest> uploadBlobValidator,
|
||||
IValidator<DownloadBlobRequest> downloadBlobValidator,
|
||||
IValidator<DeleteBlobRequest> deleteBlobValidator,
|
||||
IBlueprintServiceClient storageDALService)
|
||||
{
|
||||
_port = port ?? throw new ArgumentNullException(nameof(port));
|
||||
_uploadBlobValidator = uploadBlobValidator ?? throw new ArgumentNullException(nameof(uploadBlobValidator));
|
||||
_downloadBlobValidator = downloadBlobValidator ?? throw new ArgumentNullException(nameof(downloadBlobValidator));
|
||||
_deleteBlobValidator = deleteBlobValidator ?? throw new ArgumentNullException(nameof(deleteBlobValidator));
|
||||
_storageDALService = storageDALService ?? throw new ArgumentNullException(nameof(storageDALService));
|
||||
}
|
||||
|
||||
public async ValueTask ExecuteAsync(UploadBlobRequest command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(command);
|
||||
|
||||
if (!command.IsValid(_uploadBlobValidator))
|
||||
{
|
||||
_port.ValidationErrors(command.Notifications);
|
||||
return;
|
||||
}
|
||||
|
||||
var request = new BlobAddDto
|
||||
{
|
||||
FileName = command.BlobName,
|
||||
FileContent = command.File
|
||||
};
|
||||
|
||||
var result = await _storageDALService.UploadBlobAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
_port.NoContentSuccess();
|
||||
return;
|
||||
}
|
||||
|
||||
_port.Success(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ApiResponseHelper.EvaluatePort(ex, _port);
|
||||
}
|
||||
}
|
||||
|
||||
public async ValueTask ExecuteAsync(GetBlobListRequest command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(command);
|
||||
|
||||
var result = await _storageDALService.GetBlobListAsync(command.Prefix, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
_port.NoContentSuccess();
|
||||
return;
|
||||
}
|
||||
|
||||
_port.Success(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ApiResponseHelper.EvaluatePort(ex, _port);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async ValueTask ExecuteAsync(DownloadBlobRequest command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(command);
|
||||
|
||||
if (!command.IsValid(_downloadBlobValidator))
|
||||
{
|
||||
_port.ValidationErrors(command.Notifications);
|
||||
return;
|
||||
}
|
||||
|
||||
var result = await _storageDALService.DownloadBlobAsync(command.BlobName, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
_port.NoContentSuccess();
|
||||
return;
|
||||
}
|
||||
|
||||
_port.Success(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ApiResponseHelper.EvaluatePort(ex, _port);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async ValueTask ExecuteAsync(DeleteBlobRequest command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(command);
|
||||
|
||||
if (!command.IsValid(_deleteBlobValidator))
|
||||
{
|
||||
_port.ValidationErrors(command.Notifications);
|
||||
return;
|
||||
}
|
||||
|
||||
var result = await _storageDALService.DeleteBlobAsync(command.BlobName, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
_port.NoContentSuccess();
|
||||
return;
|
||||
}
|
||||
|
||||
_port.Success(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ApiResponseHelper.EvaluatePort(ex, _port);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Core.Blueprint.Application.UsesCases.KeyVault.Input;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Core.Cerberos.Application.UseCases.KeyVault.Validator
|
||||
{
|
||||
public class DeleteBlobValidator : AbstractValidator<DeleteBlobRequest>
|
||||
{
|
||||
public DeleteBlobValidator()
|
||||
{
|
||||
RuleFor(i => i.BlobName).NotEmpty().NotNull().OverridePropertyName(x => x.BlobName).WithName("Blob Name").WithMessage("Blob Name is Obligatory.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Core.Blueprint.Application.UsesCases.KeyVault.Input;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Core.Cerberos.Application.UseCases.KeyVault.Validator
|
||||
{
|
||||
public class DownloadBlobValidator : AbstractValidator<DownloadBlobRequest>
|
||||
{
|
||||
public DownloadBlobValidator()
|
||||
{
|
||||
RuleFor(i => i.BlobName).NotEmpty().NotNull().OverridePropertyName(x => x.BlobName).WithName("Blob Name").WithMessage("Blob Name is Obligatory.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Core.Blueprint.Application.UsesCases.KeyVault.Input;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Core.Cerberos.Application.UseCases.KeyVault.Validator
|
||||
{
|
||||
public class UploadBlobValidator : AbstractValidator<UploadBlobRequest>
|
||||
{
|
||||
public UploadBlobValidator()
|
||||
{
|
||||
RuleFor(i => i.BlobName).NotEmpty().NotNull().OverridePropertyName(x => x.BlobName).WithName("Blob Name").WithMessage("Blob Name is Obligatory.");
|
||||
RuleFor(i => i.File).NotNull().OverridePropertyName(x => x.File).WithName("Blob File").WithMessage("Blob File is Obligatory.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using Core.Blueprint.Application.UsesCases.KeyVault.Ports;
|
||||
using Core.Blueprint.KeyVault;
|
||||
using Core.Blueprint.Service.External.Clients.Adapters;
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Core.Blueprint.Application.UsesCases.MongoStorage.Adapter
|
||||
{
|
||||
public class KeyVaultPort : BasePresenter, IKeyVaultPort
|
||||
{
|
||||
public void Success(KeyVaultResponse output)
|
||||
{
|
||||
ViewModel = new OkObjectResult(output);
|
||||
}
|
||||
public void Success(KeyVaultAdapter output)
|
||||
{
|
||||
ViewModel = new OkObjectResult(output);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
|
||||
namespace Core.Blueprint.Application.UsesCases.KeyVault.Input
|
||||
{
|
||||
public class CreateSecretRequest : Notificator, ICommand
|
||||
{
|
||||
public string Name { get; set; } = null!;
|
||||
|
||||
public string Value { get; set; } = null!;
|
||||
|
||||
public bool Validate()
|
||||
{
|
||||
return !string.IsNullOrEmpty(Name) && !string.IsNullOrEmpty(Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
|
||||
namespace Core.Blueprint.Application.UsesCases.KeyVault.Input
|
||||
{
|
||||
public class DeleteSecretRequest : Notificator, ICommand
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public bool Validate()
|
||||
{
|
||||
return !string.IsNullOrEmpty(Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
|
||||
namespace Core.Blueprint.Application.UsesCases.KeyVault.Input
|
||||
{
|
||||
public class GetSecretRequest : Notificator, ICommand
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public bool Validate()
|
||||
{
|
||||
return string.IsNullOrEmpty(Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
|
||||
namespace Core.Blueprint.Application.UsesCases.KeyVault.Input
|
||||
{
|
||||
public class UpdateSecretRequest : Notificator, ICommand
|
||||
{
|
||||
public string Name { get; set; } = null!;
|
||||
public string Value { get; set; } = null!;
|
||||
public bool Validate()
|
||||
{
|
||||
return !string.IsNullOrEmpty(Name) && !string.IsNullOrEmpty(Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
160
Core.Blueprint.Application/UsesCases/KeyVault/KeyVaultHandler.cs
Normal file
160
Core.Blueprint.Application/UsesCases/KeyVault/KeyVaultHandler.cs
Normal file
@@ -0,0 +1,160 @@
|
||||
using Core.Blueprint.Application.UsesCases.KeyVault.Input;
|
||||
using Core.Blueprint.Application.UsesCases.KeyVault.Ports;
|
||||
using Core.Blueprint.KeyVault;
|
||||
using Core.Blueprint.Service.External.Clients;
|
||||
using FluentValidation;
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
using Lib.Architecture.BuildingBlocks.Helpers;
|
||||
|
||||
namespace Core.Cerberos.Application.UseCases.KeyVault
|
||||
{
|
||||
public class KeyVaultHandler :
|
||||
IComponentHandler<CreateSecretRequest>,
|
||||
IComponentHandler<GetSecretRequest>,
|
||||
IComponentHandler<UpdateSecretRequest>,
|
||||
IComponentHandler<DeleteSecretRequest>
|
||||
{
|
||||
private readonly IKeyVaultPort _port;
|
||||
private readonly IValidator<CreateSecretRequest> _createSecretValidator;
|
||||
private readonly IValidator<GetSecretRequest> _getSecretValidator;
|
||||
private readonly IValidator<UpdateSecretRequest> _updateSecretValidator;
|
||||
private readonly IValidator<DeleteSecretRequest> _deleteSecretValidator;
|
||||
private readonly IBlueprintServiceClient _keyVaultDALService;
|
||||
|
||||
public KeyVaultHandler(
|
||||
IKeyVaultPort port,
|
||||
IValidator<CreateSecretRequest> createSecretValidator,
|
||||
IValidator<GetSecretRequest> getSecretValidator,
|
||||
IValidator<UpdateSecretRequest> updateSecretValidator,
|
||||
IValidator<DeleteSecretRequest> deleteSecretValidator,
|
||||
IBlueprintServiceClient keyVaultDALService)
|
||||
{
|
||||
_port = port ?? throw new ArgumentNullException(nameof(port));
|
||||
_createSecretValidator = createSecretValidator ?? throw new ArgumentNullException(nameof(createSecretValidator));
|
||||
_getSecretValidator = getSecretValidator ?? throw new ArgumentNullException(nameof(getSecretValidator));
|
||||
_updateSecretValidator = updateSecretValidator ?? throw new ArgumentNullException(nameof(updateSecretValidator));
|
||||
_deleteSecretValidator = deleteSecretValidator ?? throw new ArgumentNullException(nameof(deleteSecretValidator));
|
||||
_keyVaultDALService = keyVaultDALService ?? throw new ArgumentNullException(nameof(keyVaultDALService));
|
||||
}
|
||||
|
||||
public async ValueTask ExecuteAsync(CreateSecretRequest command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(command);
|
||||
|
||||
if (!command.IsValid(_createSecretValidator))
|
||||
{
|
||||
_port.ValidationErrors(command.Notifications);
|
||||
return;
|
||||
}
|
||||
|
||||
var request = new KeyVaultRequest
|
||||
{
|
||||
Name = command.Name,
|
||||
Value = command.Value,
|
||||
};
|
||||
|
||||
var result = await _keyVaultDALService.CreateSecretAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
_port.NoContentSuccess();
|
||||
return;
|
||||
}
|
||||
|
||||
_port.Success(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ApiResponseHelper.EvaluatePort(ex, _port);
|
||||
}
|
||||
}
|
||||
|
||||
public async ValueTask ExecuteAsync(GetSecretRequest command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(command);
|
||||
|
||||
var result = await _keyVaultDALService.GetSecretByNameAsync(command.Name, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
_port.NoContentSuccess();
|
||||
return;
|
||||
}
|
||||
|
||||
_port.Success(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ApiResponseHelper.EvaluatePort(ex, _port);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async ValueTask ExecuteAsync(UpdateSecretRequest command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(command);
|
||||
|
||||
if (!command.IsValid(_updateSecretValidator))
|
||||
{
|
||||
_port.ValidationErrors(command.Notifications);
|
||||
return;
|
||||
}
|
||||
|
||||
var request = new KeyVaultRequest
|
||||
{
|
||||
Name = command.Name,
|
||||
Value = command.Value,
|
||||
};
|
||||
|
||||
var result = await _keyVaultDALService.UpdateSecretAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
_port.NoContentSuccess();
|
||||
return;
|
||||
}
|
||||
|
||||
_port.Success(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ApiResponseHelper.EvaluatePort(ex, _port);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async ValueTask ExecuteAsync(DeleteSecretRequest command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(command);
|
||||
|
||||
if (!command.IsValid(_deleteSecretValidator))
|
||||
{
|
||||
_port.ValidationErrors(command.Notifications);
|
||||
return;
|
||||
}
|
||||
|
||||
var result = await _keyVaultDALService.DeleteSecretAsync(command.Name, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
_port.NoContentSuccess();
|
||||
return;
|
||||
}
|
||||
|
||||
_port.Success(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ApiResponseHelper.EvaluatePort(ex, _port);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using Core.Blueprint.KeyVault;
|
||||
using Core.Blueprint.Service.External.Clients.Adapters;
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
|
||||
namespace Core.Blueprint.Application.UsesCases.KeyVault.Ports
|
||||
{
|
||||
public interface IKeyVaultPort : IBasePort,
|
||||
ICommandSuccessPort<KeyVaultResponse>,
|
||||
ICommandSuccessPort<KeyVaultAdapter>,
|
||||
INoContentPort, IBusinessErrorPort, ITimeoutPort, IValidationErrorPort,
|
||||
INotFoundPort, IForbiddenPort, IUnauthorizedPort, IInternalServerErrorPort,
|
||||
IBadRequestPort
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Core.Blueprint.Application.UsesCases.KeyVault.Input;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Core.Cerberos.Application.UseCases.KeyVault.Validator
|
||||
{
|
||||
public class CreateSecretValidator : AbstractValidator<CreateSecretRequest>
|
||||
{
|
||||
public CreateSecretValidator()
|
||||
{
|
||||
RuleFor(i => i.Name).NotEmpty().NotNull().OverridePropertyName(x => x.Name).WithName("Secret Name").WithMessage("Secret Name is Obligatory.");
|
||||
RuleFor(i => i.Value).NotEmpty().NotNull().OverridePropertyName(x => x.Value).WithName("Secret Name").WithMessage("Secret Value is Obligatory.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Core.Blueprint.Application.UsesCases.KeyVault.Input;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Core.Cerberos.Application.UseCases.KeyVault.Validator
|
||||
{
|
||||
public class DeleteSecretValidator : AbstractValidator<DeleteSecretRequest>
|
||||
{
|
||||
public DeleteSecretValidator()
|
||||
{
|
||||
RuleFor(i => i.Name).NotEmpty().NotNull().OverridePropertyName(x => x.Name).WithName("Secret Name").WithMessage("Secret Name is Obligatory.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Core.Blueprint.Application.UsesCases.KeyVault.Input;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Core.Cerberos.Application.UseCases.KeyVault.Validator
|
||||
{
|
||||
public class GetSecretValidator : AbstractValidator<GetSecretRequest>
|
||||
{
|
||||
public GetSecretValidator()
|
||||
{
|
||||
RuleFor(i => i.Name).NotEmpty().NotNull().OverridePropertyName(x => x.Name).WithName("Secret Name").WithMessage("Secret Name is Obligatory.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Core.Blueprint.Application.UsesCases.KeyVault.Input;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Core.Cerberos.Application.UseCases.KeyVault.Validator
|
||||
{
|
||||
public class UpdateSecretValidator : AbstractValidator<UpdateSecretRequest>
|
||||
{
|
||||
public UpdateSecretValidator()
|
||||
{
|
||||
RuleFor(i => i.Name).NotEmpty().NotNull().OverridePropertyName(x => x.Name).WithName("Secret Name").WithMessage("Secret Name is Obligatory.");
|
||||
RuleFor(i => i.Value).NotEmpty().NotNull().OverridePropertyName(x => x.Value).WithName("Secret Value").WithMessage("Secret Value is Obligatory.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
19
Core.Blueprint.Application/UsesCases/SQL/Adapter/SQLPort.cs
Normal file
19
Core.Blueprint.Application/UsesCases/SQL/Adapter/SQLPort.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Core.Blueprint.Application.UsesCases.SQL.Ports;
|
||||
using Core.Blueprint.Service.External.Clients.Adapters;
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Core.Blueprint.Application.UsesCases.SQL.Adapter
|
||||
{
|
||||
public class SQLPort : BasePresenter, ISQLPort
|
||||
{
|
||||
public void Success(UserProjectAdapter output)
|
||||
{
|
||||
ViewModel = new OkObjectResult(output);
|
||||
}
|
||||
public void Success(List<UserProjectAdapter> output)
|
||||
{
|
||||
ViewModel = new OkObjectResult(output);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
|
||||
namespace Core.Blueprint.Application.UsesCases.SQL.Input
|
||||
{
|
||||
public class CreateUserProjectRequest : Notificator, ICommand
|
||||
{
|
||||
public string ProjectCode { get; set; } = null!;
|
||||
public string ProjectDescription { get; set; } = null!;
|
||||
public string UserId { get; set; } = null!;
|
||||
|
||||
public bool Validate()
|
||||
{
|
||||
return ProjectCode != null && ProjectCode != string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
|
||||
namespace Core.Blueprint.Application.UsesCases.SQL.Input
|
||||
{
|
||||
public class DeleteUserProjectRequest : Notificator, ICommand
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public bool Validate()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
|
||||
namespace Core.Blueprint.Application.UsesCases.SQL.Input
|
||||
{
|
||||
public class GetAllUserProjectsRequest : Notificator, ICommand
|
||||
{
|
||||
public bool Validate()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
|
||||
namespace Core.Blueprint.Application.UsesCases.SQL.Input
|
||||
{
|
||||
public class GetUserProjectRequest : Notificator, ICommand
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public bool Validate()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using Core.Blueprint.Service.External.Clients.Adapters;
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
|
||||
namespace Core.Blueprint.Application.UsesCases.SQL.Input
|
||||
{
|
||||
public class UpdateUserProjectRequest : Notificator, ICommand
|
||||
{
|
||||
public string ProjectCode { get; set; } = null!;
|
||||
public string ProjectDescription { get; set; } = null!;
|
||||
public string UserId { get; set; } = null!;
|
||||
public int Id { get; set; }
|
||||
public string Guid { get; set; } = 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 Guid != null && Guid != string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
14
Core.Blueprint.Application/UsesCases/SQL/Ports/ISQLPort.cs
Normal file
14
Core.Blueprint.Application/UsesCases/SQL/Ports/ISQLPort.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Core.Blueprint.Service.External.Clients.Adapters;
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
|
||||
namespace Core.Blueprint.Application.UsesCases.SQL.Ports
|
||||
{
|
||||
public interface ISQLPort : IBasePort,
|
||||
ICommandSuccessPort<UserProjectAdapter>,
|
||||
ICommandSuccessPort<List<UserProjectAdapter>>,
|
||||
INoContentPort, IBusinessErrorPort, ITimeoutPort, IValidationErrorPort,
|
||||
INotFoundPort, IForbiddenPort, IUnauthorizedPort, IInternalServerErrorPort,
|
||||
IBadRequestPort
|
||||
{
|
||||
}
|
||||
}
|
||||
193
Core.Blueprint.Application/UsesCases/SQL/SQLHandler.cs
Normal file
193
Core.Blueprint.Application/UsesCases/SQL/SQLHandler.cs
Normal file
@@ -0,0 +1,193 @@
|
||||
using Core.Blueprint.Application.UsesCases.SQL.Input;
|
||||
using Core.Blueprint.Application.UsesCases.SQL.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.UserProjects
|
||||
{
|
||||
public class SQLHandler :
|
||||
IComponentHandler<CreateUserProjectRequest>,
|
||||
IComponentHandler<GetUserProjectRequest>,
|
||||
IComponentHandler<GetAllUserProjectsRequest>,
|
||||
IComponentHandler<UpdateUserProjectRequest>,
|
||||
IComponentHandler<DeleteUserProjectRequest>
|
||||
{
|
||||
private readonly ISQLPort _port;
|
||||
private readonly IValidator<CreateUserProjectRequest> _createUserProjectValidator;
|
||||
private readonly IValidator<GetUserProjectRequest> _getUserProjectValidator;
|
||||
private readonly IValidator<UpdateUserProjectRequest> _updateUserProjectValidator;
|
||||
private readonly IValidator<DeleteUserProjectRequest> _deleteUserProjectValidator;
|
||||
private readonly IBlueprintServiceClient _SQLDALService;
|
||||
|
||||
public SQLHandler(
|
||||
ISQLPort port,
|
||||
IValidator<CreateUserProjectRequest> createUserProjectValidator,
|
||||
IValidator<GetUserProjectRequest> getUserProjectValidator,
|
||||
IValidator<UpdateUserProjectRequest> updateUserProjectValidator,
|
||||
IValidator<DeleteUserProjectRequest> deleteUserProjectValidator,
|
||||
IBlueprintServiceClient SQLDALService)
|
||||
{
|
||||
_port = port ?? throw new ArgumentNullException(nameof(port));
|
||||
_createUserProjectValidator = createUserProjectValidator ?? throw new ArgumentNullException(nameof(createUserProjectValidator));
|
||||
_getUserProjectValidator = getUserProjectValidator ?? throw new ArgumentNullException(nameof(getUserProjectValidator));
|
||||
_updateUserProjectValidator = updateUserProjectValidator ?? throw new ArgumentNullException(nameof(updateUserProjectValidator));
|
||||
_deleteUserProjectValidator = deleteUserProjectValidator ?? throw new ArgumentNullException(nameof(deleteUserProjectValidator));
|
||||
_SQLDALService = SQLDALService ?? throw new ArgumentNullException(nameof(SQLDALService));
|
||||
}
|
||||
|
||||
public async ValueTask ExecuteAsync(CreateUserProjectRequest command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(command);
|
||||
|
||||
if (!command.IsValid(_createUserProjectValidator))
|
||||
{
|
||||
_port.ValidationErrors(command.Notifications);
|
||||
return;
|
||||
}
|
||||
|
||||
var request = new UserProjectRequest
|
||||
{
|
||||
ProjectCode = command.ProjectCode,
|
||||
ProjectDescription = command.ProjectDescription,
|
||||
UserId = command.UserId,
|
||||
};
|
||||
|
||||
var result = await _SQLDALService.CreateUserProjectAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
_port.NoContentSuccess();
|
||||
return;
|
||||
}
|
||||
|
||||
_port.Success(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ApiResponseHelper.EvaluatePort(ex, _port);
|
||||
}
|
||||
}
|
||||
|
||||
public async ValueTask ExecuteAsync(GetAllUserProjectsRequest command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(command);
|
||||
|
||||
var _result = await _SQLDALService.GetAllUserProjectsAsync().ConfigureAwait(false);
|
||||
if (!_result.Any())
|
||||
{
|
||||
_port.NoContentSuccess();
|
||||
return;
|
||||
}
|
||||
_port.Success(_result.ToList());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ApiResponseHelper.EvaluatePort(ex, _port);
|
||||
}
|
||||
}
|
||||
|
||||
public async ValueTask ExecuteAsync(GetUserProjectRequest command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(command);
|
||||
|
||||
var result = await _SQLDALService.GetUserProjectByIdAsync(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(UpdateUserProjectRequest command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(command);
|
||||
|
||||
if (!command.IsValid(_updateUserProjectValidator))
|
||||
{
|
||||
_port.ValidationErrors(command.Notifications);
|
||||
return;
|
||||
}
|
||||
|
||||
var request = new UserProjectAdapter
|
||||
{
|
||||
Id = command.Id,
|
||||
Guid = command.Guid,
|
||||
UserId = command.UserId,
|
||||
ProjectCode = command.ProjectCode,
|
||||
ProjectDescription = command.ProjectDescription,
|
||||
CreatedAt = command.CreatedAt,
|
||||
CreatedBy = command.CreatedBy,
|
||||
UpdatedAt = command.UpdatedAt,
|
||||
UpdatedBy = command.UpdatedBy,
|
||||
Status = command.Status
|
||||
};
|
||||
|
||||
int id = command.Id;
|
||||
|
||||
var result = await _SQLDALService.UpdateUserProjectAsync(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(DeleteUserProjectRequest command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(command);
|
||||
|
||||
if (!command.IsValid(_deleteUserProjectValidator))
|
||||
{
|
||||
_port.ValidationErrors(command.Notifications);
|
||||
return;
|
||||
}
|
||||
|
||||
var result = await _SQLDALService.DeleteUserProjectAsync(command.Id, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
_port.NoContentSuccess();
|
||||
return;
|
||||
}
|
||||
|
||||
_port.Success(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ApiResponseHelper.EvaluatePort(ex, _port);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using Core.Blueprint.Application.UsesCases.SQL.Input;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Core.Cerberos.Application.UseCases.SQL.Validator
|
||||
{
|
||||
public class CreateUserProjectValidator : AbstractValidator<CreateUserProjectRequest>
|
||||
{
|
||||
public CreateUserProjectValidator()
|
||||
{
|
||||
RuleFor(i => i.ProjectCode).NotEmpty().NotNull().OverridePropertyName(x => x.ProjectCode).WithName("Project Code").WithMessage("Project Code is Obligatory.");
|
||||
RuleFor(i => i.ProjectDescription).NotEmpty().NotNull().OverridePropertyName(x => x.ProjectDescription).WithName("Project Description").WithMessage("Project Description is Obligatory.");
|
||||
RuleFor(i => i.UserId).NotEmpty().NotNull().OverridePropertyName(x => x.UserId).WithName("User Identifier").WithMessage("User Identifier is Obligatory.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Core.Blueprint.Application.UsesCases.SQL.Input;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Core.Cerberos.Application.UseCases.SQL.Validator
|
||||
{
|
||||
public class DeleteUserProjectValidator : AbstractValidator<DeleteUserProjectRequest>
|
||||
{
|
||||
public DeleteUserProjectValidator()
|
||||
{
|
||||
RuleFor(i => i.Id).NotEmpty().NotNull().OverridePropertyName(x => x.Id).WithName("User Project Identifier").WithMessage("User Project Identifier is Obligatory.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Core.Blueprint.Application.UsesCases.SQL.Input;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Core.Cerberos.Application.UseCases.SQL.Validator
|
||||
{
|
||||
public class GetUserProjectValidator : AbstractValidator<GetUserProjectRequest>
|
||||
{
|
||||
public GetUserProjectValidator()
|
||||
{
|
||||
RuleFor(i => i.Id).NotEmpty().NotNull().OverridePropertyName(x => x.Id).WithName("User Project Identifier").WithMessage("User Project Identifier is Obligatory.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using Core.Blueprint.Application.UsesCases.SQL.Input;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Core.Cerberos.Application.UseCases.SQL.Validator
|
||||
{
|
||||
public class UpdateUserProjectValidator : AbstractValidator<UpdateUserProjectRequest>
|
||||
{
|
||||
public UpdateUserProjectValidator()
|
||||
{
|
||||
RuleFor(i => i.Id).NotEmpty().NotNull().OverridePropertyName(x => x.Id).WithName("UserProject Identifier").WithMessage("UserPoject Identifier is Obligatory.");
|
||||
RuleFor(i => i.Guid).NotEmpty().NotNull().OverridePropertyName(x => x.Guid).WithName("UserProject GUID").WithMessage("UserProject GUID is Obligatory.");
|
||||
RuleFor(i => i.ProjectCode).NotEmpty().NotNull().OverridePropertyName(x => x.ProjectCode).WithName("Project Code").WithMessage("Project Code is Obligatory.");
|
||||
RuleFor(i => i.ProjectDescription).NotEmpty().NotNull().OverridePropertyName(x => x.ProjectDescription).WithName("Project Description").WithMessage("Project Description is Obligatory.");
|
||||
RuleFor(i => i.UserId).NotEmpty().NotNull().OverridePropertyName(x => x.UserId).WithName("User Identifier").WithMessage("User Identifier is Obligatory.");
|
||||
RuleFor(i => i.Status).NotNull().OverridePropertyName(x => x.Status).WithName("UserProject Status").WithMessage("UserProject Status is Obligatory.");
|
||||
RuleFor(i => i.CreatedAt).NotNull().OverridePropertyName(x => x.CreatedAt).WithName("UserProject CreatedAt").WithMessage("UserProject CreatedAt is Obligatory.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user