File size: 1,475 Bytes
919a48f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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),
]

@app.get("/", tags=["Get hello"])
def get_hello():
    return {'message': 'Hello!'}

@app.post("/", tags=["Post hello"])
def post_hello(name: str):
    return {'message': f"Hello {name}!"}

@app.get("/ranking", tags=["Ranking"], response_model=List[RankingData])
def get_ranking():
    """Returns dummy ranking data."""
    return ranking_data

@app.get("/userdata", tags=["User"], response_model=List[UserData])
def get_userdata():
    """Returns dummy user data."""
    return user_data