Skip to content

Commit

Permalink
Merge pull request #8 from guivaloz:guivaloz/paths-exh
Browse files Browse the repository at this point in the history
Guivaloz/paths-exh
  • Loading branch information
guivaloz authored May 3, 2024
2 parents 247e911 + 69cabb1 commit 088cec5
Show file tree
Hide file tree
Showing 24 changed files with 372 additions and 83 deletions.
4 changes: 3 additions & 1 deletion carina/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from .v4.bitacoras.paths import bitacoras
from .v4.distritos.paths import distritos
from .v4.entradas_salidas.paths import entradas_salidas
from .v4.estados.paths import estados
from .v4.exh_exhortos.paths import exh_exhortos
from .v4.exh_exhortos_archivos.paths import exh_exhortos_archivos
from .v4.exh_exhortos_partes.paths import exh_exhortos_partes
Expand Down Expand Up @@ -47,10 +48,11 @@ def create_app() -> FastAPI:
)

# Rutas
app.include_router(autoridades)
app.include_router(autoridades, include_in_schema=False)
app.include_router(bitacoras, include_in_schema=False)
app.include_router(distritos)
app.include_router(entradas_salidas, include_in_schema=False)
app.include_router(estados)
app.include_router(exh_exhortos)
app.include_router(exh_exhortos_archivos)
app.include_router(exh_exhortos_partes)
Expand Down
73 changes: 66 additions & 7 deletions carina/core/exh_exhortos/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,83 @@ class ExhExhorto(Base, UniversalMixin):

# Hijos
# PersonaParte[] NO Contiene la definición de las partes del Expediente
exh_exhortos_partes = relationship("ExhExhortoParte", back_populates="exh_exhorto", lazy="noload")
exh_exhortos_partes = relationship("ExhExhortoParte", back_populates="exh_exhorto")
# ArchivoARecibir[] SI Colección de los datos referentes a los archivos que se van a recibir el Poder Judicial exhortado en el envío del Exhorto.
exh_exhortos_archivos = relationship("ExhExhortoArchivo", back_populates="exh_exhorto", lazy="noload")
exh_exhortos_archivos = relationship("ExhExhortoArchivo", back_populates="exh_exhorto")

# Propiedades que se van a cargar despues
partes = []
archivos = []

@property
def estadoOrigenId(self):
"""ID del estado de origen"""
return self.municipio_origen.estado_id
def exhortoOrigenId(self):
"""ID del exhorto de origen"""
return self.exhorto_origen_id

@property
def municipioDestinoId(self):
"""Clave INEGI del municipio de destino"""
return self.municipio_destino_id

@property
def materiaClave(self):
"""Clave de la materia"""
return self.materia.clave

@property
def estadoOrigenId(self):
"""Clave INEGI del estado de origen"""
return self.municipio_origen.estado.clave

@property
def municipioOrigenId(self):
"""ID del municipio de origen"""
return self.municipio_origen_id
"""Clave INEGI del municipio de origen"""
return self.municipio_origen.clave

@property
def juzgadoOrigenId(self):
"""ID del juzgado de origen"""
return self.juzgado_origen_id

@property
def juzgadoOrigenNombre(self):
"""Nombre del juzgado de origen"""
return self.juzgado_origen_nombre

@property
def numeroExpedienteOrigen(self):
"""Número de expediente de origen"""
return self.numero_expediente_origen

@property
def numeroOficioOrigen(self):
"""Número de oficio de origen"""
return self.numero_oficio_origen

@property
def tipoJuicioAsuntoDelitos(self):
"""Tipo de juicio"""
return self.tipo_juicio_asunto_delitos

@property
def juezExhortante(self):
"""Juez exhortante"""
return self.juez_exhortante

@property
def diasResponder(self):
"""Días para responder"""
return self.dias_responder

@property
def tipoDiligenciacionNombre(self):
"""Tipo de diligenciación"""
return self.tipo_diligenciacion_nombre

@property
def fechaOrigen(self):
"""Fecha de origen"""
return self.fecha_origen

def __repr__(self):
"""Representación"""
Expand Down
20 changes: 20 additions & 0 deletions carina/core/exh_exhortos_archivos/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,26 @@ class ExhExhortoArchivo(Base, UniversalMixin):
# URL del archivo en Google Storage
url = Column(String(512), nullable=False, default="", server_default="")

@property
def nombreArchivo(self):
"""Nombre del archivo"""
return self.nombre_archivo

@property
def hashSha1(self):
"""Hash SHA1"""
return self.hash_sha1

@property
def hashSha256(self):
"""Hash SHA256"""
return self.hash_sha256

@property
def tipoDocumento(self):
"""Tipo de documento"""
return self.tipo_documento

def __repr__(self):
"""Representación"""
return f"<ExhExhortoArchivo {self.id}>"
26 changes: 26 additions & 0 deletions carina/core/exh_exhortos_partes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,32 @@ class ExhExhortoParte(Base, UniversalMixin):
# Aquí se puede especificar el nombre del tipo de parte.
tipo_parte_nombre = Column(String(256))

@property
def apellidoPaterno(self):
"""Apellido paterno"""
return self.apellido_paterno

@property
def apellidoMaterno(self):
"""Apellido materno"""
return self.apellido_materno

@property
def esPersonaMoral(self):
"""Es persona moral"""
return self.es_persona_moral

@property
def tipoParte(self):
"""Tipo de parte"""
return self.tipo_parte

@property
def tipoParteNombre(self):
"""Nombre del tipo de parte"""
return self.tipo_parte_nombre

@property
def __repr__(self):
"""Representación"""
return f"<ExhExhortoParte {self.id}>"
4 changes: 2 additions & 2 deletions carina/core/municipios/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class Municipio(Base, UniversalMixin):
id = Column(Integer, primary_key=True)

# Clave foránea
# estado_id = Column(Integer, ForeignKey("estados.id"), index=True, nullable=False)
# estado = relationship("Estado", back_populates="municipios")
estado_id = Column(Integer, ForeignKey("estados.id"), index=True, nullable=False)
estado = relationship("Estado", back_populates="municipios")

# Columnas
clave = Column(String(3), nullable=False)
Expand Down
3 changes: 2 additions & 1 deletion carina/v4/autoridades/paths.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Autoridades v4, rutas (paths)
"""

from typing import Annotated

from fastapi import APIRouter, Depends, HTTPException, status
Expand Down Expand Up @@ -54,4 +55,4 @@ async def detalle_autoridad(
autoridad = get_autoridad_with_clave(database, autoridad_clave)
except MyAnyError as error:
return OneAutoridadOut(success=False, errors=[str(error)])
return OneAutoridadOut.model_validate(autoridad)
return OneAutoridadOut(success=True, data=autoridad)
16 changes: 7 additions & 9 deletions carina/v4/autoridades/schemas.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
"""
Autoridades v4, esquemas de pydantic
"""

from pydantic import BaseModel, ConfigDict

from lib.schemas_base import OneBaseOut


class AutoridadListOut(BaseModel):
"""Esquema para entregar autoridades como listado"""
class AutoridadOut(BaseModel):
"""Esquema para entregar autoridades"""

id: int | None = None
clave: str | None = None
descripcion_corta: str | None = None
model_config = ConfigDict(from_attributes=True)


class AutoridadOut(AutoridadListOut):
"""Esquema para entregar autoridades"""

distrito_id: int | None = None
distrito_clave: str | None = None
descripcion: str | None = None
es_extinto: bool | None = None
model_config = ConfigDict(from_attributes=True)


class OneAutoridadOut(AutoridadOut, OneBaseOut):
class OneAutoridadOut(OneBaseOut):
"""Esquema para entregar un autoridad"""

data: AutoridadOut | None = None
3 changes: 2 additions & 1 deletion carina/v4/distritos/paths.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Distritos v4, rutas (paths)
"""

from typing import Annotated

