-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: insert game moves into database
- Loading branch information
Showing
11 changed files
with
97 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from api.app.dto.base import CamelBaseModel | ||
from typing import List | ||
|
||
class InsertMoveRequest(CamelBaseModel): | ||
game_id: int | ||
user_id: int | ||
move_details: List[str] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
from .variants import Variants | ||
from .puzzle import Puzzle | ||
from .profile import Profile | ||
from .move import Move |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from sqlalchemy.orm import Session | ||
from sqlalchemy import select | ||
from api.app.model import Move | ||
from datetime import datetime | ||
from api.app.dto.core.insert_moves import InsertMoveRequest | ||
from fastapi import Depends | ||
from api.app.helper.db import db_session | ||
from api.app.model import Game | ||
|
||
|
||
async def insert_game_move(db: Session, request: InsertMoveRequest): | ||
for move_detail in request.move_details: | ||
move = Move(game_id=request.game_id, user_id=request.user_id, move_detail=move_detail, | ||
time_stamp=datetime.now()) | ||
db.add(move) | ||
db.commit() | ||
pass | ||
|
||
async def get_game_id_from_slug(db: Session, slug: str): | ||
statement = select(Game.id).where(Game.slug == slug) | ||
row = db.scalars(statement).one(); | ||
return row; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters