Skip to content

Commit

Permalink
Add an unauthenticated router as an example
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisLovering committed Aug 19, 2024
1 parent 5210cec commit dec7cf2
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions thallium-backend/src/routes/vouchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@
from src.orm import Voucher as DBVoucher
from src.settings import DBSession

router = APIRouter(
prefix="/vouchers",
tags=["Voucher users"],
dependencies=[Depends(TokenAuth(allow_vouchers=True))],
)
router = APIRouter(prefix="/vouchers", tags=["Voucher users"])
authenticated_router = APIRouter(dependencies=[Depends(TokenAuth(allow_vouchers=True))])
unauthenticated_router = APIRouter()

log = logging.getLogger(__name__)


@router.get("/me")
@authenticated_router.get("/me")
async def get_vouchers(request: Request, db: DBSession) -> Voucher | None:
"""Get the voucher for the currently authenticated voucher id."""
stmt = select(DBVoucher).where(DBVoucher.id == request.state.voucher_id)
res = await db.execute(stmt)
return res.scalars().one_or_none()


router.include_router(authenticated_router)
router.include_router(unauthenticated_router)

0 comments on commit dec7cf2

Please sign in to comment.