Skip to content

Commit

Permalink
Merge pull request #10 from guivaloz:guivaloz/paso-dos-exhortos-parte…
Browse files Browse the repository at this point in the history
…s-archivos

Paso 2 listo
  • Loading branch information
guivaloz authored May 6, 2024
2 parents 0e3fb12 + 2ae945b commit d13c869
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 47 deletions.
75 changes: 35 additions & 40 deletions carina/v4/exh_exhortos/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

from sqlalchemy.orm import Session

from carina.core.estados.models import Estado
from carina.core.exh_exhortos_archivos.models import ExhExhortoArchivo
from carina.core.exh_exhortos_partes.models import ExhExhortoParte
from carina.core.materias.models import Materia
from carina.core.municipios.models import Municipio
from lib.exceptions import MyIsDeletedError, MyNotExistsError

from ...core.estados.models import Estado
from ...core.exh_exhortos.models import ExhExhorto
from ...core.exh_exhortos_archivos.models import ExhExhortoArchivo
from ...core.exh_exhortos_partes.models import ExhExhortoParte
from ...core.materias.models import Materia
from ...core.municipios.models import Municipio
from ..exh_exhortos.schemas import ExhExhortoIn

ESTADO_DESTINO_ID = 5

Expand All @@ -34,7 +34,7 @@ def get_exh_exhorto(database: Session, exh_exhorto_id: int) -> ExhExhorto:
return exh_exhorto


def create_exh_exhorto(database: Session, exh_exhorto_in: ExhExhorto) -> ExhExhorto:
def create_exh_exhorto(database: Session, exh_exhorto_in: ExhExhortoIn) -> ExhExhorto:
"""Crear un exhorto"""

# Inicializar la instancia ExhExhorto
Expand Down Expand Up @@ -103,44 +103,39 @@ def create_exh_exhorto(database: Session, exh_exhorto_in: ExhExhorto) -> ExhExho
# Texto simple que contenga información extra o relevante sobre el exhorto.
exh_exhorto.observaciones = exh_exhorto_in.observaciones

# Cargar el exhorto
# Iniciar la transaccion, agregar el exhorto
database.add(exh_exhorto)
database.commit()
database.refresh(exh_exhorto)

# Procesar las partes
# partes = []
# for parte in exh_exhorto_in.partes:
# partes.append(
# ExhExhortoParte(
# exh_exhorto=exh_exhorto,
# nombre=parte.nombre,
# apellido_paterno=parte.apellidoPaterno,
# apellido_materno=parte.apellidoMaterno,
# genero=parte.genero,
# es_persona_moral=parte.esPersonaMoral,
# tipo_parte=parte.tipoParte,
# tipo_parte_nombre=parte.tipoParteNombre,
# )
# )
# database.add(parte)

# Procesar los archivos
# archivos = []
# for archivo in exh_exhorto_in.archivos:
# archivos.append(
# ExhExhortoArchivo(
# exh_exhorto=exh_exhorto,
# nombre_archivo=archivo.nombreArchivo,
# hash_sha1=archivo.hashSha1,
# hash_sha256=archivo.hashSha256,
# tipo_documento=archivo.tipoDocumento,
# )
# )
# database.add(archivo)
# Insertar las partes
for parte in exh_exhorto_in.partes:
database.add(
ExhExhortoParte(
exh_exhorto=exh_exhorto,
nombre=parte.nombre,
apellido_paterno=parte.apellidoPaterno,
apellido_materno=parte.apellidoMaterno,
genero=parte.genero,
es_persona_moral=parte.esPersonaMoral,
tipo_parte=parte.tipoParte,
tipo_parte_nombre=parte.tipoParteNombre,
)
)

# Insertar los archivos
for archivo in exh_exhorto_in.archivos:
database.add(
ExhExhortoArchivo(
exh_exhorto=exh_exhorto,
nombre_archivo=archivo.nombreArchivo,
hash_sha1=archivo.hashSha1,
hash_sha256=archivo.hashSha256,
tipo_documento=archivo.tipoDocumento,
)
)

# Terminar la transacción
database.commit()
database.refresh(exh_exhorto)

# Entregar
return exh_exhorto
10 changes: 5 additions & 5 deletions carina/v4/exh_exhortos/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,20 @@ async def detalle_exh_exhorto(


@exh_exhortos.post("", response_model=OneExhExhortoConfirmacionDatosExhortoRecibidoOut)
async def confirmacion_datos_exhorto_recibido(
async def recepcion_exh_exhorto(
current_user: Annotated[UsuarioInDB, Depends(get_current_active_user)],
database: Annotated[Session, Depends(get_db)],
exh_exhorto: ExhExhortoIn,
):
"""Crear un Exhorto"""
"""Recepción de datos de un exhorto"""
if current_user.permissions.get("EXH EXHORTOS", 0) < Permiso.CREAR:
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Forbidden")
try:
create_exh_exhorto(database, exh_exhorto)
exh_exhorto = create_exh_exhorto(database, exh_exhorto)
except MyAnyError as error:
return OneExhExhortoConfirmacionDatosExhortoRecibidoOut(success=False, message=str(error))
data = ExhExhortoConfirmacionDatosExhortoRecibidoOut(
exhortoOrigenId="XXX",
fechaHora=datetime.now(),
exhortoOrigenId=exh_exhorto.exhorto_origen_id,
fechaHora=exh_exhorto.creado,
)
return OneExhExhortoConfirmacionDatosExhortoRecibidoOut(success=True, data=data)
5 changes: 3 additions & 2 deletions tests/test_exh_exhortos.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ def test_get_exh_exhorto_by_id(self):
def test_post_exh_exhorto(self):
"""Test POST method for exh_exhorto"""
random_uuid = uuid.uuid4()
exhorto_origen_id = str(random_uuid)
datos_nuevo_exhorto = {
"exhortoOrigenId": str(random_uuid),
"exhortoOrigenId": exhorto_origen_id,
"municipioDestinoId": 30,
"materiaClave": "FAM",
"estadoOrigenId": 19,
Expand Down Expand Up @@ -83,7 +84,7 @@ def test_post_exh_exhorto(self):
self.assertEqual(response.status_code, 200)
data = response.json()
self.assertEqual(data["success"], True)
self.assertEqual(data["data"]["exhortoOrigenId"], "XXX")
self.assertEqual(data["data"]["exhortoOrigenId"], exhorto_origen_id)


if __name__ == "__main__":
Expand Down

0 comments on commit d13c869

Please sign in to comment.