Re-factor on service

This commit is contained in:
2025-06-22 23:16:10 -06:00
parent e99b2c5a5a
commit f76e318f92
26 changed files with 178 additions and 86 deletions

View File

@@ -7,19 +7,19 @@
using Core.Blueprint.Mongo;
using Lib.Architecture.BuildingBlocks;
namespace Core.Inventory.Application.UseCases.Inventory.Input
namespace Core.Inventory.Application.UseCases.Inventory.Input.Base
{
/// <summary>
/// Command to change the status of a furniture base model.
/// </summary>
public class ChangeFurnitureBaseStatusRequest : Notificator, ICommand
{
public string Id { get; set; } = null!;
public string MongoId { get; set; } = null!;
public StatusEnum Status { get; set; }
public bool Validate()
{
return !string.IsNullOrWhiteSpace(Id);
return !string.IsNullOrWhiteSpace(MongoId);
}
}
}

View File

@@ -6,7 +6,7 @@
using Core.Inventory.Application.UseCases.Inventory.Input.Common;
using Lib.Architecture.BuildingBlocks;
namespace Core.Inventory.Application.UseCases.Inventory.Input
namespace Core.Inventory.Application.UseCases.Inventory.Input.Base
{
/// <summary>
/// Command for creating a new furniture base entity.

View File

@@ -5,7 +5,7 @@
// ***********************************************************************
using Lib.Architecture.BuildingBlocks;
namespace Core.Inventory.Application.UseCases.Inventory.Input
namespace Core.Inventory.Application.UseCases.Inventory.Input.Base
{
public class GetAllFurnitureBaseRequest : ICommand
{

View File

@@ -5,18 +5,18 @@
// ***********************************************************************
using Lib.Architecture.BuildingBlocks;
namespace Core.Inventory.Application.UseCases.Inventory.Input
namespace Core.Inventory.Application.UseCases.Inventory.Input.Base
{
/// <summary>
/// Query to retrieve a furniture base by its identifier.
/// </summary>
public class GetFurnitureBaseByIdRequest : Notificator, ICommand
{
public string Id { get; set; } = null!;
public string MongoId { get; set; } = null!;
public bool Validate()
{
return !string.IsNullOrWhiteSpace(Id);
return !string.IsNullOrWhiteSpace(MongoId);
}
}
}

View File

@@ -6,7 +6,7 @@
using Core.Inventory.Application.UseCases.Inventory.Input.Common;
using Lib.Architecture.BuildingBlocks;
namespace Core.Inventory.Application.UseCases.Inventory.Input
namespace Core.Inventory.Application.UseCases.Inventory.Input.Base
{
/// <summary>
/// Command for updating an existing furniture base entity.

View File

@@ -6,19 +6,19 @@
using Core.Blueprint.Mongo;
using Lib.Architecture.BuildingBlocks;
namespace Core.Inventory.Application.UseCases.Inventory.Input
namespace Core.Inventory.Application.UseCases.Inventory.Input.Variant
{
/// <summary>
/// Command to change the status of a furniture variant.
/// </summary>
public class ChangeFurnitureVariantStatusRequest : Notificator, ICommand
{
public string Id { get; set; } = null!;
public string MongoId { get; set; } = null!;
public StatusEnum Status { get; set; }
public bool Validate()
{
return !string.IsNullOrWhiteSpace(Id);
return !string.IsNullOrWhiteSpace(MongoId);
}
}
}

View File

@@ -5,7 +5,7 @@
// ***********************************************************************
using Lib.Architecture.BuildingBlocks;
namespace Core.Inventory.Application.UseCases.Inventory.Input
namespace Core.Inventory.Application.UseCases.Inventory.Input.Variant
{
public class CreateFurnitureVariantRequest : Notificator, ICommand
{

View File

@@ -5,7 +5,7 @@
// ***********************************************************************
using Lib.Architecture.BuildingBlocks;
namespace Core.Inventory.Application.UseCases.Inventory.Input
namespace Core.Inventory.Application.UseCases.Inventory.Input.Variant
{
public class GetAllFurnitureVariantsByModelIdRequest : Notificator, ICommand
{

View File

@@ -5,15 +5,15 @@
// ***********************************************************************
using Lib.Architecture.BuildingBlocks;
namespace Core.Inventory.Application.UseCases.Inventory.Input
namespace Core.Inventory.Application.UseCases.Inventory.Input.Variant
{
public class GetFurnitureVariantByIdRequest : Notificator, ICommand
{
public string Id { get; set; } = null!;
public string MongoId { get; set; } = null!;
public bool Validate()
{
return !string.IsNullOrWhiteSpace(Id);
return !string.IsNullOrWhiteSpace(MongoId);
}
}
}

View File

@@ -0,0 +1,22 @@
// ***********************************************************************
// <copyright file="GetVariantsByIdsRequest.cs">
// Core.Inventory
// </copyright>
// ***********************************************************************
using Lib.Architecture.BuildingBlocks;
namespace Core.Inventory.Application.UseCases.Inventory.Input.Variant
{
/// <summary>
/// Request to retrieve multiple furniture variants by their identifiers.
/// </summary>
public class GetFurnitureVariantsByIdsRequest : Notificator, ICommand
{
public string[] Ids { get; set; } = [];
public bool Validate()
{
return Ids is not null && Ids.Length > 0 && Ids.All(id => !string.IsNullOrWhiteSpace(id));
}
}
}

View File

@@ -6,7 +6,7 @@
using Lib.Architecture.BuildingBlocks;
namespace Core.Inventory.Application.UseCases.Inventory.Input
namespace Core.Inventory.Application.UseCases.Inventory.Input.Variant
{
/// <summary>
/// Command for updating an existing furniture variant.

View File

@@ -1,5 +1,7 @@
using Core.Inventory.Application.UseCases.Inventory.Input;
using Core.Inventory.Application.UseCases.Inventory.Input.Base;
using Core.Inventory.Application.UseCases.Inventory.Input.Variant;
using Core.Inventory.Application.UseCases.Inventory.Ports;
using Core.Inventory.Application.UseCases.Inventory.Validator.Variant;
using Core.Inventory.External.Clients;
using Core.Inventory.External.Clients.Requests;
using FluentValidation;
@@ -20,7 +22,8 @@ namespace Core.Inventory.Application.UseCases.Inventory
IComponentHandler<UpdateFurnitureVariantRequest>,
IComponentHandler<GetFurnitureVariantByIdRequest>,
IComponentHandler<GetAllFurnitureVariantsByModelIdRequest>,
IComponentHandler<ChangeFurnitureVariantStatusRequest>
IComponentHandler<ChangeFurnitureVariantStatusRequest>,
IComponentHandler<GetFurnitureVariantsByIdsRequest>
{
// FurnitureBase
private readonly IFurnitureBasePort _basePort;
@@ -161,7 +164,7 @@ namespace Core.Inventory.Application.UseCases.Inventory
try
{
ArgumentNullException.ThrowIfNull(command);
var result = await _inventoryDALService.GetFurnitureBaseByIdAsync(command.Id, cancellationToken);
var result = await _inventoryDALService.GetFurnitureBaseByIdAsync(command.MongoId, cancellationToken);
if (result is null)
{
_basePort.NoContentSuccess();
@@ -186,7 +189,7 @@ namespace Core.Inventory.Application.UseCases.Inventory
return;
}
var result = await _inventoryDALService.ChangeFurnitureBaseStatusAsync(command.Id, command.Status, cancellationToken);
var result = await _inventoryDALService.ChangeFurnitureBaseStatusAsync(command.MongoId, command.Status, cancellationToken);
_basePort.Success(result);
}
catch (Exception ex)
@@ -267,7 +270,7 @@ namespace Core.Inventory.Application.UseCases.Inventory
try
{
ArgumentNullException.ThrowIfNull(command);
var result = await _inventoryDALService.GetFurnitureVariantByIdAsync(command.Id, cancellationToken);
var result = await _inventoryDALService.GetFurnitureVariantByIdAsync(command.MongoId, cancellationToken);
if (result is null)
{
_variantPort.NoContentSuccess();
@@ -300,6 +303,34 @@ namespace Core.Inventory.Application.UseCases.Inventory
}
}
public async ValueTask ExecuteAsync(GetFurnitureVariantsByIdsRequest command, CancellationToken cancellationToken = default)
{
try
{
ArgumentNullException.ThrowIfNull(command);
if (!command.IsValid(new GetFurnitureVariantsByIdsValidator()))
{
_variantPort.ValidationErrors(command.Notifications);
return;
}
var result = await _inventoryDALService.GetFurnitureVariantsByIdsAsync(command.Ids.ToArray());
if (result is null || !result.Any())
{
_variantPort.NoContentSuccess();
return;
}
_variantPort.Success([.. result]);
}
catch (Exception ex)
{
ApiResponseHelper.EvaluatePort(ex, _variantPort);
}
}
public async ValueTask ExecuteAsync(ChangeFurnitureVariantStatusRequest command, CancellationToken cancellationToken = default)
{
try
@@ -310,7 +341,7 @@ namespace Core.Inventory.Application.UseCases.Inventory
_variantPort.ValidationErrors(command.Notifications);
return;
}
var result = await _inventoryDALService.ChangeFurnitureVariantStatusAsync(command.Id, command.Status, cancellationToken);
var result = await _inventoryDALService.ChangeFurnitureVariantStatusAsync(command.MongoId, command.Status, cancellationToken);
_variantPort.Success(result);
}
catch (Exception ex)

View File

@@ -1,13 +1,13 @@
using Core.Inventory.Application.UseCases.Inventory.Input;
using Core.Inventory.Application.UseCases.Inventory.Input.Base;
using FluentValidation;
namespace Core.Inventory.Application.UseCases.Inventory.Validator
namespace Core.Inventory.Application.UseCases.Inventory.Validator.Base
{
public class ChangeFurnitureBaseStatusValidator : AbstractValidator<ChangeFurnitureBaseStatusRequest>
{
public ChangeFurnitureBaseStatusValidator()
{
RuleFor(x => x.Id)
RuleFor(x => x.MongoId)
.NotEmpty().WithMessage("Id is required.");
RuleFor(x => x.Status)

View File

@@ -3,11 +3,11 @@
// Core.Inventory
// </copyright>
// ***********************************************************************
using Core.Inventory.Application.UseCases.Inventory.Input;
using Core.Inventory.Application.UseCases.Inventory.Input.Base;
using Core.Inventory.Application.UseCases.Inventory.Validator.Common;
using FluentValidation;
namespace Core.Inventory.Application.UseCases.Inventory.Validator
namespace Core.Inventory.Application.UseCases.Inventory.Validator.Base
{
public class CreateFurnitureBaseValidator : AbstractValidator<CreateFurnitureBaseRequest>
{

View File

@@ -1,13 +1,13 @@
using Core.Inventory.Application.UseCases.Inventory.Input;
using Core.Inventory.Application.UseCases.Inventory.Input.Base;
using FluentValidation;
namespace Core.Inventory.Application.UseCases.Inventory.Validator
namespace Core.Inventory.Application.UseCases.Inventory.Validator.Base
{
public class GetFurnitureBaseByIdValidator : AbstractValidator<GetFurnitureBaseByIdRequest>
{
public GetFurnitureBaseByIdValidator()
{
RuleFor(x => x.Id)
RuleFor(x => x.MongoId)
.NotEmpty().WithMessage("Id is required.");
}
}

View File

@@ -1,8 +1,8 @@
using Core.Inventory.Application.UseCases.Inventory.Input;
using Core.Inventory.Application.UseCases.Inventory.Input.Base;
using Core.Inventory.Application.UseCases.Inventory.Validator.Common;
using FluentValidation;
namespace Core.Inventory.Application.UseCases.Inventory.Validator
namespace Core.Inventory.Application.UseCases.Inventory.Validator.Base
{
public class UpdateFurnitureBaseValidator : AbstractValidator<UpdateFurnitureBaseRequest>
{

View File

@@ -1,13 +1,13 @@
using Core.Inventory.Application.UseCases.Inventory.Input;
using Core.Inventory.Application.UseCases.Inventory.Input.Variant;
using FluentValidation;
namespace Core.Inventory.Application.UseCases.Inventory.Validator
namespace Core.Inventory.Application.UseCases.Inventory.Validator.Variant
{
public class ChangeFurnitureVariantStatusValidator : AbstractValidator<ChangeFurnitureVariantStatusRequest>
{
public ChangeFurnitureVariantStatusValidator()
{
RuleFor(x => x.Id)
RuleFor(x => x.MongoId)
.NotEmpty().WithMessage("Id is required.");
RuleFor(x => x.Status)

View File

@@ -1,7 +1,7 @@
using Core.Inventory.Application.UseCases.Inventory.Input;
using Core.Inventory.Application.UseCases.Inventory.Input.Variant;
using FluentValidation;
namespace Core.Inventory.Application.UseCases.Inventory.Validator
namespace Core.Inventory.Application.UseCases.Inventory.Validator.Variant
{
public class CreateFurnitureVariantValidator : AbstractValidator<CreateFurnitureVariantRequest>
{

View File

@@ -1,7 +1,7 @@
using Core.Inventory.Application.UseCases.Inventory.Input;
using Core.Inventory.Application.UseCases.Inventory.Input.Variant;
using FluentValidation;
namespace Core.Inventory.Application.UseCases.Inventory.Validator
namespace Core.Inventory.Application.UseCases.Inventory.Validator.Variant
{
public class GetAllFurnitureVariantsByModelIdValidator : AbstractValidator<GetAllFurnitureVariantsByModelIdRequest>
{

View File

@@ -1,13 +1,13 @@
using Core.Inventory.Application.UseCases.Inventory.Input;
using Core.Inventory.Application.UseCases.Inventory.Input.Variant;
using FluentValidation;
namespace Core.Inventory.Application.UseCases.Inventory.Validator
namespace Core.Inventory.Application.UseCases.Inventory.Validator.Variant
{
public class GetFurnitureVariantByIdValidator : AbstractValidator<GetFurnitureVariantByIdRequest>
{
public GetFurnitureVariantByIdValidator()
{
RuleFor(x => x.Id)
RuleFor(x => x.MongoId)
.NotEmpty().WithMessage("Id is required.");
}
}

View File

@@ -0,0 +1,27 @@
// ***********************************************************************
// <copyright file="GetVariantsByIdsValidator.cs">
// Core.Inventory
// </copyright>
// ***********************************************************************
using Core.Inventory.Application.UseCases.Inventory.Input.Variant;
using FluentValidation;
namespace Core.Inventory.Application.UseCases.Inventory.Validator.Variant
{
/// <summary>
/// Validator for <see cref="GetFurnitureVariantsByIdsRequest"/>.
/// </summary>
public class GetFurnitureVariantsByIdsValidator : AbstractValidator<GetFurnitureVariantsByIdsRequest>
{
public GetFurnitureVariantsByIdsValidator()
{
RuleFor(x => x.Ids)
.NotNull()
.WithMessage("The list of IDs must not be null.")
.Must(ids => ids.Length!=0)
.WithMessage("At least one ID must be provided.")
.Must(ids => ids.All(id => !string.IsNullOrWhiteSpace(id)))
.WithMessage("All IDs must be non-empty strings.");
}
}
}

View File

@@ -1,7 +1,7 @@
using Core.Inventory.Application.UseCases.Inventory.Input;
using Core.Inventory.Application.UseCases.Inventory.Input.Variant;
using FluentValidation;
namespace Core.Inventory.Application.UseCases.Inventory.Validator
namespace Core.Inventory.Application.UseCases.Inventory.Validator.Variant
{
public class UpdateFurnitureVariantValidator : AbstractValidator<UpdateFurnitureVariantRequest>
{