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