Added ability to request plays of specific boardgame
This commit is contained in:
parent
c2e6e755c3
commit
9679aeb44d
2 changed files with 12 additions and 13 deletions
|
|
@ -6,3 +6,8 @@ def filter_out_expansion_plays(play_list: list[play_classes.Play]):
|
||||||
to_return_plays = list(filter(lambda x: x.expansion == None, play_list))
|
to_return_plays = list(filter(lambda x: x.expansion == None, play_list))
|
||||||
|
|
||||||
return to_return_plays
|
return to_return_plays
|
||||||
|
|
||||||
|
|
||||||
|
def filter_only_specific_boardgame(boardgame_id: int, play_list: list[play_classes.Play]):
|
||||||
|
|
||||||
|
return list(filter(lambda x: x.boardgame_id == boardgame_id or x.expansion_id == boardgame_id, play_list))
|
||||||
16
src/main.py
16
src/main.py
|
|
@ -17,7 +17,7 @@ def get_db_session():
|
||||||
@asynccontextmanager
|
@asynccontextmanager
|
||||||
async def lifespan(app: FastAPI):
|
async def lifespan(app: FastAPI):
|
||||||
# Startup
|
# Startup
|
||||||
data_connection.delete_database()
|
#data_connection.delete_database()
|
||||||
data_connection.create_db_and_tables()
|
data_connection.create_db_and_tables()
|
||||||
yield
|
yield
|
||||||
# Shutdown
|
# Shutdown
|
||||||
|
|
@ -79,20 +79,14 @@ def get_wishlist_collection(priority: int = 0, session: Session = Depends(get_db
|
||||||
|
|
||||||
|
|
||||||
@app.get("/plays", response_model=list[play_classes.PlayPublicWithPlayers])
|
@app.get("/plays", response_model=list[play_classes.PlayPublicWithPlayers])
|
||||||
def get_plays(session: Session = Depends(get_db_session)):
|
def get_plays(boardgame_id: int = -1, session: Session = Depends(get_db_session)):
|
||||||
|
|
||||||
requested_plays = data_connection.get_plays(session)[0:10]
|
requested_plays = data_connection.get_plays(session)
|
||||||
|
|
||||||
# all_played_boardgame_ids = []
|
|
||||||
|
|
||||||
# for play in requested_plays:
|
|
||||||
# if play.boardgame_id not in all_played_boardgame_ids:
|
|
||||||
# all_played_boardgame_ids.append(play.boardgame_id)
|
|
||||||
|
|
||||||
#all_played_boardgames = data_connection.get_multiple_boardgames(session, all_played_boardgame_ids)
|
|
||||||
|
|
||||||
requested_plays = play_filters.filter_out_expansion_plays(requested_plays)
|
requested_plays = play_filters.filter_out_expansion_plays(requested_plays)
|
||||||
|
|
||||||
|
if boardgame_id > -1:
|
||||||
|
requested_plays = play_filters.filter_only_specific_boardgame(boardgame_id, requested_plays)
|
||||||
|
|
||||||
return requested_plays
|
return requested_plays
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue