More refactors
This commit is contained in:
23
src/main.py
23
src/main.py
@@ -9,10 +9,11 @@ sys.path.append("..")
|
||||
from src.crud import authentication as crud_authentication
|
||||
from src.crud import courseprogress as crud_courseprogress
|
||||
from src.crud import highscores as crud_highscores
|
||||
from src.crud import saved_data as crud_saved_data
|
||||
from src.crud import users as crud_users
|
||||
from src.database import Base, engine, get_db
|
||||
from src.enums import CourseEnum, MinigameEnum
|
||||
from src.schemas import courseprogress, highscores, users
|
||||
from src.schemas import courseprogress, highscores, users, saved_data
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
@@ -46,6 +47,13 @@ async def patch_current_user(
|
||||
crud_users.patch_user(db, current_user_name, user)
|
||||
|
||||
|
||||
@app.get("/saveddata", response_model=saved_data.SavedUser)
|
||||
async def read_saved_data(
|
||||
current_user_name: str = Depends(crud_authentication.get_current_user_name),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
return crud_saved_data.get_saved_data(db, current_user_name)
|
||||
|
||||
@app.post("/register")
|
||||
async def register(user: users.UserCreate, db: Session = Depends(get_db)):
|
||||
access_token = crud_authentication.register(
|
||||
@@ -61,18 +69,21 @@ async def login(user: users.UserCreate, db: Session = Depends(get_db)):
|
||||
return crud_authentication.login(db, user.username, user.password)
|
||||
|
||||
|
||||
@app.get("/highscores/{minigame}", response_model=List[users.UserHighScore])
|
||||
@app.get("/highscores/{minigame}", response_model=List[highscores.Score])
|
||||
async def get_high_scores(
|
||||
minigame: MinigameEnum,
|
||||
nr_highest: Optional[int] = 1,
|
||||
amount: Optional[int] = 1,
|
||||
mine_only: Optional[bool] = True,
|
||||
most_recent: Optional[bool] = False,
|
||||
current_user_name: str = Depends(crud_authentication.get_current_user_name),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
print(str(nr_highest))
|
||||
print(str(mine_only))
|
||||
if most_recent:
|
||||
return crud_highscores.get_most_recent_high_scores(db, minigame, amount)
|
||||
user = crud_users.get_user_by_username(db, current_user_name)
|
||||
return crud_highscores.get_high_scores(db, minigame, user, nr_highest, mine_only)
|
||||
return crud_highscores.get_highest_high_scores(
|
||||
db, minigame, user, amount, mine_only
|
||||
)
|
||||
|
||||
|
||||
@app.put("/highscores/{minigame}", response_model=highscores.HighScore)
|
||||
|
||||
Reference in New Issue
Block a user