Skip to content

Commit

Permalink
Merge pull request #22 from guivaloz:guivaloz/tareas-id-string
Browse files Browse the repository at this point in the history
Correcciones
  • Loading branch information
guivaloz authored Jun 21, 2024
2 parents 53a36a7 + 43be8c9 commit c42d5d1
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 58 deletions.
1 change: 1 addition & 0 deletions .gcloudignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
.gitignore
.DS_Store

*.code-workspace
*.csv
*.py[cod]
*.sqlite3
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.env
.DS_Store
.~lock.*
*.code-workspace
*.csv
*.py[cod]
*.log
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ then
echo " DB_NAME: ${DB_NAME}"
echo " DB_USER: ${DB_USER}"
echo " DB_PASS: ${DB_PASS}"
echo " GOOGLE_APPLICATION_CREDENTIALS: ${GOOGLE_APPLICATION_CREDENTIALS}"
echo " ORIGINS: ${ORIGINS}"
echo " SALT: ${SALT}"
echo
Expand Down
2 changes: 1 addition & 1 deletion carina/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def create_app() -> FastAPI:
app.include_router(exh_areas, include_in_schema=False)
app.include_router(exh_exhortos)
app.include_router(exh_exhortos_archivos)
app.include_router(exh_exhortos_partes)
app.include_router(exh_exhortos_partes, include_in_schema=False)
app.include_router(materias)
app.include_router(modulos, include_in_schema=False)
app.include_router(municipios)
Expand Down
12 changes: 6 additions & 6 deletions carina/core/tareas/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Tareas, modelos
"""

from sqlalchemy import ForeignKey, String, Uuid
from sqlalchemy import ForeignKey, String
from sqlalchemy.orm import Mapped, mapped_column, relationship

from lib.database import Base
Expand All @@ -16,18 +16,18 @@ class Tarea(Base, UniversalMixin):
__tablename__ = "tareas"

# Clave primaria NOTA: El id es string y es el mismo que usa el RQ worker
id: Mapped[str] = mapped_column(Uuid, primary_key=True)
id: Mapped[str] = mapped_column(String(36), primary_key=True)

# Clave foránea
usuario_id: Mapped[int] = mapped_column(ForeignKey("usuarios.id"))
usuario: Mapped["Usuario"] = relationship("Usuario", back_populates="tareas")

# Columnas
archivo: Mapped[str] = mapped_column(String(256))
comando: Mapped[str] = mapped_column(String(256), index=True)
archivo: Mapped[str] = mapped_column(String(256), default="", server_default="")
comando: Mapped[str] = mapped_column(String(256), index=True, default="", server_default="")
ha_terminado: Mapped[bool] = mapped_column(default=False)
mensaje: Mapped[str] = mapped_column(String(1024))
url: Mapped[str] = mapped_column(String(512))
mensaje: Mapped[str] = mapped_column(String(1024), default="", server_default="")
url: Mapped[str] = mapped_column(String(512), default="", server_default="")

def __repr__(self):
"""Representación"""
Expand Down
6 changes: 4 additions & 2 deletions carina/v4/exh_exhortos/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
Exh Exhortos v4, CRUD (create, read, update, and delete)
"""

import uuid
from datetime import datetime
from typing import Any
import uuid

from sqlalchemy.orm import Session

from carina.core.autoridades.models import Autoridad
from carina.core.exh_areas.models import ExhArea
from lib.exceptions import MyIsDeletedError, MyNotExistsError, MyNotValidParamError

from ...core.estados.models import Estado
from ...core.exh_exhortos.models import ExhExhorto
from ...core.exh_exhortos_archivos.models import ExhExhortoArchivo
Expand All @@ -19,6 +20,7 @@
from ...core.municipios.models import Municipio
from ..exh_exhortos.schemas import ExhExhortoIn

ESTADO_DESTINO_NOMBRE = "COAHUILA DE ZARAGOZA"
ESTADO_DESTINO_ID = 5


Expand Down Expand Up @@ -71,7 +73,7 @@ def create_exh_exhorto(database: Session, exh_exhorto_in: ExhExhortoIn) -> ExhEx
database.query(Municipio).filter_by(estado_id=ESTADO_DESTINO_ID).filter_by(clave=municipio_destino_clave).first()
)
if municipio_destino is None:
raise MyNotExistsError("No existe ese municipio de destino")
raise MyNotExistsError(f"No existe el municipio de destino {municipio_destino_clave} en {ESTADO_DESTINO_NOMBRE}")
exh_exhorto.municipio_destino_id = municipio_destino.id

