-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from guivaloz:guivaloz/exhortos
Guivaloz/exhortos
- Loading branch information
Showing
23 changed files
with
575 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
""" | ||
Exh Exhortos Archivos, modelos | ||
""" | ||
|
||
from sqlalchemy import Column, ForeignKey, Integer, String | ||
from sqlalchemy.orm import relationship | ||
|
||
from lib.database import Base | ||
from lib.universal_mixin import UniversalMixin | ||
|
||
|
||
class ExhExhortoArchivo(Base, UniversalMixin): | ||
"""ExhExhortoArchivo""" | ||
|
||
# Nombre de la tabla | ||
__tablename__ = "exh_exhortos_archivos" | ||
|
||
# Clave primaria | ||
id = Column(Integer, primary_key=True) | ||
|
||
# Clave foránea | ||
exh_exhorto_id = Column(Integer, ForeignKey("exh_exhortos.id"), index=True, nullable=False) | ||
exh_exhorto = relationship("ExhExhorto", back_populates="exh_exhortos_archivos") | ||
|
||
# Nombre del archivo, como se enviará. Este debe incluir el la extensión del archivo. | ||
nombre_archivo = Column(String(256), nullable=False) | ||
|
||
# Hash SHA1 en hexadecimal que corresponde al archivo a recibir. Esto para comprobar la integridad del archivo. | ||
hash_sha1 = Column(String(256)) | ||
|
||
# Hash SHA256 en hexadecimal que corresponde al archivo a recibir. Esto apra comprobar la integridad del archivo. | ||
hash_sha256 = Column(String(256)) | ||
|
||
# Identificador del tipo de documento que representa el archivo: | ||
# 1 = Oficio | ||
# 2 = Acuerdo | ||
# 3 = Anexo | ||
tipo_documento = Column(Integer, nullable=False) | ||
|
||
# URL del archivo en Google Storage | ||
url = Column(String(512), nullable=False, default="", server_default="") | ||
|
||
def __repr__(self): | ||
"""Representación""" | ||
return f"<ExhExhortoArchivo {self.id}>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
""" | ||
Exh Exhortos Partes, modelos | ||
""" | ||
|
||
from sqlalchemy import Boolean, Column, Enum, ForeignKey, Integer, String | ||
from sqlalchemy.orm import relationship | ||
|
||
from lib.database import Base | ||
from lib.universal_mixin import UniversalMixin | ||
|
||
|
||
class ExhExhortoParte(Base, UniversalMixin): | ||
"""ExhExhortoParte""" | ||
|
||
GENEROS = { | ||
"M": "MASCULINO", | ||
"F": "FEMENINO", | ||
} | ||
|
||
# Nombre de la tabla | ||
__tablename__ = "exh_exhortos_partes" | ||
|
||
# Clave primaria | ||
id = Column(Integer, primary_key=True) | ||
|
||
# Clave foránea | ||
exh_exhorto_id = Column(Integer, ForeignKey("exh_exhortos.id"), index=True, nullable=False) | ||
exh_exhorto = relationship("ExhExhorto", back_populates="exh_exhortos_partes") | ||
|
||
# Nombre de la parte, en el caso de persona moral, solo en nombre de la empresa o razón social. | ||
nombre = Column(String(256), nullable=False) | ||
|
||
# Apellido paterno de la parte. Solo cuando no sea persona moral. | ||
apellido_paterno = Column(String(256)) | ||
|
||
# Apellido materno de la parte, si es que aplica para la persona. Solo cuando no sea persona moral. | ||
apellido_materno = Column(String(256)) | ||
|
||
# 'M' = Masculino, | ||
# 'F' = Femenino. | ||
# Solo cuando aplique y se quiera especificar (que se tenga el dato). NO aplica para persona moral. | ||
genero = Column(Enum(*GENEROS, name="tipos_generos", native_enum=False), nullable=True) | ||
|
||
# Valor que indica si la parte es una persona moral. | ||
es_persona_moral = Column(Boolean, nullable=False) | ||
|
||
# Indica el tipo de parte: | ||
# 1 = Actor, Promovente, Ofendido; | ||
# 2 = Demandado, Inculpado, Imputado; | ||
# 0 = No definido o se especifica en tipoParteNombre | ||
tipo_parte = Column(Integer, nullable=False, default=0) | ||
|
||
# Aquí se puede especificar el nombre del tipo de parte. | ||
tipo_parte_nombre = Column(String(256)) | ||
|
||
def __repr__(self): | ||
"""Representación""" | ||
return f"<ExhExhortoParte {self.id}>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
""" | ||
Exh Exhortos v4, CRUD (create, read, update, and delete) | ||
""" | ||
|
||
from typing import Any | ||
|
||
from sqlalchemy.orm import Session | ||
|
||
from lib.exceptions import MyIsDeletedError, MyNotExistsError | ||
|
||
from ...core.exh_exhortos.models import ExhExhorto | ||
|
||
|
||
def get_exh_exhortos(database: Session) -> Any: | ||
"""Consultar los exhortos activos""" | ||
consulta = database.query(ExhExhorto) | ||
return consulta.filter_by(estatus="A").order_by(ExhExhorto.id) | ||
|
||
|
||
def get_exh_exhorto(database: Session, exh_exhorto_id: int) -> ExhExhorto: | ||
"""Consultar un exhorto por su id""" | ||
exh_exhorto = database.query(ExhExhorto).get(exh_exhorto_id) | ||
if exh_exhorto is None: | ||
raise MyNotExistsError("No existe ese exhorto") | ||
if exh_exhorto.estatus != "A": | ||
raise MyIsDeletedError("No es activo ese exhorto, está eliminado") | ||
return exh_exhorto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
""" | ||
Exh Exhortos 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_exh_exhortos, get_exh_exhorto | ||
from .schemas import ExhExhortoOut, OneExhExhortoOut | ||
|
||
exh_exhortos = APIRouter(prefix="/v4/exh_exhortos", tags=["exhortos"]) | ||
|
||
|
||
@exh_exhortos.get("", response_model=CustomPage[ExhExhortoOut]) | ||
async def paginado_exh_exhortos( | ||
current_user: Annotated[UsuarioInDB, Depends(get_current_active_user)], | ||
database: Annotated[Session, Depends(get_db)], | ||
): | ||
"""Paginado de exhortos""" | ||
if current_user.permissions.get("EXH EXHORTOS", 0) < Permiso.VER: | ||
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Forbidden") | ||
try: | ||
resultados = get_exh_exhortos(database) | ||
except MyAnyError as error: | ||
return CustomPage(success=False, errors=[str(error)]) | ||
return paginate(resultados) | ||
|
||
|
||
@exh_exhortos.get("/{exh_exhorto_id}", response_model=OneExhExhortoOut) | ||
async def detalle_exh_exhorto( | ||
current_user: Annotated[UsuarioInDB, Depends(get_current_active_user)], | ||
database: Annotated[Session, Depends(get_db)], | ||
exh_exhorto_id: int, | ||
): | ||
"""Detalle de una exhorto a partir de su id""" | ||
if current_user.permissions.get("EXH EXHORTOS", 0) < Permiso.VER: | ||
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Forbidden") | ||
try: | ||
exh_exhorto = get_exh_exhorto(database, exh_exhorto_id) | ||
except MyAnyError as error: | ||
return OneExhExhortoOut(success=False, errors=[str(error)]) | ||
return OneExhExhortoOut.model_validate(exh_exhorto) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
""" | ||
Exh Exhortos v4, esquemas de pydantic | ||
""" | ||
|
||
from pydantic import BaseModel, ConfigDict | ||
|
||
from lib.schemas_base import OneBaseOut | ||
|
||
|
||
class ExhExhortoOut(BaseModel): | ||
"""Esquema para entregar plural""" | ||
|
||
id: int | None = None | ||
exhorto_origen_id: str | None = None | ||
municipio_destino_id: int | None = None | ||
materia_id: int | None = None | ||
materia_nombre: str | None = None | ||
estado_origen_id: int | None = None | ||
municipio_origen_id: int | None = None | ||
juzgado_origen_id: str | None = None | ||
juzgado_origen_nombre: str | None = None | ||
numero_expediente_origen: str | None = None | ||
model_config = ConfigDict(from_attributes=True) | ||
|
||
|
||
class OneExhExhortoOut(ExhExhortoOut, OneBaseOut): | ||
"""Esquema para entregar un singular""" |
Empty file.
Oops, something went wrong.