26 lines
559 B
Python
26 lines
559 B
Python
from fastapi import APIRouter, HTTPException, Depends
|
|
from ..models import Item
|
|
from ..database import get_db
|
|
from bson import ObjectId
|
|
|
|
router = APIRouter(
|
|
prefix="/items",
|
|
tags=["items"]
|
|
)
|
|
|
|
|
|
@router.post("/")
|
|
async def create_item(item: Item):
|
|
db = get_db()
|
|
result = db.items.insert_one(item.dict(by_alias=True))
|
|
return {"id": str(result.inserted_id)}
|
|
|
|
|
|
@router.get("/")
|
|
async def read_items():
|
|
db = get_db()
|
|
items = list(db.items.find())
|
|
return [Item(**item).dict(by_alias=True) for item in items]
|
|
|
|
# Add other item-related routes here
|