feat: Implement SITAR modules for PROSEC, RCG2, Regulaciones, REIT, RequisitoPrevio, TLCS, and Vehiculos
- Added schemas, services, and routers for PROSEC, RCG2, Regulaciones, REIT, RequisitoPrevio, TLCS, and Vehiculos modules. - Each module includes search and get by ID functionalities. - Integrated FastAPI routers for each module into the main SITAR router. - Ensured proper response models using Pydantic for data validation.
This commit is contained in:
7
backend/api/v1/modules/sitar/reit/__init__.py
Normal file
7
backend/api/v1/modules/sitar/reit/__init__.py
Normal file
@@ -0,0 +1,7 @@
|
||||
"""Reit Module"""
|
||||
|
||||
from .schemas import ReitResponse
|
||||
from .service import ReitService
|
||||
from .router import router
|
||||
|
||||
__all__ = ["ReitResponse", "ReitService", "router"]
|
||||
34
backend/api/v1/modules/sitar/reit/router.py
Normal file
34
backend/api/v1/modules/sitar/reit/router.py
Normal file
@@ -0,0 +1,34 @@
|
||||
"""Reit Router"""
|
||||
|
||||
from typing import Optional, List
|
||||
from fastapi import APIRouter, HTTPException, Query, Depends
|
||||
from core.security import get_current_user
|
||||
from .service import ReitService
|
||||
from .schemas import ReitResponse
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/", response_model=List[ReitResponse])
|
||||
async def search(
|
||||
fraccion: Optional[str] = Query(None),
|
||||
nico: Optional[str] = Query(None),
|
||||
skip: int = Query(0, ge=0),
|
||||
limit: int = Query(100, ge=1, le=1000),
|
||||
current_user: dict = Depends(get_current_user),
|
||||
):
|
||||
try:
|
||||
service = ReitService.get_instance()
|
||||
return await service.search(
|
||||
fraccion=fraccion, nico=nico, skip=skip, limit=limit
|
||||
)
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
@router.get("/{sysid}", response_model=ReitResponse)
|
||||
async def get_by_id(sysid: int, current_user: dict = Depends(get_current_user)):
|
||||
try:
|
||||
return await ReitService.get_instance().get_by_id(sysid)
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
25
backend/api/v1/modules/sitar/reit/schemas.py
Normal file
25
backend/api/v1/modules/sitar/reit/schemas.py
Normal file
@@ -0,0 +1,25 @@
|
||||
"""REIT Schemas"""
|
||||
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class ReitResponse(BaseModel):
|
||||
"""Registro de Empresas de Industria Terminal"""
|
||||
|
||||
FRACCION: Optional[str] = Field(None, max_length=10)
|
||||
ARTICULO: Optional[str] = Field(None, max_length=50)
|
||||
FUNDAMENTO: Optional[str] = Field(None, max_length=1500)
|
||||
ACUERDO: Optional[str] = Field(None, max_length=500)
|
||||
PERMISO: Optional[str] = Field(None, max_length=2)
|
||||
DOF: Optional[str] = Field(None, max_length=8)
|
||||
DOCUMENTO: Optional[str] = Field(None, max_length=200)
|
||||
TEMPORALIDAD: Optional[int] = None
|
||||
TEMPORALIDADSERVICIO: Optional[int] = None
|
||||
TEMPORALIDADCERTIFICADA: Optional[int] = None
|
||||
WEB_DOCUMENTO_ID: Optional[int] = None
|
||||
NICO: Optional[str] = Field("", max_length=2)
|
||||
SYSID: int
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
34
backend/api/v1/modules/sitar/reit/service.py
Normal file
34
backend/api/v1/modules/sitar/reit/service.py
Normal file
@@ -0,0 +1,34 @@
|
||||
"""Reit Service"""
|
||||
|
||||
from typing import Optional, List
|
||||
from ..common import SitarAPIBaseService
|
||||
from .schemas import ReitResponse
|
||||
|
||||
|
||||
class ReitService(SitarAPIBaseService):
|
||||
_instance: Optional["ReitService"] = None
|
||||
|
||||
@classmethod
|
||||
def get_instance(cls) -> "ReitService":
|
||||
if cls._instance is None:
|
||||
cls._instance = cls()
|
||||
return cls._instance
|
||||
|
||||
async def search(
|
||||
self,
|
||||
fraccion: Optional[str] = None,
|
||||
nico: Optional[str] = None,
|
||||
skip: int = 0,
|
||||
limit: int = 100,
|
||||
) -> List[ReitResponse]:
|
||||
params = {"skip": skip, "limit": min(limit, 1000)}
|
||||
if fraccion:
|
||||
params["fraccion"] = fraccion
|
||||
if nico:
|
||||
params["nico"] = nico
|
||||
data = await self._make_request("GET", "/api/v1/reit/", params=params)
|
||||
return [ReitResponse(**item) for item in data]
|
||||
|
||||
async def get_by_id(self, sysid: int) -> ReitResponse:
|
||||
data = await self._make_request("GET", f"/api/v1/reit/{sysid}")
|
||||
return ReitResponse(**data)
|
||||
Reference in New Issue
Block a user