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

@@ -10,11 +10,13 @@ namespace SIGCM2.Application.Secciones.Update;
public sealed class UpdateSeccionCommandHandler : ICommandHandler<UpdateSeccionCommand, SeccionUpdatedDto>
{
private readonly ISeccionRepository _repo;
private readonly IMedioRepository _medioRepo;
private readonly IAuditLogger _audit;
public UpdateSeccionCommandHandler(ISeccionRepository repo, IAuditLogger audit)
public UpdateSeccionCommandHandler(ISeccionRepository repo, IMedioRepository medioRepo, IAuditLogger audit)
{
_repo = repo;
_medioRepo = medioRepo;
_audit = audit;
}
@@ -23,6 +25,12 @@ public sealed class UpdateSeccionCommandHandler : ICommandHandler<UpdateSeccionC
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);
var updated = target.WithUpdatedProfile(command.Nombre, command.Tipo);
using var tx = new TransactionScope(