diff --git a/src/api/SIGCM2.Domain/Entities/Medio.cs b/src/api/SIGCM2.Domain/Entities/Medio.cs new file mode 100644 index 0000000..6c7df79 --- /dev/null +++ b/src/api/SIGCM2.Domain/Entities/Medio.cs @@ -0,0 +1,75 @@ +namespace SIGCM2.Domain.Entities; + +public sealed class Medio +{ + public int Id { get; } + public string Codigo { get; } + public string Nombre { get; } + public TipoMedio Tipo { get; } + public int? PlataformaEmpresaId { get; } + public bool Activo { get; } + public DateTime FechaCreacion { get; } + public DateTime? FechaModificacion { get; } + + public Medio( + int id, + string codigo, + string nombre, + TipoMedio tipo, + int? plataformaEmpresaId, + bool activo, + DateTime fechaCreacion, + DateTime? fechaModificacion) + { + Id = id; + Codigo = codigo; + Nombre = nombre; + Tipo = tipo; + PlataformaEmpresaId = plataformaEmpresaId; + Activo = activo; + FechaCreacion = fechaCreacion; + FechaModificacion = fechaModificacion; + } + + /// + /// Factory for creating a new Medio (Id=0 — DB assigns via IDENTITY; Activo=true; FechaCreacion set by DB default). + /// + public static Medio ForCreation(string codigo, string nombre, TipoMedio tipo, int? plataformaEmpresaId) + { + return new Medio( + id: 0, + codigo: codigo, + nombre: nombre, + tipo: tipo, + plataformaEmpresaId: plataformaEmpresaId, + activo: true, + fechaCreacion: default, + fechaModificacion: null); + } + + /// + /// Returns a new instance with updated fields. Codigo is immutable (use BD UQ to enforce). + /// Sets FechaModificacion = UtcNow. + /// + public Medio WithUpdatedProfile(string nombre, TipoMedio tipo, int? plataformaEmpresaId) + => new( + id: Id, + codigo: Codigo, + nombre: nombre, + tipo: tipo, + plataformaEmpresaId: plataformaEmpresaId, + activo: Activo, + fechaCreacion: FechaCreacion, + fechaModificacion: DateTime.UtcNow); + + public Medio WithActivo(bool activo) + => new( + id: Id, + codigo: Codigo, + nombre: Nombre, + tipo: Tipo, + plataformaEmpresaId: PlataformaEmpresaId, + activo: activo, + fechaCreacion: FechaCreacion, + fechaModificacion: DateTime.UtcNow); +} diff --git a/src/api/SIGCM2.Domain/Entities/Seccion.cs b/src/api/SIGCM2.Domain/Entities/Seccion.cs new file mode 100644 index 0000000..f7d3e2f --- /dev/null +++ b/src/api/SIGCM2.Domain/Entities/Seccion.cs @@ -0,0 +1,72 @@ +namespace SIGCM2.Domain.Entities; + +public sealed class Seccion +{ + public int Id { get; } + public int MedioId { get; } + public string Codigo { get; } + public string Nombre { get; } + public string Tipo { get; } // 'clasificados' | 'notables' | 'suplementos' — enforzado por CHECK en BD + public bool Activo { get; } + public DateTime FechaCreacion { get; } + public DateTime? FechaModificacion { get; } + + public Seccion( + int id, + int medioId, + string codigo, + string nombre, + string tipo, + bool activo, + DateTime fechaCreacion, + DateTime? fechaModificacion) + { + Id = id; + MedioId = medioId; + Codigo = codigo; + Nombre = nombre; + Tipo = tipo; + Activo = activo; + FechaCreacion = fechaCreacion; + FechaModificacion = fechaModificacion; + } + + public static Seccion ForCreation(int medioId, string codigo, string nombre, string tipo) + { + return new Seccion( + id: 0, + medioId: medioId, + codigo: codigo, + nombre: nombre, + tipo: tipo, + activo: true, + fechaCreacion: default, + fechaModificacion: null); + } + + /// + /// Returns a new instance with updated fields. MedioId and Codigo are immutable. + /// Sets FechaModificacion = UtcNow. + /// + public Seccion WithUpdatedProfile(string nombre, string tipo) + => new( + id: Id, + medioId: MedioId, + codigo: Codigo, + nombre: nombre, + tipo: tipo, + activo: Activo, + fechaCreacion: FechaCreacion, + fechaModificacion: DateTime.UtcNow); + + public Seccion WithActivo(bool activo) + => new( + id: Id, + medioId: MedioId, + codigo: Codigo, + nombre: Nombre, + tipo: Tipo, + activo: activo, + fechaCreacion: FechaCreacion, + fechaModificacion: DateTime.UtcNow); +} diff --git a/src/api/SIGCM2.Domain/Entities/TipoMedio.cs b/src/api/SIGCM2.Domain/Entities/TipoMedio.cs new file mode 100644 index 0000000..df8ef89 --- /dev/null +++ b/src/api/SIGCM2.Domain/Entities/TipoMedio.cs @@ -0,0 +1,9 @@ +namespace SIGCM2.Domain.Entities; + +public enum TipoMedio +{ + Diario = 1, + Radio = 2, + Web = 3, + Poster = 4, +} diff --git a/src/api/SIGCM2.Domain/Exceptions/MedioCodigoDuplicadoException.cs b/src/api/SIGCM2.Domain/Exceptions/MedioCodigoDuplicadoException.cs new file mode 100644 index 0000000..0568d49 --- /dev/null +++ b/src/api/SIGCM2.Domain/Exceptions/MedioCodigoDuplicadoException.cs @@ -0,0 +1,15 @@ +namespace SIGCM2.Domain.Exceptions; + +/// +/// Thrown when attempting to create a Medio with a Codigo that already exists (global UQ). +/// +public sealed class MedioCodigoDuplicadoException : DomainException +{ + public string Codigo { get; } + + public MedioCodigoDuplicadoException(string codigo) + : base($"El medio con código '{codigo}' ya existe.") + { + Codigo = codigo; + } +} diff --git a/src/api/SIGCM2.Domain/Exceptions/MedioNotFoundException.cs b/src/api/SIGCM2.Domain/Exceptions/MedioNotFoundException.cs new file mode 100644 index 0000000..3a5bf6f --- /dev/null +++ b/src/api/SIGCM2.Domain/Exceptions/MedioNotFoundException.cs @@ -0,0 +1,15 @@ +namespace SIGCM2.Domain.Exceptions; + +/// +/// Thrown when a requested Medio does not exist in the system. +/// +public sealed class MedioNotFoundException : DomainException +{ + public int Id { get; } + + public MedioNotFoundException(int id) + : base($"El medio con id '{id}' no existe.") + { + Id = id; + } +} diff --git a/src/api/SIGCM2.Domain/Exceptions/SeccionCodigoDuplicadoEnMedioException.cs b/src/api/SIGCM2.Domain/Exceptions/SeccionCodigoDuplicadoEnMedioException.cs new file mode 100644 index 0000000..79e6aef --- /dev/null +++ b/src/api/SIGCM2.Domain/Exceptions/SeccionCodigoDuplicadoEnMedioException.cs @@ -0,0 +1,18 @@ +namespace SIGCM2.Domain.Exceptions; + +/// +/// Thrown when attempting to create a Seccion with a Codigo that already exists within the same Medio +/// (composite UQ on MedioId + Codigo). +/// +public sealed class SeccionCodigoDuplicadoEnMedioException : DomainException +{ + public int MedioId { get; } + public string Codigo { get; } + + public SeccionCodigoDuplicadoEnMedioException(int medioId, string codigo) + : base($"La sección con código '{codigo}' ya existe para el medio {medioId}.") + { + MedioId = medioId; + Codigo = codigo; + } +} diff --git a/src/api/SIGCM2.Domain/Exceptions/SeccionNotFoundException.cs b/src/api/SIGCM2.Domain/Exceptions/SeccionNotFoundException.cs new file mode 100644 index 0000000..faf72d6 --- /dev/null +++ b/src/api/SIGCM2.Domain/Exceptions/SeccionNotFoundException.cs @@ -0,0 +1,15 @@ +namespace SIGCM2.Domain.Exceptions; + +/// +/// Thrown when a requested Seccion does not exist in the system. +/// +public sealed class SeccionNotFoundException : DomainException +{ + public int Id { get; } + + public SeccionNotFoundException(int id) + : base($"La sección con id '{id}' no existe.") + { + Id = id; + } +}