feat(infrastructure): ProductRepository + ProductQueryRepository, DI swap activates guard (PRD-002)
This commit is contained in:
@@ -69,7 +69,6 @@ using SIGCM2.Application.Rubros.GetById;
|
||||
using SIGCM2.Application.Rubros.Dtos;
|
||||
using SIGCM2.Application.Abstractions.Persistence;
|
||||
using SIGCM2.Application.Avisos;
|
||||
using SIGCM2.Application.Products;
|
||||
using SIGCM2.Application.Products.Create;
|
||||
using SIGCM2.Application.Products.Update;
|
||||
using SIGCM2.Application.Products.Deactivate;
|
||||
@@ -184,8 +183,7 @@ public static class DependencyInjection
|
||||
services.AddScoped<ICommandHandler<ListProductsQuery, PagedResult<ProductListItemDto>>, ListProductsQueryHandler>();
|
||||
|
||||
// ProductTypes (PRD-001)
|
||||
// PRD-002 reemplaza IProductQueryRepository con implementación Dapper contra dbo.Product.
|
||||
services.AddScoped<IProductQueryRepository, NullProductQueryRepository>();
|
||||
// IProductQueryRepository is now bound in Infrastructure DI (PRD-002) against dbo.Product.
|
||||
|
||||
services.AddScoped<ICommandHandler<CreateProductTypeCommand, ProductTypeCreatedDto>, CreateProductTypeCommandHandler>();
|
||||
services.AddScoped<ICommandHandler<UpdateProductTypeCommand, ProductTypeUpdatedDto>, UpdateProductTypeCommandHandler>();
|
||||
|
||||
@@ -37,12 +37,10 @@ public sealed class DeactivateProductTypeCommandHandler
|
||||
if (!target.IsActive)
|
||||
return new ProductTypeStatusDto(command.Id, false);
|
||||
|
||||
// 3. Guard: check if any active product uses this type (guard before audit — ordering matters)
|
||||
// 3. Guard: check if any active product uses this type
|
||||
var inUse = await _productQuery.ExistsActiveByProductTypeAsync(command.Id);
|
||||
if (inUse)
|
||||
throw new ProductTypeEnUsoException(command.Id, productsActivos: -1);
|
||||
// Note: count=-1 sentinel because Products table doesn't exist in PRD-001.
|
||||
// PRD-002 will update this with the actual count.
|
||||
throw new ProductTypeEnUsoException(command.Id, productsActivos: 1);
|
||||
|
||||
// 4. Deactivate (immutable — returns new instance)
|
||||
var deactivated = target.WithDeactivated(_timeProvider);
|
||||
|
||||
Reference in New Issue
Block a user