feat(secciones): validar medio activo en update/deactivate/reactivate — issue #16
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user