feat(secciones): validar medio activo en update/deactivate/reactivate — issue #16

This commit is contained in:
2026-04-17 11:46:01 -03:00
parent 1ad6633cdd
commit 870cbe91b3
3 changed files with 27 additions and 3 deletions

View File

@@ -11,11 +11,13 @@ namespace SIGCM2.Application.Secciones.Reactivate;
public sealed class ReactivateSeccionCommandHandler : ICommandHandler<ReactivateSeccionCommand, SeccionStatusDto>
{
private readonly ISeccionRepository _repo;
private readonly IMedioRepository _medioRepo;
private readonly IAuditLogger _audit;
public ReactivateSeccionCommandHandler(ISeccionRepository repo, IAuditLogger audit)
public ReactivateSeccionCommandHandler(ISeccionRepository repo, IMedioRepository medioRepo, IAuditLogger audit)
{
_repo = repo;
_medioRepo = medioRepo;
_audit = audit;
}
@@ -24,6 +26,12 @@ public sealed class ReactivateSeccionCommandHandler : ICommandHandler<Reactivate
var target = await _repo.GetByIdAsync(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
if (target.Activo)
return new SeccionStatusDto(target.Id, target.Codigo, target.Activo);