bgg_api/src/modules/data_connection.py

53 lines
1.9 KiB
Python
Raw Normal View History

2024-08-08 18:41:18 +02:00
from typing import Union
from src.modules import bgg_connection, db_connection
from src.classes import boardgame_classes, play_classes
def get_boardgame(boardgame_id: int) -> boardgame_classes.BoardGame:
#Will check if it already exists in db, then it will get it from there
boardgame_in_db: list[boardgame_classes.BoardGame] = db_connection.get_base_boardgames(boardgame_id=boardgame_id)
to_return_boardgame = None
if len(boardgame_in_db) != 0:
to_return_boardgame = boardgame_in_db[0]
else:
to_return_boardgame = bgg_connection.get_boardgame(boardgame_id)
db_connection.add_boardgame(to_return_boardgame)
return to_return_boardgame
2024-08-08 18:41:18 +02:00
def get_user_owned_collection() -> list[Union[boardgame_classes.OwnedBoardGame, boardgame_classes.OwnedBoardGameExpansion]]:
owned_boardgames_from_db = db_connection.get_all_owned_boardgames()
2024-08-08 18:41:18 +02:00
owned_boardgame_expanions_from_db = db_connection.get_all_owned_boardgames_expansions()
2024-08-08 18:41:18 +02:00
boardgames_to_return = []
if len(owned_boardgames_from_db) == 0 and len(owned_boardgame_expanions_from_db) == 0:
owned_boardgames = bgg_connection.get_user_owned_collection()
for boardgame in owned_boardgames:
db_connection.add_boardgame(boardgame)
return owned_boardgames
2024-08-08 18:41:18 +02:00
else:
return owned_boardgames_from_db
def get_user_wishlist_collection(wishlist_priority: int = 0) -> Union[list[boardgame_classes.WishlistBoardGame], list[boardgame_classes.WishlistBoardGameExpansion]]:
owned_boardgames_from_db = db_connection.get_all_wishlisted_boardgames
return bgg_connection.get_user_wishlist_collection(wishlist_priority)
def get_plays() -> list[play_classes.Play]:
return bgg_connection.get_plays()
2024-08-08 16:50:52 +02:00
def delete_database():
db_connection.delete_database()
def create_db_and_tables():
db_connection.create_db_and_tables()