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
|
"acquired_from" : acquired_from
|
||||||
}
|
}
|
||||||
|
|
||||||
boardgame_dict = {
|
|
||||||
**boardgame_extra_info.__dict__,
|
|
||||||
**owned_boardgame_dict
|
|
||||||
}
|
|
||||||
|
|
||||||
owned_info = boardgame_classes.OwnedInfo.model_validate(owned_boardgame_dict)
|
owned_info = boardgame_classes.OwnedInfo.model_validate(owned_boardgame_dict)
|
||||||
|
|
||||||
boardgame_extra_info.owned_info = owned_info
|
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,
|
"wishlist_priority" : wishlist_priority,
|
||||||
}
|
}
|
||||||
|
|
||||||
boardgame_dict = {
|
wishlist_info = boardgame_classes.WishlistInfo.model_validate(wishlist_boardgame_dict)
|
||||||
**boardgame_extra_info.__dict__,
|
|
||||||
**wishlist_boardgame_dict
|
|
||||||
}
|
|
||||||
|
|
||||||
match boardgame_type:
|
boardgame_extra_info.wishlist_info = wishlist_info
|
||||||
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_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
|
return boardgame
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,18 +40,16 @@ def get_multiple_boardgames(session: Session, boardgame_ids: list[int]) -> list[
|
||||||
return boardgames_in_db
|
return boardgames_in_db
|
||||||
|
|
||||||
def get_user_collection(session: Session) -> list[boardgame_classes.BoardGame]:
|
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()
|
boardgames = bgg_connection.get_user_collection()
|
||||||
|
|
||||||
#db_connection.add_boardgame(session, boardgame)
|
|
||||||
db_connection.add_multiple_boardgames(session, boardgames)
|
db_connection.add_multiple_boardgames(session, boardgames)
|
||||||
|
|
||||||
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)
|
||||||
#boardgame_expansions_from_db: list[boardgame_classes.BoardGameExpansion] = db_connection.get_all_boardgames(session, boardgame_classes.BoardGameExpansion)
|
|
||||||
|
|
||||||
return boardgames_from_db # + boardgame_expansions_from_db
|
return boardgames_from_db
|
||||||
|
|
||||||
def get_user_owned_collection(session: Session) -> list[boardgame_classes.BoardGame]:
|
def get_user_owned_collection(session: Session) -> list[boardgame_classes.BoardGame]:
|
||||||
|
|
||||||
|
|
@ -64,23 +62,22 @@ def get_user_owned_collection(session: Session) -> list[boardgame_classes.BoardG
|
||||||
owned_boardgames_from_db: list[boardgame_classes.BoardGame] = db_connection.get_owned_boardgames(session)
|
owned_boardgames_from_db: list[boardgame_classes.BoardGame] = db_connection.get_owned_boardgames(session)
|
||||||
|
|
||||||
return owned_boardgames_from_db
|
return owned_boardgames_from_db
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_user_wishlist_collection(session: Session, wishlist_priority: int = 0) -> list[boardgame_classes.BoardGame]:
|
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:
|
if len(wishlisted_boardgames_from_db) == 0:
|
||||||
wishlisted_boardgames = bgg_connection.get_user_wishlist_collection()
|
wishlisted_boardgames = bgg_connection.get_user_wishlist_collection()
|
||||||
db_connection.add_multiple_boardgames(session, wishlisted_boardgames)
|
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
|
to_return_boardgames = wishlisted_boardgames_from_db
|
||||||
|
|
||||||
if wishlist_priority != 0:
|
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
|
return to_return_boardgames
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ def add_boardgame(session: Session, boardgame: boardgame_classes.BoardGame):
|
||||||
boardgame.designers[designer_index] = designer_in_db
|
boardgame.designers[designer_index] = designer_in_db
|
||||||
|
|
||||||
is_boardgame_present = len(session.exec(
|
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
|
).all()) != 0
|
||||||
|
|
||||||
if not is_boardgame_present:
|
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()
|
base_boardgames = session.exec(statement).all()
|
||||||
|
|
||||||
# statement = select(boardgame_classes.BoardGameExpansion).where(boardgame_classes.BoardGameExpansion.id == boardgame_id)
|
returned_boardgames = base_boardgames
|
||||||
|
|
||||||
# expansion_boardgames = session.exec(statement).all()
|
|
||||||
|
|
||||||
returned_boardgames = base_boardgames # + expansion_boardgames
|
|
||||||
|
|
||||||
if len(returned_boardgames) == 0:
|
if len(returned_boardgames) == 0:
|
||||||
boardgame = None
|
boardgame = None
|
||||||
|
|
@ -122,6 +118,16 @@ def get_multiple_boardgames(session: Session, boardgame_ids: list[int]) -> tuple
|
||||||
|
|
||||||
return boardgames, missing_boardgame_ids
|
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]:
|
def get_owned_boardgames(session: Session) -> list[boardgame_classes.BoardGame]:
|
||||||
statement = select(boardgame_classes.OwnedInfo)
|
statement = select(boardgame_classes.OwnedInfo)
|
||||||
results = session.exec(statement)
|
results = session.exec(statement)
|
||||||
|
|
@ -130,15 +136,14 @@ def get_owned_boardgames(session: Session) -> list[boardgame_classes.BoardGame]:
|
||||||
|
|
||||||
return owned_boardgames
|
return owned_boardgames
|
||||||
|
|
||||||
def get_all_boardgames(session: Session, boardgame_type: SQLModel) -> list[boardgame_classes.BoardGame]:
|
def get_wishlist_boardgames(session: Session) -> list[boardgame_classes.BoardGame]:
|
||||||
|
statement = select(boardgame_classes.WishlistInfo)
|
||||||
statement = select(boardgame_type)
|
|
||||||
|
|
||||||
results = session.exec(statement)
|
results = session.exec(statement)
|
||||||
|
|
||||||
boardgame_list = results.all()
|
|
||||||
|
|
||||||
return boardgame_list
|
wishlisted_boardgames = [wishlist_info.boardgame for wishlist_info in results.all()]
|
||||||
|
|
||||||
|
return wishlisted_boardgames
|
||||||
|
|
||||||
|
|
||||||
def add_play(session: Session, play: play_classes.Play):
|
def add_play(session: Session, play: play_classes.Play):
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue