miya3333 commited on
Commit
919a48f
·
verified ·
1 Parent(s): 866d302

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +9 -0
  2. app.py +48 -0
  3. requirements.txt +4 -0
Dockerfile ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10.9
2
+
3
+ COPY . .
4
+
5
+ WORKDIR /
6
+
7
+ RUN pip install --no-cache-dir --upgrade -r /requirements.txt
8
+
9
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from pydantic import BaseModel, Field
3
+ from typing import List
4
+
5
+ app = FastAPI(title="This is test API. This API will return user game data.")
6
+
7
+ # Dummy ranking data
8
+ class RankingData(BaseModel):
9
+ rank: int = Field(..., description="Ranking position")
10
+ user_id: int = Field(..., description="User ID")
11
+ score: int = Field(..., description="Score")
12
+
13
+ ranking_data: List[RankingData] = [
14
+ RankingData(rank=1, user_id=123, score=10000),
15
+ RankingData(rank=2, user_id=456, score=9000),
16
+ RankingData(rank=3, user_id=789, score=8000),
17
+ ]
18
+
19
+ # Dummy user data
20
+ class UserData(BaseModel):
21
+ user_id: int = Field(..., description="User ID")
22
+ user_name: str = Field(..., description="User Name")
23
+ level: int = Field(..., description="Level")
24
+
25
+ user_data: List[UserData] = [
26
+ UserData(user_id=123, user_name="Player1", level=50),
27
+ UserData(user_id=456, user_name="Player2", level=45),
28
+ UserData(user_id=789, user_name="Player3", level=40),
29
+ ]
30
+
31
+ @app.get("/", tags=["Get hello"])
32
+ def get_hello():
33
+ return {'message': 'Hello!'}
34
+
35
+ @app.post("/", tags=["Post hello"])
36
+ def post_hello(name: str):
37
+ return {'message': f"Hello {name}!"}
38
+
39
+ @app.get("/ranking", tags=["Ranking"], response_model=List[RankingData])
40
+ def get_ranking():
41
+ """Returns dummy ranking data."""
42
+ return ranking_data
43
+
44
+ @app.get("/userdata", tags=["User"], response_model=List[UserData])
45
+ def get_userdata():
46
+ """Returns dummy user data."""
47
+ return user_data
48
+
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ fastapi==0.99.1
2
+ uvicorn
3
+ requests
4
+ pydantic==1.10.12