from fastapi import APIRouter, Depends, HTTPException, status
Expand Down Expand Up @@ -52,4 +53,4 @@ async def detalle_distrito(
distrito = get_distrito_with_clave(database, distrito_clave)
except MyAnyError as error:
return OneDistritoOut(success=False, errors=[str(error)])
return OneDistritoOut.model_validate(distrito)
return OneDistritoOut(success=True, data=distrito)
16 changes: 7 additions & 9 deletions carina/v4/distritos/schemas.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
"""
Distritos v4, esquemas de pydantic
"""

from pydantic import BaseModel, ConfigDict

from lib.schemas_base import OneBaseOut


class DistritoListOut(BaseModel):
"""Esquema para entregar distritos como listado"""
class DistritoOut(BaseModel):
"""Esquema para entregar distritos"""

id: int | None = None
clave: str | None = None
nombre_corto: str | None = None
model_config = ConfigDict(from_attributes=True)


class DistritoOut(DistritoListOut):
"""Esquema para entregar distritos"""

nombre: str | None = None
es_distrito: bool | None = None
es_jurisdiccional: bool | None = None
model_config = ConfigDict(from_attributes=True)


class OneDistritoOut(DistritoOut, OneBaseOut):
class OneDistritoOut(OneBaseOut):
"""Esquema para entregar un distrito"""

data: DistritoOut | None = None
26 changes: 26 additions & 0 deletions carina/v4/estados/crud.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""
Estados v4, CRUD (create, read, update, and delete)
"""

from typing import Any

from sqlalchemy.orm import Session

from lib.exceptions import MyIsDeletedError, MyNotExistsError

from ...core.estados.models import Estado


def get_estados(database: Session) -> Any:
"""Consultar los estados activos"""
return database.query(Estado).filter_by(estatus="A").order_by(Estado.clave)


def get_estado(database: Session, estado_id: int) -> Estado:
"""Consultar un estado por su id"""
estado = database.query(Estado).get(estado_id)
if estado is None:
raise MyNotExistsError("No existe ese estado")
if estado.estatus != "A":
raise MyIsDeletedError("No es activo ese estado, está eliminado")
return estado
50 changes: 50 additions & 0 deletions carina/v4/estados/paths.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""
Estados v4, rutas (paths)
"""

from typing import Annotated

from fastapi import APIRouter, Depends, HTTPException, status
from fastapi_pagination.ext.sqlalchemy import paginate

from lib.database import Session, get_db
from lib.exceptions import MyAnyError
from lib.fastapi_pagination_custom_page import CustomPage

from ...core.permisos.models import Permiso
from ..usuarios.authentications import UsuarioInDB, get_current_active_user
from .crud import get_estados, get_estado
from .schemas import EstadoOut, OneEstadoOut

estados = APIRouter(prefix="/v4/estados", tags=["estados"])


@estados.get("", response_model=CustomPage[EstadoOut])
async def paginado_estados(
current_user: Annotated[UsuarioInDB, Depends(get_current_active_user)],
database: Annotated[Session, Depends(get_db)],
):
"""Paginado de estados"""
if current_user.permissions.get("ESTADOS", 0) < Permiso.VER:
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Forbidden")
try:
resultados = get_estados(database)
except MyAnyError as error:
return CustomPage(success=False, errors=[str(error)])
return paginate(resultados)


@estados.get("/{estado_id}", response_model=OneEstadoOut)
async def detalle_estado(
current_user: Annotated[UsuarioInDB, Depends(get_current_active_user)],
database: Annotated[Session, Depends(get_db)],
estado_id: int,
):
"""Detalle de un estado a partir de su id"""
if current_user.permissions.get("ESTADOS", 0) < Permiso.VER:
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Forbidden")
try:
estado = get_estado(database, estado_id)
except MyAnyError as error:
return OneEstadoOut(success=False, errors=[str(error)])
return OneEstadoOut(success=True, data=estado)
22 changes: 22 additions & 0 deletions carina/v4/estados/schemas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""
Estados v4, esquemas de pydantic
"""

from pydantic import BaseModel, ConfigDict

from lib.schemas_base import OneBaseOut


class EstadoOut(BaseModel):
"""Esquema para entregar estados"""

id: int | None = None
clave: str | None = None
nombre: str | None = None
model_config = ConfigDict(from_attributes=True)


class OneEstadoOut(OneBaseOut):
"""Esquema para entregar un estado"""

data: EstadoOut | None = None
Loading

0 comments on commit 088cec5

Please sign in to comment.