Fixed bug with retrieving single boardgame if table is not empty
This commit is contained in:
parent
fc551be2a4
commit
1ea7a24694
3 changed files with 5 additions and 5 deletions
|
|
@ -57,7 +57,7 @@ def read_root():
|
|||
|
||||
@app.get("/boardgame", response_model=Union[boardgame_classes.BoardGame, boardgame_classes.BoardGameExpansion])
|
||||
def get_boardgame_by_id(id: int, session: Session = Depends(get_db_session)):
|
||||
requested_boardgame: Union[boardgame_classes.BoardGame, boardgame_classes.BoardGameExpansion] = data_connection.get_boardgame(session, boardgame_classes.BoardGame, id)
|
||||
requested_boardgame: Union[boardgame_classes.BoardGame, boardgame_classes.BoardGameExpansion] = data_connection.get_boardgame(session, id)
|
||||
return requested_boardgame
|
||||
|
||||
@app.get("/owned", response_model=list[Union[boardgame_classes.OwnedBoardGame, boardgame_classes.OwnedBoardGameExpansion]])
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ from src.classes import boardgame_classes, play_classes
|
|||
def get_db_session():
|
||||
return db_connection.get_session()
|
||||
|
||||
def get_boardgame(session: Session, boardgame_type: SQLModel, boardgame_id: int) -> boardgame_classes.BoardGame:
|
||||
def get_boardgame(session: Session, boardgame_id: int) -> boardgame_classes.BoardGame:
|
||||
#Will check if it already exists in db, then it will get it from there
|
||||
|
||||
boardgame_in_db = db_connection.get_boardgame(session, boardgame_id=boardgame_id)
|
||||
|
|
|
|||
|
|
@ -46,11 +46,11 @@ def add_multiple_boardgames(session: Session, boardgame_list: list[Union[
|
|||
def get_boardgame(session: Session, boardgame_id: int) -> Union[
|
||||
boardgame_classes.BoardGame, boardgame_classes.BoardGameExpansion]:
|
||||
|
||||
statement = select(boardgame_classes.BoardGame)
|
||||
statement = select(boardgame_classes.BoardGame).where(boardgame_classes.BoardGame.id == boardgame_id)
|
||||
|
||||
base_boardgames = session.exec(statement).all()
|
||||
|
||||
statement = select(boardgame_classes.BoardGameExpansion)
|
||||
statement = select(boardgame_classes.BoardGameExpansion).where(boardgame_classes.BoardGameExpansion.id == boardgame_id)
|
||||
|
||||
expansion_boardgames = session.exec(statement).all()
|
||||
|
||||
|
|
@ -59,7 +59,7 @@ def get_boardgame(session: Session, boardgame_id: int) -> Union[
|
|||
if len(returned_boardgames) == 0:
|
||||
boardgame = None
|
||||
else:
|
||||
boardgame = list(filter(lambda boardgame: boardgame.id == boardgame_id, returned_boardgames))[0]
|
||||
boardgame = returned_boardgames[0]
|
||||
|
||||
return boardgame
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue