Add TagOverride CRUD

This commit is contained in:
Oscar Morales
2025-08-05 12:31:51 -06:00
parent a63a351b84
commit 85e186396d
18 changed files with 635 additions and 5 deletions

View File

@@ -0,0 +1,19 @@
using Core.Adapters.Lib;
using Core.Inventory.Application.UseCases.TagOverride.Ports;
using Lib.Architecture.BuildingBlocks;
using Microsoft.AspNetCore.Mvc;
namespace Core.Inventory.Application.UseCases.TagOverride.Adapter
{
public class TagOverridePort : BasePresenter, ITagOverridePort
{
public void Success(TagOverrideAdapter output)
{
ViewModel = new OkObjectResult(output);
}
public void Success(List<TagOverrideAdapter> output)
{
ViewModel = new OkObjectResult(output);
}
}
}

View File

@@ -0,0 +1,16 @@
using Core.Blueprint.Mongo;
using Lib.Architecture.BuildingBlocks;
namespace Core.Inventory.Application.UseCases.TagOverride.Input
{
public class ChangeTagOverrideStatusRequest : Notificator, ICommand
{
public string Id { get; set; }
public StatusEnum Status { get; set; }
public bool Validate()
{
return Id != null;
}
}
}

View File

@@ -0,0 +1,16 @@
using Lib.Architecture.BuildingBlocks;
namespace Core.Inventory.Application.UseCases.TagOverride.Input
{
public class CreateTagOverrideRequest : Notificator, ICommand
{
public string TenantId { get; set; } = null!;
public string BaseTagId { get; set; } = null!;
public string OverrideTagId { get; set; } = null!;
public bool Validate()
{
return BaseTagId != null;
}
}
}

View File

@@ -0,0 +1,14 @@
using Lib.Architecture.BuildingBlocks;
namespace Core.Inventory.Application.UseCases.TagOverride.Input
{
public class GetAllTagOverridesByListRequest : Notificator, ICommand
{
public string[] TagOverrides { get; set; }
public bool Validate()
{
return TagOverrides != null;
}
}
}

View File

@@ -0,0 +1,12 @@
using Lib.Architecture.BuildingBlocks;
namespace Core.Inventory.Application.UseCases.TagOverride.Input
{
public class GetAllTagOverridesRequest : ICommand
{
public bool Validate()
{
return true;
}
}
}

View File

@@ -0,0 +1,13 @@
using Lib.Architecture.BuildingBlocks;
namespace Core.Inventory.Application.UseCases.TagOverride.Input
{
public class GetTagOverrideRequest : Notificator, ICommand
{
public string Id { get; set; }
public bool Validate()
{
return Id != null;
}
}
}

View File

@@ -0,0 +1,16 @@
using Lib.Architecture.BuildingBlocks;
namespace Core.Inventory.Application.UseCases.TagOverride.Input
{
public class UpdateTagOverrideRequest : Notificator, ICommand
{
public string Id { get; set; } = null!;
public string TenantId { get; set; } = null!;
public string BaseTagId { get; set; } = null!;
public string OverrideTagId { get; set; } = null!;
public bool Validate()
{
return Id != null;
}
}
}

View File

@@ -0,0 +1,14 @@
using Core.Adapters.Lib;
using Lib.Architecture.BuildingBlocks;
namespace Core.Inventory.Application.UseCases.TagOverride.Ports
{
public interface ITagOverridePort : IBasePort,
ICommandSuccessPort<TagOverrideAdapter>,
ICommandSuccessPort<List<TagOverrideAdapter>>,
INoContentPort, IBusinessErrorPort, ITimeoutPort, IValidationErrorPort,
INotFoundPort, IForbiddenPort, IUnauthorizedPort, IInternalServerErrorPort,
IBadRequestPort
{
}
}

View File

@@ -0,0 +1,212 @@
using Core.Adapters.Lib;
using Core.Inventory.Application.UseCases.TagOverride.Input;
using Core.Inventory.Application.UseCases.TagOverride.Ports;
using Core.Inventory.External.Clients;
using Core.Inventory.External.Clients.Requests;
using FluentValidation;
using Lib.Architecture.BuildingBlocks;
using Lib.Architecture.BuildingBlocks.Helpers;
namespace Core.Inventory.Application.UseCases.TagOverride
{
public class TagOverrideHandler :
IComponentHandler<ChangeTagOverrideStatusRequest>,
IComponentHandler<GetAllTagOverridesRequest>,
IComponentHandler<GetAllTagOverridesByListRequest>,
IComponentHandler<UpdateTagOverrideRequest>,
IComponentHandler<GetTagOverrideRequest>,
IComponentHandler<CreateTagOverrideRequest>
{
private readonly ITagOverridePort _port;
private readonly IValidator<ChangeTagOverrideStatusRequest> _changeTagOverrideStatusValidator;
private readonly IValidator<CreateTagOverrideRequest> _registerTagOverrideValidator;
private readonly IValidator<UpdateTagOverrideRequest> _updateTagOverrideValidator;
private readonly IValidator<GetAllTagOverridesByListRequest> _TagOverridesByListValidator;
private readonly IInventoryServiceClient _inventoryServiceClient;
public TagOverrideHandler(
ITagOverridePort port,
IValidator<ChangeTagOverrideStatusRequest> changeTagOverrideStatusValidator,
IValidator<CreateTagOverrideRequest> registerTagOverrideValidator,
IValidator<UpdateTagOverrideRequest> updateTagOverrideValidator,
IValidator<GetAllTagOverridesByListRequest> TagOverridesByListValidator,
IInventoryServiceClient inventoryDALService)
{
_port = port ?? throw new ArgumentNullException(nameof(port));
_changeTagOverrideStatusValidator = changeTagOverrideStatusValidator ?? throw new ArgumentNullException(nameof(changeTagOverrideStatusValidator));
_registerTagOverrideValidator = registerTagOverrideValidator ?? throw new ArgumentNullException(nameof(registerTagOverrideValidator));
_updateTagOverrideValidator = updateTagOverrideValidator ?? throw new ArgumentNullException(nameof(updateTagOverrideValidator));
_inventoryServiceClient = inventoryDALService ?? throw new ArgumentNullException(nameof(inventoryDALService));
_TagOverridesByListValidator = TagOverridesByListValidator ?? throw new ArgumentNullException(nameof(TagOverridesByListValidator));
}
public async ValueTask ExecuteAsync(GetTagOverrideRequest command, CancellationToken cancellationToken = default)
{
try
{
ArgumentNullException.ThrowIfNull(command);
var result = await _inventoryServiceClient.GetTagOverrideByIdAsync(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(GetAllTagOverridesRequest command, CancellationToken cancellationToken = default)
{
try
{
ArgumentNullException.ThrowIfNull(command);
var _result = await _inventoryServiceClient.GetAllTagOverridesAsync().ConfigureAwait(false);
if (!_result.Any())
{
_port.NoContentSuccess();
return;
}
_port.Success(_result.ToList());
}
catch (Exception ex)
{
ApiResponseHelper.EvaluatePort(ex, _port);
}
}
public async ValueTask ExecuteAsync(GetAllTagOverridesByListRequest command, CancellationToken cancellationToken = default)
{
try
{
ArgumentNullException.ThrowIfNull(command);
if (!command.IsValid(_TagOverridesByListValidator))
{
_port.ValidationErrors(command.Notifications);
return;
}
var _result = await _inventoryServiceClient.GetAllTagOverridesByListAsync(command.TagOverrides, cancellationToken).ConfigureAwait(false);
if (!_result.Any())
{
_port.NoContentSuccess();
return;
}
_port.Success(_result.ToList());
}
catch (Exception ex)
{
ApiResponseHelper.EvaluatePort(ex, _port);
}
}
public async ValueTask ExecuteAsync(ChangeTagOverrideStatusRequest command, CancellationToken cancellationToken = default)
{
try
{
ArgumentNullException.ThrowIfNull(command);
if (!command.IsValid(_changeTagOverrideStatusValidator))
{
_port.ValidationErrors(command.Notifications);
return;
}
var result = await _inventoryServiceClient.ChangeStatusTagOverrideAsync(command.Id, command.Status, cancellationToken).ConfigureAwait(false);
if (result == null)
{
_port.NoContentSuccess();
return;
}
_port.Success(result);
}
catch (Exception ex)
{
ApiResponseHelper.EvaluatePort(ex, _port);
}
}
public async ValueTask ExecuteAsync(CreateTagOverrideRequest command, CancellationToken cancellationToken = default)
{
try
{
ArgumentNullException.ThrowIfNull(command);
if (!command.IsValid(_registerTagOverrideValidator))
{
_port.ValidationErrors(command.Notifications);
return;
}
var request = new TagOverrideRequest
{
TenantId = command.TenantId,
BaseTagId = command.BaseTagId,
OverrideTagId = command.OverrideTagId,
};
var result = await _inventoryServiceClient.CreateTagOverrideAsync(request, cancellationToken).ConfigureAwait(false);
if (result == null)
{
_port.NoContentSuccess();
return;
}
_port.Success(result);
}
catch (Exception ex)
{
ApiResponseHelper.EvaluatePort(ex, _port);
}
}
public async ValueTask ExecuteAsync(UpdateTagOverrideRequest command, CancellationToken cancellationToken = default)
{
try
{
ArgumentNullException.ThrowIfNull(command);
if (!command.IsValid(_updateTagOverrideValidator))
{
_port.ValidationErrors(command.Notifications);
return;
}
var request = new TagOverrideAdapter
{
Id = command.Id,
TenantId = command.TenantId,
BaseTagId = command.BaseTagId,
OverrideTagId = command.OverrideTagId
};
string id = command.Id;
var result = await _inventoryServiceClient.UpdateTagOverrideAsync(request, id, cancellationToken).ConfigureAwait(false);
if (result == null)
{
_port.NoContentSuccess();
return;
}
_port.Success(result);
}
catch (Exception ex)
{
ApiResponseHelper.EvaluatePort(ex, _port);
}
}
}
}

View File

@@ -0,0 +1,14 @@
using Core.Inventory.Application.UseCases.TagOverride.Input;
using FluentValidation;
namespace Core.Inventory.Application.UseCases.TagOverride.Validator
{
public class ChangeTagOverrideStatusValidator : AbstractValidator<ChangeTagOverrideStatusRequest>
{
public ChangeTagOverrideStatusValidator()
{
RuleFor(i => i.Id).NotEmpty().NotNull().OverridePropertyName(x => x.Id).WithName("TagOverride ID").WithMessage("TagOverride ID is Obligatory.");
RuleFor(i => i.Status).NotNull().OverridePropertyName(x => x.Status).WithName("Status").WithMessage("Status is Obligatory.");
}
}
}

View File

@@ -0,0 +1,14 @@
using Core.Inventory.Application.UseCases.TagOverride.Input;
using FluentValidation;
namespace Core.Inventory.Application.UseCases.TagOverride.Validator
{
public class CreateTagOverrideValidator : AbstractValidator<CreateTagOverrideRequest>
{
public CreateTagOverrideValidator()
{
RuleFor(i => i.BaseTagId).NotEmpty().NotNull().OverridePropertyName(x => x.BaseTagId).WithName("TagOverride BaseTagId").WithMessage("TagOverride BaseTagId is Obligatory.");
RuleFor(i => i.OverrideTagId).NotEmpty().NotNull().OverridePropertyName(x => x.OverrideTagId).WithName("TagOverride OverrideTagId").WithMessage("TagOverride OverrideTagId is Obligatory.");
}
}
}

View File

@@ -0,0 +1,14 @@
using Core.Inventory.Application.UseCases.TagOverride.Input;
using FluentValidation;
namespace Core.Inventory.Application.UseCases.TagOverride.Validator
{
public class GetAllTagOverridesByListValidator : AbstractValidator<GetAllTagOverridesByListRequest>
{
public GetAllTagOverridesByListValidator()
{
RuleFor(i => i.TagOverrides).NotEmpty().NotNull().OverridePropertyName(x => x.TagOverrides).WithName("TagOverrides").WithMessage("TagOverrides are Obligatory.");
}
}
}

View File

@@ -0,0 +1,14 @@
using Core.Inventory.Application.UseCases.TagOverride.Input;
using FluentValidation;
namespace Core.Inventory.Application.UseCases.TagOverride.Validator
{
public class UpdateTagOverrideValidator : AbstractValidator<UpdateTagOverrideRequest>
{
public UpdateTagOverrideValidator()
{
RuleFor(i => i.BaseTagId).NotEmpty().NotNull().OverridePropertyName(x => x.BaseTagId).WithName("TagOverride BaseTagId").WithMessage("TagOverride BaseTagId is Obligatory.");
RuleFor(i => i.OverrideTagId).NotEmpty().NotNull().OverridePropertyName(x => x.OverrideTagId).WithName("TagOverride OverrideTagId").WithMessage("TagOverride OverrideTagId is Obligatory.");
}
}
}

View File

@@ -1,9 +1,4 @@
using Lib.Architecture.BuildingBlocks;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Core.Inventory.Application.UseCases.TagType.Input
{