fix(adm-001): cascada de inactividad Medio→Seccion — Closes #16 #18
@@ -10,11 +10,13 @@ namespace SIGCM2.Application.Secciones.Deactivate;
|
|||||||
public sealed class DeactivateSeccionCommandHandler : ICommandHandler<DeactivateSeccionCommand, SeccionStatusDto>
|
public sealed class DeactivateSeccionCommandHandler : ICommandHandler<DeactivateSeccionCommand, SeccionStatusDto>
|
||||||
{
|
{
|
||||||
private readonly ISeccionRepository _repo;
|
private readonly ISeccionRepository _repo;
|
||||||
|
private readonly IMedioRepository _medioRepo;
|
||||||
private readonly IAuditLogger _audit;
|
private readonly IAuditLogger _audit;
|
||||||
|
|
||||||
public DeactivateSeccionCommandHandler(ISeccionRepository repo, IAuditLogger audit)
|
public DeactivateSeccionCommandHandler(ISeccionRepository repo, IMedioRepository medioRepo, IAuditLogger audit)
|
||||||
{
|
{
|
||||||
_repo = repo;
|
_repo = repo;
|
||||||
|
_medioRepo = medioRepo;
|
||||||
_audit = audit;
|
_audit = audit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,6 +25,12 @@ public sealed class DeactivateSeccionCommandHandler : ICommandHandler<Deactivate
|
|||||||
var target = await _repo.GetByIdAsync(command.Id)
|
var target = await _repo.GetByIdAsync(command.Id)
|
||||||
?? throw new SeccionNotFoundException(command.Id);
|
?? throw new SeccionNotFoundException(command.Id);
|
||||||
|
|
||||||
|
var medio = await _medioRepo.GetByIdAsync(target.MedioId)
|
||||||
|
?? throw new MedioNotFoundException(target.MedioId);
|
||||||
|
|
||||||
|
if (!medio.Activo)
|
||||||
|
throw new MedioInactivoException(medio.Id);
|
||||||
|
|
||||||
// Idempotent: already inactive → return as-is without writing an audit event
|
// Idempotent: already inactive → return as-is without writing an audit event
|
||||||
if (!target.Activo)
|
if (!target.Activo)
|
||||||
return new SeccionStatusDto(target.Id, target.Codigo, target.Activo);
|
return new SeccionStatusDto(target.Id, target.Codigo, target.Activo);
|
||||||
|
|||||||
@@ -11,11 +11,13 @@ namespace SIGCM2.Application.Secciones.Reactivate;
|
|||||||
public sealed class ReactivateSeccionCommandHandler : ICommandHandler<ReactivateSeccionCommand, SeccionStatusDto>
|
public sealed class ReactivateSeccionCommandHandler : ICommandHandler<ReactivateSeccionCommand, SeccionStatusDto>
|
||||||
{
|
{
|
||||||
private readonly ISeccionRepository _repo;
|
private readonly ISeccionRepository _repo;
|
||||||
|
private readonly IMedioRepository _medioRepo;
|
||||||
private readonly IAuditLogger _audit;
|
private readonly IAuditLogger _audit;
|
||||||
|
|
||||||
public ReactivateSeccionCommandHandler(ISeccionRepository repo, IAuditLogger audit)
|
public ReactivateSeccionCommandHandler(ISeccionRepository repo, IMedioRepository medioRepo, IAuditLogger audit)
|
||||||
{
|
{
|
||||||
_repo = repo;
|
_repo = repo;
|
||||||
|
_medioRepo = medioRepo;
|
||||||
_audit = audit;
|
_audit = audit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,6 +26,12 @@ public sealed class ReactivateSeccionCommandHandler : ICommandHandler<Reactivate
|
|||||||
var target = await _repo.GetByIdAsync(command.Id)
|
var target = await _repo.GetByIdAsync(command.Id)
|
||||||
?? throw new SeccionNotFoundException(command.Id);
|
?? throw new SeccionNotFoundException(command.Id);
|
||||||
|
|
||||||
|
var medio = await _medioRepo.GetByIdAsync(target.MedioId)
|
||||||
|
?? throw new MedioNotFoundException(target.MedioId);
|
||||||
|
|
||||||
|
if (!medio.Activo)
|
||||||
|
throw new MedioInactivoException(medio.Id);
|
||||||
|
|
||||||
// Idempotent: already active → return as-is without writing an audit event
|
// Idempotent: already active → return as-is without writing an audit event
|
||||||
if (target.Activo)
|
if (target.Activo)
|
||||||
return new SeccionStatusDto(target.Id, target.Codigo, target.Activo);
|
return new SeccionStatusDto(target.Id, target.Codigo, target.Activo);
|
||||||
|
|||||||
@@ -10,11 +10,13 @@ namespace SIGCM2.Application.Secciones.Update;
|
|||||||
public sealed class UpdateSeccionCommandHandler : ICommandHandler<UpdateSeccionCommand, SeccionUpdatedDto>
|
public sealed class UpdateSeccionCommandHandler : ICommandHandler<UpdateSeccionCommand, SeccionUpdatedDto>
|
||||||
{
|
{
|
||||||
private readonly ISeccionRepository _repo;
|
private readonly ISeccionRepository _repo;
|
||||||
|
private readonly IMedioRepository _medioRepo;
|
||||||
private readonly IAuditLogger _audit;
|
private readonly IAuditLogger _audit;
|
||||||
|
|
||||||
public UpdateSeccionCommandHandler(ISeccionRepository repo, IAuditLogger audit)
|
public UpdateSeccionCommandHandler(ISeccionRepository repo, IMedioRepository medioRepo, IAuditLogger audit)
|
||||||
{
|
{
|
||||||
_repo = repo;
|
_repo = repo;
|
||||||
|
_medioRepo = medioRepo;
|
||||||
_audit = audit;
|
_audit = audit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,6 +25,12 @@ public sealed class UpdateSeccionCommandHandler : ICommandHandler<UpdateSeccionC
|
|||||||
var target = await _repo.GetByIdAsync(command.Id)
|
var target = await _repo.GetByIdAsync(command.Id)
|
||||||
?? throw new SeccionNotFoundException(command.Id);
|
?? throw new SeccionNotFoundException(command.Id);
|
||||||
|
|
||||||
|
var medio = await _medioRepo.GetByIdAsync(target.MedioId)
|
||||||
|
?? throw new MedioNotFoundException(target.MedioId);
|
||||||
|
|
||||||
|
if (!medio.Activo)
|
||||||
|
throw new MedioInactivoException(medio.Id);
|
||||||
|
|
||||||
var updated = target.WithUpdatedProfile(command.Nombre, command.Tipo);
|
var updated = target.WithUpdatedProfile(command.Nombre, command.Tipo);
|
||||||
|
|
||||||
using var tx = new TransactionScope(
|
using var tx = new TransactionScope(
|
||||||
|
|||||||
Reference in New Issue
Block a user