public endpoints
This commit is contained in:
@@ -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 CustomsSection
|
||||
from .dto import CustomsSectionDTO
|
||||
|
||||
@@ -18,7 +19,11 @@ def get_customs_section(customs_code: str, db: Session = Depends(get_core_db)):
|
||||
return obj
|
||||
|
||||
@router.post("/", response_model=CustomsSectionDTO, status_code=201)
|
||||
def create_customs_section(data: CustomsSectionDTO, db: Session = Depends(get_core_db)):
|
||||
def create_customs_section(
|
||||
data: CustomsSectionDTO,
|
||||
db: Session = Depends(get_core_db),
|
||||
current_user: dict = Depends(has_role("admin"))
|
||||
):
|
||||
obj = CustomsSection(**data.dict())
|
||||
db.add(obj)
|
||||
db.commit()
|
||||
@@ -26,7 +31,12 @@ def create_customs_section(data: CustomsSectionDTO, db: Session = Depends(get_co
|
||||
return obj
|
||||
|
||||
@router.put("/{customs_code}", response_model=CustomsSectionDTO)
|
||||
def update_customs_section(customs_code: str, data: CustomsSectionDTO, db: Session = Depends(get_core_db)):
|
||||
def update_customs_section(
|
||||
customs_code: str,
|
||||
data: CustomsSectionDTO,
|
||||
db: Session = Depends(get_core_db),
|
||||
current_user: dict = Depends(has_role("admin"))
|
||||
):
|
||||
obj = db.query(CustomsSection).filter(CustomsSection.customs_code == customs_code).first()
|
||||
if not obj:
|
||||
raise HTTPException(status_code=404, detail="Not found")
|
||||
@@ -37,7 +47,11 @@ def update_customs_section(customs_code: str, data: CustomsSectionDTO, db: Sessi
|
||||
return obj
|
||||
|
||||
@router.delete("/{customs_code}", status_code=204)
|
||||
def delete_customs_section(customs_code: str, db: Session = Depends(get_core_db)):
|
||||
def delete_customs_section(
|
||||
customs_code: str,
|
||||
db: Session = Depends(get_core_db),
|
||||
current_user: dict = Depends(has_role("admin"))
|
||||
):
|
||||
obj = db.query(CustomsSection).filter(CustomsSection.customs_code == customs_code).first()
|
||||
if not obj:
|
||||
raise HTTPException(status_code=404, detail="Not found")
|
||||
|
||||
Reference in New Issue
Block a user