Created ability to add board games to db
This commit is contained in:
parent
1ad9985377
commit
dfec34acc7
2 changed files with 33 additions and 3 deletions
|
|
@ -10,8 +10,12 @@ def get_boardgame(boardgame_id: int) -> boardgame_classes.BoardGame:
|
||||||
|
|
||||||
|
|
||||||
def get_user_owned_collection() -> list[boardgame_classes.BoardGame]:
|
def get_user_owned_collection() -> list[boardgame_classes.BoardGame]:
|
||||||
|
owned_boardgames_from_db = db_connection.get_all_owned_boardgames()
|
||||||
|
|
||||||
return bgg_connection.get_user_owned_collection()
|
if len(owned_boardgames_from_db) != 0:
|
||||||
|
return owned_boardgames_from_db
|
||||||
|
else:
|
||||||
|
return bgg_connection.get_user_owned_collection()
|
||||||
|
|
||||||
|
|
||||||
def get_user_wishlist_collection() -> list[boardgame_classes.BoardGame]:
|
def get_user_wishlist_collection() -> list[boardgame_classes.BoardGame]:
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
from sqlmodel import create_engine, SQLModel
|
from sqlmodel import create_engine, SQLModel, Session, select
|
||||||
from src.config import definitions
|
from src.config import definitions
|
||||||
import os
|
import os
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
|
from src.classes import boardgame_classes
|
||||||
|
|
||||||
sqlite_url = definitions.SQLITE_URL
|
sqlite_url = definitions.SQLITE_URL
|
||||||
|
|
||||||
|
|
@ -8,6 +11,29 @@ sqlite_url = definitions.SQLITE_URL
|
||||||
connect_args = {"check_same_thread": False}
|
connect_args = {"check_same_thread": False}
|
||||||
engine = create_engine(sqlite_url, echo=True, connect_args=connect_args)
|
engine = create_engine(sqlite_url, echo=True, connect_args=connect_args)
|
||||||
|
|
||||||
|
def add_boardgame(boardgame: Union[
|
||||||
|
boardgame_classes.BoardGame, boardgame_classes.BoardGameExpansion,
|
||||||
|
boardgame_classes.OwnedBoardGame, boardgame_classes.OwnedBoardGameExpansion,
|
||||||
|
boardgame_classes.WishlistBoardGame, boardgame_classes.WishlistBoardGameExpansion]):
|
||||||
|
|
||||||
|
session = Session(engine)
|
||||||
|
|
||||||
|
session.add(boardgame)
|
||||||
|
|
||||||
|
session.commit()
|
||||||
|
|
||||||
|
def get_all_owned_boardgames():
|
||||||
|
with Session(engine) as session:
|
||||||
|
statement = select(boardgame_classes.OwnedBoardGame)
|
||||||
|
results = session.exec(statement)
|
||||||
|
|
||||||
|
boardgame_list = []
|
||||||
|
|
||||||
|
for boardgame in results:
|
||||||
|
boardgame_list.append(boardgame)
|
||||||
|
|
||||||
|
return boardgame_list
|
||||||
|
|
||||||
def delete_database():
|
def delete_database():
|
||||||
os.remove(definitions.DATABASE_FILE_PATH)
|
os.remove(definitions.DATABASE_FILE_PATH)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue