public endpoints

This commit is contained in:
2025-11-01 11:33:40 -06:00
parent 0aa5fc72fd
commit e8294af60d
21 changed files with 297 additions and 57 deletions

View File

@@ -1,6 +1,7 @@
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
from core.database import get_core_db
from core.security import has_role
from .models import PedimentoCode
from .dto import PedimentoCodeDTO
@@ -18,7 +19,11 @@ def get_pedimento_code(code: str, db: Session = Depends(get_core_db)):
return obj
@router.post("/", response_model=PedimentoCodeDTO, status_code=201)
def create_pedimento_code(data: PedimentoCodeDTO, db: Session = Depends(get_core_db)):
def create_pedimento_code(
data: PedimentoCodeDTO,
db: Session = Depends(get_core_db),
current_user: dict = Depends(has_role("admin"))
):
obj = PedimentoCode(**data.dict())
db.add(obj)
db.commit()
@@ -26,7 +31,12 @@ def create_pedimento_code(data: PedimentoCodeDTO, db: Session = Depends(get_core
return obj
@router.put("/{code}", response_model=PedimentoCodeDTO)
def update_pedimento_code(code: str, data: PedimentoCodeDTO, db: Session = Depends(get_core_db)):
def update_pedimento_code(
code: str,
data: PedimentoCodeDTO,
db: Session = Depends(get_core_db),
current_user: dict = Depends(has_role("admin"))
):
obj = db.query(PedimentoCode).filter(PedimentoCode.code == code).first()
if not obj:
raise HTTPException(status_code=404, detail="Not found")
@@ -37,7 +47,11 @@ def update_pedimento_code(code: str, data: PedimentoCodeDTO, db: Session = Depen
return obj
@router.delete("/{code}", status_code=204)
def delete_pedimento_code(code: str, db: Session = Depends(get_core_db)):
def delete_pedimento_code(
code: str,
db: Session = Depends(get_core_db),
current_user: dict = Depends(has_role("admin"))
):
obj = db.query(PedimentoCode).filter(PedimentoCode.code == code).first()
if not obj:
raise HTTPException(status_code=404, detail="Not found")