-
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 #8 from guivaloz:guivaloz/paths-exh
Guivaloz/paths-exh
- Loading branch information
Showing
24 changed files
with
372 additions
and
83 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
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
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 |
---|---|---|
@@ -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 |
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 |
---|---|---|
@@ -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 |
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,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 |
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 @@ | ||
""" | ||
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) |
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,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 |
Oops, something went wrong.