marley-ijf4of/endpoints/signup.post.py
2025-03-21 02:10:05 +00:00

71 lines
1.6 KiB
Python

from fastapi import APIRouter, Depends, HTTPException
from core.database import fake_users_db
import uuid
from typing import List, Optional
router = APIRouter()
@router.get("/cats")
async def get_cats(
limit: Optional[int] = 10,
offset: Optional[int] = 0
):
"""Get list of cats"""
cats = list(fake_users_db.get("cats", {}).values())
return {
"message": "Cats retrieved successfully",
"data": cats[offset:offset + limit],
"metadata": {
"total": len(cats),
"limit": limit,
"offset": offset
}
}
@router.get("/cats/{cat_id}")
async def get_cat(
cat_id: str
):
"""Get cat by ID"""
cat = fake_users_db.get("cats", {}).get(cat_id)
if not cat:
raise HTTPException(status_code=404, detail="Cat not found")
return {
"message": "Cat retrieved successfully",
"data": cat,
"metadata": {
"source": "demo_db",
"result_count": 1
}
}
@router.post("/cats")
async def create_cat(
name: str,
breed: str,
age: int
):
"""Create new cat"""
cat_id = str(uuid.uuid4())
if "cats" not in fake_users_db:
fake_users_db["cats"] = {}
new_cat = {
"id": cat_id,
"name": name,
"breed": breed,
"age": age
}
fake_users_db["cats"][cat_id] = new_cat
return {
"message": "Cat created successfully",
"data": new_cat,
"next_steps": [
"Add cat photo",
"Set feeding schedule"
]
}