Made wishlist work with refactored changes
This commit is contained in:
parent
9181f5a601
commit
929e45380b
3 changed files with 40 additions and 39 deletions
|
|
@ -148,11 +148,6 @@ def convert_collection_xml_to_owned_boardgame(boardgame_extra_info: boardgame_cl
|
|||
"acquired_from" : acquired_from
|
||||
}
|
||||
|
||||
boardgame_dict = {
|
||||
**boardgame_extra_info.__dict__,
|
||||
**owned_boardgame_dict
|
||||
}
|
||||
|
||||
owned_info = boardgame_classes.OwnedInfo.model_validate(owned_boardgame_dict)
|
||||
|
||||
boardgame_extra_info.owned_info = owned_info
|
||||
|
|
@ -179,19 +174,23 @@ def convert_collection_xml_to_wishlist_boardgame(boardgame_extra_info: boardgame
|
|||
"wishlist_priority" : wishlist_priority,
|
||||
}
|
||||
|
||||
boardgame_dict = {
|
||||
**boardgame_extra_info.__dict__,
|
||||
**wishlist_boardgame_dict
|
||||
}
|
||||
wishlist_info = boardgame_classes.WishlistInfo.model_validate(wishlist_boardgame_dict)
|
||||
|
||||
match boardgame_type:
|
||||
case "boardgame":
|
||||
boardgame = boardgame_classes.WishlistBoardGame(**boardgame_dict)
|
||||
case "boardgameexpansion":
|
||||
boardgame_dict['expansion_for'] = boardgame_extra_info.expansion_for
|
||||
boardgame = boardgame_classes.WishlistBoardGameExpansion(**boardgame_dict)
|
||||
boardgame_extra_info.wishlist_info = wishlist_info
|
||||
|
||||
# boardgame_dict = {
|
||||
# **boardgame_extra_info.__dict__,
|
||||
# **wishlist_boardgame_dict
|
||||
# }
|
||||
|
||||
# match boardgame_type:
|
||||
# case "boardgame":
|
||||
# boardgame = boardgame_classes.WishlistBoardGame(**boardgame_dict)
|
||||
# case "boardgameexpansion":
|
||||
# boardgame_dict['expansion_for'] = boardgame_extra_info.expansion_for
|
||||
# boardgame = boardgame_classes.WishlistBoardGameExpansion(**boardgame_dict)
|
||||
|
||||
boardgame = boardgame_extra_info
|
||||
|
||||
return boardgame
|
||||
|
||||
|
|
|
|||
|
|
@ -40,18 +40,16 @@ def get_multiple_boardgames(session: Session, boardgame_ids: list[int]) -> list[
|
|||
return boardgames_in_db
|
||||
|
||||
def get_user_collection(session: Session) -> list[boardgame_classes.BoardGame]:
|
||||
boardgames_from_db: list[boardgame_classes.BoardGame] = db_connection.get_all_boardgames(session, boardgame_classes.BoardGame)
|
||||
boardgames_from_db: list[boardgame_classes.BoardGame] = db_connection.get_all_boardgames(session)
|
||||
|
||||
if len(boardgames_from_db) == 0: # and len(boardgame_expansions_from_db) == 0:
|
||||
if len(boardgames_from_db) == 0:
|
||||
boardgames = bgg_connection.get_user_collection()
|
||||
|
||||
#db_connection.add_boardgame(session, boardgame)
|
||||
db_connection.add_multiple_boardgames(session, boardgames)
|
||||
|
||||
boardgames_from_db: list[boardgame_classes.BoardGame] = db_connection.get_all_boardgames(session, boardgame_classes.BoardGame)
|
||||
#boardgame_expansions_from_db: list[boardgame_classes.BoardGameExpansion] = db_connection.get_all_boardgames(session, boardgame_classes.BoardGameExpansion)
|
||||
boardgames_from_db: list[boardgame_classes.BoardGame] = db_connection.get_all_boardgames(session)
|
||||
|
||||
return boardgames_from_db # + boardgame_expansions_from_db
|
||||
return boardgames_from_db
|
||||
|
||||
def get_user_owned_collection(session: Session) -> list[boardgame_classes.BoardGame]:
|
||||
|
||||
|
|
@ -66,21 +64,20 @@ def get_user_owned_collection(session: Session) -> list[boardgame_classes.BoardG
|
|||
return owned_boardgames_from_db
|
||||
|
||||
|
||||
|
||||
def get_user_wishlist_collection(session: Session, wishlist_priority: int = 0) -> list[boardgame_classes.BoardGame]:
|
||||
|
||||
wishlisted_boardgames_from_db = db_connection.get_all_boardgames(session, boardgame_classes.BoardGame)
|
||||
wishlisted_boardgames_from_db = db_connection.get_wishlist_boardgames(session)
|
||||
|
||||
if len(wishlisted_boardgames_from_db) == 0:
|
||||
wishlisted_boardgames = bgg_connection.get_user_wishlist_collection()
|
||||
db_connection.add_multiple_boardgames(session, wishlisted_boardgames)
|
||||
|
||||
wishlisted_boardgames_from_db = db_connection.get_all_boardgames(session, boardgame_classes.BoardGame)
|
||||
wishlisted_boardgames_from_db = db_connection.get_wishlist_boardgames(session)
|
||||
|
||||
to_return_boardgames = wishlisted_boardgames_from_db
|
||||
|
||||
if wishlist_priority != 0:
|
||||
to_return_boardgames = list(filter(lambda game: game.wishlist_priority == wishlist_priority, to_return_boardgames))
|
||||
to_return_boardgames = list(filter(lambda game: game.wishlist_info.wishlist_priority == wishlist_priority, to_return_boardgames))
|
||||
|
||||
return to_return_boardgames
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ def add_boardgame(session: Session, boardgame: boardgame_classes.BoardGame):
|
|||
boardgame.designers[designer_index] = designer_in_db
|
||||
|
||||
is_boardgame_present = len(session.exec(
|
||||
select(boardgame.__class__).where(boardgame.__class__.id == boardgame.id)
|
||||
select(boardgame_classes.BoardGame).where(boardgame_classes.BoardGame.id == boardgame.id)
|
||||
).all()) != 0
|
||||
|
||||
if not is_boardgame_present:
|
||||
|
|
@ -91,11 +91,7 @@ def get_boardgame(session: Session, boardgame_id: int) -> boardgame_classes.Boar
|
|||
|
||||
base_boardgames = session.exec(statement).all()
|
||||
|
||||
# statement = select(boardgame_classes.BoardGameExpansion).where(boardgame_classes.BoardGameExpansion.id == boardgame_id)
|
||||
|
||||
# expansion_boardgames = session.exec(statement).all()
|
||||
|
||||
returned_boardgames = base_boardgames # + expansion_boardgames
|
||||
returned_boardgames = base_boardgames
|
||||
|
||||
if len(returned_boardgames) == 0:
|
||||
boardgame = None
|
||||
|
|
@ -122,6 +118,16 @@ def get_multiple_boardgames(session: Session, boardgame_ids: list[int]) -> tuple
|
|||
|
||||
return boardgames, missing_boardgame_ids
|
||||
|
||||
def get_all_boardgames(session: Session) -> list[boardgame_classes.BoardGame]:
|
||||
|
||||
statement = select(boardgame_classes.BoardGame)
|
||||
|
||||
results = session.exec(statement)
|
||||
|
||||
boardgame_list = results.all()
|
||||
|
||||
return boardgame_list
|
||||
|
||||
def get_owned_boardgames(session: Session) -> list[boardgame_classes.BoardGame]:
|
||||
statement = select(boardgame_classes.OwnedInfo)
|
||||
results = session.exec(statement)
|
||||
|
|
@ -130,15 +136,14 @@ def get_owned_boardgames(session: Session) -> list[boardgame_classes.BoardGame]:
|
|||
|
||||
return owned_boardgames
|
||||
|
||||
def get_all_boardgames(session: Session, boardgame_type: SQLModel) -> list[boardgame_classes.BoardGame]:
|
||||
|
||||
statement = select(boardgame_type)
|
||||
|
||||
def get_wishlist_boardgames(session: Session) -> list[boardgame_classes.BoardGame]:
|
||||
statement = select(boardgame_classes.WishlistInfo)
|
||||
results = session.exec(statement)
|
||||
|
||||
boardgame_list = results.all()
|
||||
wishlisted_boardgames = [wishlist_info.boardgame for wishlist_info in results.all()]
|
||||
|
||||
return wishlisted_boardgames
|
||||
|
||||
return boardgame_list
|
||||
|
||||
def add_play(session: Session, play: play_classes.Play):
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue