diff --git a/endpoints/cats.post.py b/endpoints/cats.post.py index e69de29..bf22978 100644 --- a/endpoints/cats.post.py +++ b/endpoints/cats.post.py @@ -0,0 +1,36 @@ +from fastapi import APIRouter, Depends, HTTPException +from core.database import fake_users_db +import uuid + +router = APIRouter() + +@router.post("/cats") +async def create_cat( + name: str, + breed: str, + age: int, + db: Session = Depends(get_db), + token: str = Depends(oauth2_scheme) +): + """Create a new cat""" + user = get_current_user(token, db) + if not user: + raise HTTPException(status_code=401, detail="Invalid authentication credentials") + + cat_id = str(uuid.uuid4()) + new_cat = { + "id": cat_id, + "name": name, + "breed": breed, + "age": age, + "owner_id": user.id + } + fake_users_db[user.id]["cats"].append(new_cat) + + return { + "message": "Cat created successfully", + "data": new_cat, + "metadata": { + "owner": user.username + } + } \ No newline at end of file