lqs
d20566fe07
Some checks failed
Test / lint (push) Has been cancelled
Test / test (pydantic-v1, 3.10) (push) Has been cancelled
Test / test (pydantic-v1, 3.11) (push) Has been cancelled
Test / test (pydantic-v1, 3.12) (push) Has been cancelled
Test / test (pydantic-v1, 3.8) (push) Has been cancelled
Test / test (pydantic-v1, 3.9) (push) Has been cancelled
Test / test (pydantic-v2, 3.10) (push) Has been cancelled
Test / test (pydantic-v2, 3.11) (push) Has been cancelled
Test / test (pydantic-v2, 3.12) (push) Has been cancelled
Test / test (pydantic-v2, 3.8) (push) Has been cancelled
Test / test (pydantic-v2, 3.9) (push) Has been cancelled
Test / coverage-combine (push) Has been cancelled
Test / check (push) Has been cancelled
Issue Manager / issue-manager (push) Has been cancelled
Label Approved / label-approved (push) Has been cancelled
39 lines
1011 B
Python
39 lines
1011 B
Python
from fastapi import APIRouter, Depends, HTTPException
|
|
|
|
from ..dependencies import get_token_header
|
|
|
|
router = APIRouter(
|
|
prefix="/items",
|
|
tags=["items"],
|
|
dependencies=[Depends(get_token_header)],
|
|
responses={404: {"description": "Not found"}},
|
|
)
|
|
|
|
|
|
fake_items_db = {"plumbus": {"name": "Plumbus"}, "gun": {"name": "Portal Gun"}}
|
|
|
|
|
|
@router.get("/")
|
|
async def read_items():
|
|
return fake_items_db
|
|
|
|
|
|
@router.get("/{item_id}")
|
|
async def read_item(item_id: str):
|
|
if item_id not in fake_items_db:
|
|
raise HTTPException(status_code=404, detail="Item not found")
|
|
return {"name": fake_items_db[item_id]["name"], "item_id": item_id}
|
|
|
|
|
|
@router.put(
|
|
"/{item_id}",
|
|
tags=["custom"],
|
|
responses={403: {"description": "Operation forbidden"}},
|
|
)
|
|
async def update_item(item_id: str):
|
|
if item_id != "plumbus":
|
|
raise HTTPException(
|
|
status_code=403, detail="You can only update the item: plumbus"
|
|
)
|
|
return {"item_id": item_id, "name": "The great Plumbus"}
|