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 ValuationMethod
from .dto import ValuationMethodDTO
@@ -18,7 +19,11 @@ def get_valuation_method(key: str, db: Session = Depends(get_core_db)):
return obj
@router.post("/", response_model=ValuationMethodDTO, status_code=201)
def create_valuation_method(data: ValuationMethodDTO, db: Session = Depends(get_core_db)):
def create_valuation_method(
data: ValuationMethodDTO,
db: Session = Depends(get_core_db),
current_user: dict = Depends(has_role("admin"))
):
obj = ValuationMethod(**data.dict())
db.add(obj)
db.commit()
@@ -26,7 +31,12 @@ def create_valuation_method(data: ValuationMethodDTO, db: Session = Depends(get_
return obj
@router.put("/{key}", response_model=ValuationMethodDTO)
def update_valuation_method(key: str, data: ValuationMethodDTO, db: Session = Depends(get_core_db)):
def update_valuation_method(
key: str,
data: ValuationMethodDTO,
db: Session = Depends(get_core_db),
current_user: dict = Depends(has_role("admin"))
):
obj = db.query(ValuationMethod).filter(ValuationMethod.key == key).first()
if not obj:
raise HTTPException(status_code=404, detail="Not found")
@@ -37,7 +47,11 @@ def update_valuation_method(key: str, data: ValuationMethodDTO, db: Session = De
return obj
@router.delete("/{key}", status_code=204)
def delete_valuation_method(key: str, db: Session = Depends(get_core_db)):
def delete_valuation_method(
key: str,
db: Session = Depends(get_core_db),
current_user: dict = Depends(has_role("admin"))
):
obj = db.query(ValuationMethod).filter(ValuationMethod.key == key).first()
if not obj:
raise HTTPException(status_code=404, detail="Not found")