feat(api): UDT-004 dominio + repositorio + application roles (tdd)
- Migraciones V003 (tabla Rol + 8 seeds canonicos) y V004 (drop CK + FK Usuario.Rol) - Dominio: Rol entity + 3 excepciones (RolNotFound/AlreadyExists/InUse) - Infraestructura: RolRepository (Dapper) con List/Get/ExistsActive/Add/Update/HasActiveUsuarios - Application: CRUD queries y commands (List, Get, Create, Update, Deactivate) + validators (codigo regex ^[a-z][a-z0-9_]*$) - Validator UDT-003: whitelist alineada a codigos canonicos (full IRolRepository lookup diferido a Phase 5.1) - Tests: 169 application + 15 api (todos verdes). Respawn configurado para re-seedear Rol canonical post-reset. - Estricto TDD: RED/GREEN/TRIANGULATE en todos los handlers nuevos.
This commit is contained in:
44
src/api/SIGCM2.Domain/Entities/Rol.cs
Normal file
44
src/api/SIGCM2.Domain/Entities/Rol.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
namespace SIGCM2.Domain.Entities;
|
||||
|
||||
public sealed class Rol
|
||||
{
|
||||
public int Id { get; }
|
||||
public string Codigo { get; }
|
||||
public string Nombre { get; }
|
||||
public string? Descripcion { get; }
|
||||
public bool Activo { get; }
|
||||
public DateTime FechaCreacion { get; }
|
||||
public DateTime? FechaModificacion { get; }
|
||||
|
||||
public Rol(
|
||||
int id,
|
||||
string codigo,
|
||||
string nombre,
|
||||
string? descripcion,
|
||||
bool activo,
|
||||
DateTime fechaCreacion,
|
||||
DateTime? fechaModificacion)
|
||||
{
|
||||
Id = id;
|
||||
Codigo = codigo;
|
||||
Nombre = nombre;
|
||||
Descripcion = descripcion;
|
||||
Activo = activo;
|
||||
FechaCreacion = fechaCreacion;
|
||||
FechaModificacion = fechaModificacion;
|
||||
}
|
||||
|
||||
// Factory for creating a new Rol (Id=0 — DB assigns via IDENTITY; Activo=true; FechaCreacion set by DB default).
|
||||
public static Rol ForCreation(string codigo, string nombre, string? descripcion)
|
||||
{
|
||||
return new Rol(
|
||||
id: 0,
|
||||
codigo: codigo,
|
||||
nombre: nombre,
|
||||
descripcion: descripcion,
|
||||
activo: true,
|
||||
fechaCreacion: default,
|
||||
fechaModificacion: null
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace SIGCM2.Domain.Exceptions;
|
||||
|
||||
public sealed class RolAlreadyExistsException : Exception
|
||||
{
|
||||
public string Codigo { get; }
|
||||
|
||||
public RolAlreadyExistsException(string codigo)
|
||||
: base($"El rol '{codigo}' ya existe.")
|
||||
{
|
||||
Codigo = codigo;
|
||||
}
|
||||
}
|
||||
12
src/api/SIGCM2.Domain/Exceptions/RolInUseException.cs
Normal file
12
src/api/SIGCM2.Domain/Exceptions/RolInUseException.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace SIGCM2.Domain.Exceptions;
|
||||
|
||||
public sealed class RolInUseException : Exception
|
||||
{
|
||||
public string Codigo { get; }
|
||||
|
||||
public RolInUseException(string codigo)
|
||||
: base($"El rol '{codigo}' no puede desactivarse porque existen usuarios activos que lo referencian.")
|
||||
{
|
||||
Codigo = codigo;
|
||||
}
|
||||
}
|
||||
12
src/api/SIGCM2.Domain/Exceptions/RolNotFoundException.cs
Normal file
12
src/api/SIGCM2.Domain/Exceptions/RolNotFoundException.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace SIGCM2.Domain.Exceptions;
|
||||
|
||||
public sealed class RolNotFoundException : Exception
|
||||
{
|
||||
public string Codigo { get; }
|
||||
|
||||
public RolNotFoundException(string codigo)
|
||||
: base($"El rol '{codigo}' no existe.")
|
||||
{
|
||||
Codigo = codigo;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user