# Consultar y validar la materia
Expand Down
16 changes: 10 additions & 6 deletions carina/v4/exh_exhortos/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from lib.exceptions import MyAnyError

from ...core.permisos.models import Permiso
from ..exh_exhortos_archivos.schemas import ExhExhortoArchivoOut
from ..exh_exhortos_partes.schemas import ExhExhortoParteIn
from ..municipios.crud import get_municipio
from ..usuarios.authentications import UsuarioInDB, get_current_active_user
from .crud import create_exh_exhorto, get_exh_exhorto_by_folio_seguimiento
Expand All @@ -21,8 +23,6 @@
OneExhExhortoConfirmacionDatosExhortoRecibidoOut,
OneExhExhortoOut,
)
from ..exh_exhortos_archivos.schemas import ExhExhortoArchivoOut
from ..exh_exhortos_partes.schemas import ExhExhortoParteIn

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

Expand Down Expand Up @@ -78,8 +78,8 @@ async def detalle_exh_exhorto_con_folio_seguimiento(

# Definir datos del exhorto a entregar
ext_extorto_data = ExhExhortoOut(
exhortoOrigenId=exh_exhorto.exhorto_origen_id,
folioSeguimiento=exh_exhorto.folio_seguimiento,
exhortoOrigenId=str(exh_exhorto.exhorto_origen_id),
folioSeguimiento=str(exh_exhorto.folio_seguimiento),
estadoDestinoId=estado_destino.clave,
estadoDestinoNombre=estado_destino.nombre,
municipioDestinoId=municipio_destino.clave,
Expand Down Expand Up @@ -128,9 +128,13 @@ async def recepcion_exh_exhorto(
try:
exh_exhorto = create_exh_exhorto(database, exh_exhorto)
except MyAnyError as error:
return OneExhExhortoConfirmacionDatosExhortoRecibidoOut(success=False, message=str(error))
return OneExhExhortoConfirmacionDatosExhortoRecibidoOut(
success=False,
message="Error al recibir un exhorto",
errors=[str(error)],
)
data = ExhExhortoConfirmacionDatosExhortoRecibidoOut(
exhortoOrigenId=exh_exhorto.exhorto_origen_id,
exhortoOrigenId=str(exh_exhorto.exhorto_origen_id),
fechaHora=exh_exhorto.creado,
)
return OneExhExhortoConfirmacionDatosExhortoRecibidoOut(success=True, data=data)
27 changes: 15 additions & 12 deletions carina/v4/exh_exhortos_archivos/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,17 @@
Exh Exhortos Archivos v4, rutas (paths)
"""

from datetime import datetime
from typing import Annotated
import hashlib
import uuid
from datetime import datetime
from typing import Annotated

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

from config.settings import get_settings
from lib.database import Session, get_db
from lib.exceptions import MyAnyError
from lib.fastapi_pagination_custom_page import CustomPage
from lib.google_cloud_storage import upload_file_to_gcs

from carina.core.permisos.models import Permiso
from carina.v4.exh_exhortos.crud import get_exh_exhorto_by_exhorto_origen_id, update_set_exhorto
from carina.v4.exh_exhortos_archivos.crud import get_exh_exhortos_archivos, get_exh_exhorto_archivo, update_set_exhorto_archivo
from carina.v4.exh_exhortos_archivos.crud import get_exh_exhorto_archivo, get_exh_exhortos_archivos, update_set_exhorto_archivo
from carina.v4.exh_exhortos_archivos.schemas import (
ExhExhortoArchivoFileDataAcuseOut,
ExhExhortoArchivoFileDataArchivoOut,
Expand All @@ -28,6 +22,11 @@
OneExhExhortoArchivoOut,
)
from carina.v4.usuarios.authentications import UsuarioInDB, get_current_active_user
from config.settings import get_settings
from lib.database import Session, get_db
from lib.exceptions import MyAnyError
from lib.fastapi_pagination_custom_page import CustomPage
from lib.google_cloud_storage import upload_file_to_gcs

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

Expand Down Expand Up @@ -152,7 +151,11 @@ async def upload_exh_exhorto_archivo(
data=archivo_en_memoria,
)
except MyAnyError as error:
return ExhExhortoArchivoFileOut(success=False, errors=[str(error)])
return ExhExhortoArchivoFileOut(
success=False,
message="Error al recibir un archivo de un exhorto",
errors=[str(error)],
)

# Cambiar el estado de exh_exhorto_archivo_encontrado a RECIBIDO
exh_exhorto_archivo = update_set_exhorto_archivo(
Expand Down Expand Up @@ -183,7 +186,7 @@ async def upload_exh_exhorto_archivo(
)
# Y se va a elaborar el acuse
acuse = ExhExhortoArchivoFileDataAcuseOut(
exhortoOrigenId=exh_exhorto_actualizado.exhorto_origen_id,
exhortoOrigenId=str(exh_exhorto_actualizado.exhorto_origen_id),
folioSeguimiento=folio_seguimiento,
fechaHoraRecepcion=fecha_hora_recepcion,
municipioAreaRecibeId=exh_exhorto_actualizado.municipio_destino_id,
Expand Down
59 changes: 29 additions & 30 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,54 +1,53 @@
annotated-types==0.6.0 ; python_version >= "3.11" and python_version < "4.0"
anyio==4.3.0 ; python_version >= "3.11" and python_version < "4.0"
annotated-types==0.7.0 ; python_version >= "3.11" and python_version < "4.0"
anyio==4.4.0 ; python_version >= "3.11" and python_version < "4.0"
cachetools==5.3.3 ; python_version >= "3.11" and python_version < "4.0"
certifi==2024.2.2 ; python_version >= "3.11" and python_version < "4.0"
certifi==2024.6.2 ; python_version >= "3.11" and python_version < "4.0"
cffi==1.16.0 ; python_version >= "3.11" and python_version < "4.0"
charset-normalizer==3.3.2 ; python_version >= "3.11" and python_version < "4.0"
click==8.1.7 ; python_version >= "3.11" and python_version < "4.0"
colorama==0.4.6 ; python_version >= "3.11" and python_version < "4.0" and platform_system == "Windows"
cryptography==41.0.7 ; python_version >= "3.11" and python_version < "4.0"
fastapi-pagination==0.12.19 ; python_version >= "3.11" and python_version < "4.0"
fastapi==0.109.2 ; python_version >= "3.11" and python_version < "4.0"
fastapi-pagination==0.12.25 ; python_version >= "3.11" and python_version < "4.0"
fastapi[sqlalchemy]==0.109.2 ; python_version >= "3.11" and python_version < "4.0"
google-api-core==2.17.1 ; python_version >= "3.11" and python_version < "4.0"
google-api-core[grpc]==2.17.1 ; python_version >= "3.11" and python_version < "4.0"
google-auth==2.28.1 ; python_version >= "3.11" and python_version < "4.0"
google-api-core==2.19.0 ; python_version >= "3.11" and python_version < "4.0"
google-api-core[grpc]==2.19.0 ; python_version >= "3.11" and python_version < "4.0"
google-auth==2.30.0 ; python_version >= "3.11" and python_version < "4.0"
google-cloud-core==2.4.1 ; python_version >= "3.11" and python_version < "4.0"
google-cloud-secret-manager==2.18.3 ; python_version >= "3.11" and python_version < "4.0"
google-cloud-storage==2.15.0 ; python_version >= "3.11" and python_version < "4.0"
google-cloud-secret-manager==2.20.0 ; python_version >= "3.11" and python_version < "4.0"
google-cloud-storage==2.17.0 ; python_version >= "3.11" and python_version < "4.0"
google-cloud==0.34.0 ; python_version >= "3.11" and python_version < "4.0"
google-crc32c==1.5.0 ; python_version >= "3.11" and python_version < "4.0"
google-resumable-media==2.7.0 ; python_version >= "3.11" and python_version < "4.0"
googleapis-common-protos==1.62.0 ; python_version >= "3.11" and python_version < "4.0"
googleapis-common-protos[grpc]==1.62.0 ; python_version >= "3.11" and python_version < "4.0"
greenlet==3.0.3 ; python_version >= "3.11" and python_version < "4.0" and (platform_machine == "aarch64" or platform_machine == "ppc64le" or platform_machine == "x86_64" or platform_machine == "amd64" or platform_machine == "AMD64" or platform_machine == "win32" or platform_machine == "WIN32")
google-resumable-media==2.7.1 ; python_version >= "3.11" and python_version < "4.0"
googleapis-common-protos==1.63.1 ; python_version >= "3.11" and python_version < "4.0"
googleapis-common-protos[grpc]==1.63.1 ; python_version >= "3.11" and python_version < "4.0"
greenlet==3.0.3 ; python_version < "3.13" and (platform_machine == "aarch64" or platform_machine == "ppc64le" or platform_machine == "x86_64" or platform_machine == "amd64" or platform_machine == "AMD64" or platform_machine == "win32" or platform_machine == "WIN32") and python_version >= "3.11"
grpc-google-iam-v1==0.13.0 ; python_version >= "3.11" and python_version < "4.0"
grpcio-status==1.62.0 ; python_version >= "3.11" and python_version < "4.0"
grpcio==1.62.0 ; python_version >= "3.11" and python_version < "4.0"
grpcio-status==1.62.2 ; python_version >= "3.11" and python_version < "4.0"
grpcio==1.64.1 ; python_version >= "3.11" and python_version < "4.0"
gunicorn==21.2.0 ; python_version >= "3.11" and python_version < "4.0"
h11==0.14.0 ; python_version >= "3.11" and python_version < "4.0"
hashids==1.3.1 ; python_version >= "3.11" and python_version < "4.0"
idna==3.6 ; python_version >= "3.11" and python_version < "4.0"
packaging==23.2 ; python_version >= "3.11" and python_version < "4.0"
proto-plus==1.23.0 ; python_version >= "3.11" and python_version < "4.0"
idna==3.7 ; python_version >= "3.11" and python_version < "4.0"
packaging==24.1 ; python_version >= "3.11" and python_version < "4.0"
proto-plus==1.24.0 ; python_version >= "3.11" and python_version < "4.0"
protobuf==4.25.3 ; python_version >= "3.11" and python_version < "4.0"
psycopg2-binary==2.9.9 ; python_version >= "3.11" and python_version < "4.0"
pyasn1-modules==0.3.0 ; python_version >= "3.11" and python_version < "4.0"
pyasn1==0.5.1 ; python_version >= "3.11" and python_version < "4.0"
pycparser==2.21 ; python_version >= "3.11" and python_version < "4.0"
pydantic-core==2.16.3 ; python_version >= "3.11" and python_version < "4.0"
pydantic-settings==2.2.1 ; python_version >= "3.11" and python_version < "4.0"
pydantic==2.6.3 ; python_version >= "3.11" and python_version < "4.0"
pyasn1-modules==0.4.0 ; python_version >= "3.11" and python_version < "4.0"
pyasn1==0.6.0 ; python_version >= "3.11" and python_version < "4.0"
pycparser==2.22 ; python_version >= "3.11" and python_version < "4.0"
pydantic-core==2.18.4 ; python_version >= "3.11" and python_version < "4.0"
pydantic-settings==2.3.3 ; python_version >= "3.11" and python_version < "4.0"
pydantic==2.7.4 ; python_version >= "3.11" and python_version < "4.0"
python-dotenv==1.0.1 ; python_version >= "3.11" and python_version < "4.0"
python-multipart==0.0.9 ; python_version >= "3.11" and python_version < "4.0"
pytz==2023.4 ; python_version >= "3.11" and python_version < "4.0"
requests==2.31.0 ; python_version >= "3.11" and python_version < "4.0"
requests==2.32.3 ; python_version >= "3.11" and python_version < "4.0"
rsa==4.9 ; python_version >= "3.11" and python_version < "4"
sniffio==1.3.1 ; python_version >= "3.11" and python_version < "4.0"
sqlalchemy-utils==0.41.1 ; python_version >= "3.11" and python_version < "4.0"
sqlalchemy==2.0.28 ; python_version >= "3.11" and python_version < "4.0"
sqlalchemy-utils==0.41.2 ; python_version >= "3.11" and python_version < "4.0"
sqlalchemy==2.0.31 ; python_version >= "3.11" and python_version < "4.0"
starlette==0.36.3 ; python_version >= "3.11" and python_version < "4.0"
typing-extensions==4.10.0 ; python_version >= "3.11" and python_version < "4.0"
typing-extensions==4.12.2 ; python_version >= "3.11" and python_version < "4.0"
unidecode==1.3.8 ; python_version >= "3.11" and python_version < "4.0"
urllib3==2.2.1 ; python_version >= "3.11" and python_version < "4.0"
urllib3==2.2.2 ; python_version >= "3.11" and python_version < "4.0"
uvicorn==0.25.0 ; python_version >= "3.11" and python_version < "4.0"

0 comments on commit c42d5d1

Please sign in to comment.