feat(medios,secciones): application layer + handlers TDD — ADM-001 B3+B4

- IMedioRepository, ISeccionRepository interfaces
- MediosQuery, SeccionesQuery common records
- TipoSeccion static AllowedTipos helper
- Medios: 6 use cases (Create/Update/Deactivate/Reactivate/List/GetById) with validators, handlers and DTOs
- Secciones: 6 use cases mirroring Medios; Create validates MedioId active via IMedioRepository
- 52 unit tests (xUnit + NSubstitute) all green; audit LogAsync asserted per mutating handler
- DI registrations for all 12 handlers and validators auto-scanned via AddValidatorsFromAssemblyContaining
This commit is contained in:
2026-04-16 18:53:57 -03:00
parent bb98dbf217
commit f672de78ce
56 changed files with 1844 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
using System.Transactions;
using SIGCM2.Application.Abstractions;
using SIGCM2.Application.Abstractions.Persistence;
using SIGCM2.Application.Audit;
using SIGCM2.Domain.Entities;
using SIGCM2.Domain.Exceptions;
namespace SIGCM2.Application.Medios.Update;
public sealed class UpdateMedioCommandHandler : ICommandHandler<UpdateMedioCommand, MedioUpdatedDto>
{
private readonly IMedioRepository _repo;
private readonly IAuditLogger _audit;
public UpdateMedioCommandHandler(IMedioRepository repo, IAuditLogger audit)
{
_repo = repo;
_audit = audit;
}
public async Task<MedioUpdatedDto> Handle(UpdateMedioCommand command)
{
var target = await _repo.GetByIdAsync(command.Id)
?? throw new MedioNotFoundException(command.Id);
var updated = target.WithUpdatedProfile(command.Nombre, command.Tipo, command.PlataformaEmpresaId);
using var tx = new TransactionScope(
TransactionScopeOption.Required,
new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted },
TransactionScopeAsyncFlowOption.Enabled);
await _repo.UpdateAsync(updated);
await _audit.LogAsync(
action: "medio.update",
targetType: "Medio",
targetId: command.Id.ToString(),
metadata: new
{
before = new { target.Nombre, target.Tipo, target.PlataformaEmpresaId },
after = new { updated.Nombre, updated.Tipo, updated.PlataformaEmpresaId },
});
tx.Complete();
return new MedioUpdatedDto(
Id: updated.Id,
Codigo: updated.Codigo,
Nombre: updated.Nombre,
Tipo: updated.Tipo,
PlataformaEmpresaId: updated.PlataformaEmpresaId,
Activo: updated.Activo);
}
}