Spaces:
Sleeping
Sleeping
| from fastapi import FastAPI | |
| from pydantic import BaseModel, Field | |
| from typing import List | |
| app = FastAPI(title="This is test API. This API will return user game data.") | |
| # Dummy ranking data | |
| class RankingData(BaseModel): | |
| rank: int = Field(..., description="Ranking position") | |
| user_id: int = Field(..., description="User ID") | |
| score: int = Field(..., description="Score") | |
| ranking_data: List[RankingData] = [ | |
| RankingData(rank=1, user_id=123, score=10000), | |
| RankingData(rank=2, user_id=456, score=9000), | |
| RankingData(rank=3, user_id=789, score=8000), | |
| ] | |
| # Dummy user data | |
| class UserData(BaseModel): | |
| user_id: int = Field(..., description="User ID") | |
| user_name: str = Field(..., description="User Name") | |
| level: int = Field(..., description="Level") | |
| user_data: List[UserData] = [ | |
| UserData(user_id=123, user_name="Player1", level=50), | |
| UserData(user_id=456, user_name="Player2", level=45), | |
| UserData(user_id=789, user_name="Player3", level=40), | |
| ] | |
| def get_hello(): | |
| return {'message': 'Hello!'} | |
| def post_hello(name: str): | |
| return {'message': f"Hello {name}!"} | |
| def get_ranking(): | |
| """Returns dummy ranking data.""" | |
| return ranking_data | |
| def get_userdata(): | |
| """Returns dummy user data.""" | |
| return user_data | |