Get started on high score creation
This commit is contained in:
28
src/crud.py
28
src/crud.py
@@ -1,10 +1,11 @@
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from models import CourseProgress, HighScore, User
|
||||
from schemas.highscores import HighScoreCreate
|
||||
from schemas.users import UserCreate
|
||||
|
||||
|
||||
def get_user(db: Session, user_id: int):
|
||||
def get_user_by_id(db: Session, user_id: int):
|
||||
return db.query(User).filter(User.user_id == user_id).first()
|
||||
|
||||
|
||||
@@ -22,3 +23,28 @@ def create_user(db: Session, user: UserCreate):
|
||||
db.commit()
|
||||
db.refresh(db_user)
|
||||
return db_user
|
||||
|
||||
|
||||
def get_high_scores(db: Session):
|
||||
return db.query(HighScore).all()
|
||||
|
||||
|
||||
def create_high_score(db: Session, high_score: HighScoreCreate):
|
||||
db_high_score = HighScore(
|
||||
score_value=high_score.score_value,
|
||||
minigame=high_score.minigame,
|
||||
owner_id=high_score.owner_id,
|
||||
)
|
||||
db.add(db_high_score)
|
||||
db.commit()
|
||||
db.refresh(db_high_score)
|
||||
owner = get_user_by_id(db, high_score.owner_id)
|
||||
print("ID IS " + str(db_high_score.high_score_id) + " " + owner.username)
|
||||
owner.high_score_ids.append(db_high_score.high_score_id)
|
||||
owner.high_scores.append(db_high_score)
|
||||
print("LIST OF IDS: " + str(owner.high_score_ids))
|
||||
db.commit()
|
||||
db.refresh(owner)
|
||||
owner2 = db.query(User).filter(User.user_id == high_score.owner_id).first()
|
||||
print("LIST OF IDS: " + str(owner2.high_score_ids))
|
||||
return db_high_score
|
||||
|
||||
Reference in New Issue
Block a user