Added more typing
This commit is contained in:
parent
3e9347d71c
commit
a34b482b95
3 changed files with 17 additions and 12 deletions
10
src/main.py
10
src/main.py
|
|
@ -25,16 +25,14 @@ def get_boardgame_by_id(boardgame_id: int):
|
||||||
requested_boardgame: boardgame_classes.BoardGame = data_connection.get_boardgame(boardgame_id)
|
requested_boardgame: boardgame_classes.BoardGame = data_connection.get_boardgame(boardgame_id)
|
||||||
return requested_boardgame
|
return requested_boardgame
|
||||||
|
|
||||||
@app.get("/owned", response_model=Union[list[boardgame_classes.OwnedBoardGame], list[boardgame_classes.OwnedBoardGameExpansion]])
|
@app.get("/owned", response_model=list[Union[boardgame_classes.OwnedBoardGame, boardgame_classes.OwnedBoardGameExpansion]])
|
||||||
def get_owned_collection():
|
def get_owned_collection():
|
||||||
requested_collection: list[boardgame_classes.OwnedBoardGame] = data_connection.get_user_owned_collection()
|
return data_connection.get_user_owned_collection()
|
||||||
return requested_collection
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/wishlist", response_model=Union[list[boardgame_classes.WishlistBoardGame], list[boardgame_classes.WishlistBoardGameExpansion]])
|
@app.get("/wishlist", response_model=list[Union[boardgame_classes.WishlistBoardGame, boardgame_classes.WishlistBoardGameExpansion]])
|
||||||
def get_wishlist_collection():
|
def get_wishlist_collection():
|
||||||
requested_collection: list[boardgame_classes.WishlistBoardGame] = data_connection.get_user_wishlist_collection()
|
return data_connection.get_user_wishlist_collection()
|
||||||
return requested_collection
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import requests
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import time
|
import time
|
||||||
import math
|
import math
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
from src.classes import boardgame_classes, play_classes
|
from src.classes import boardgame_classes, play_classes
|
||||||
from src.modules import auth_manager
|
from src.modules import auth_manager
|
||||||
|
|
@ -96,7 +97,7 @@ def convert_xml_to_boardgame(boardgame_xml: ET.Element) -> boardgame_classes.Boa
|
||||||
|
|
||||||
return boardgame
|
return boardgame
|
||||||
|
|
||||||
def convert_collection_xml_to_owned_boardgame(boardgame_extra_info: boardgame_classes.BoardGame, collection_boardgame_xml: ET.Element) -> boardgame_classes.OwnedBoardGame:
|
def convert_collection_xml_to_owned_boardgame(boardgame_extra_info: boardgame_classes.BoardGame, collection_boardgame_xml: ET.Element) -> Union[boardgame_classes.OwnedBoardGame, boardgame_classes.OwnedBoardGameExpansion]:
|
||||||
|
|
||||||
boardgame_type = collection_boardgame_xml.get('subtype')
|
boardgame_type = collection_boardgame_xml.get('subtype')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
from src.modules import bgg_connection, db_connection
|
from src.modules import bgg_connection, db_connection
|
||||||
from src.classes import boardgame_classes, play_classes
|
from src.classes import boardgame_classes, play_classes
|
||||||
|
|
||||||
|
|
@ -18,20 +20,24 @@ def get_boardgame(boardgame_id: int) -> boardgame_classes.BoardGame:
|
||||||
return to_return_boardgame
|
return to_return_boardgame
|
||||||
|
|
||||||
|
|
||||||
def get_user_owned_collection() -> list[boardgame_classes.OwnedBoardGame]:
|
def get_user_owned_collection() -> list[Union[boardgame_classes.OwnedBoardGame, boardgame_classes.OwnedBoardGameExpansion]]:
|
||||||
owned_boardgames_from_db = db_connection.get_all_owned_boardgames()
|
owned_boardgames_from_db = db_connection.get_all_owned_boardgames()
|
||||||
|
owned_boardgame_expanions_from_db = db_connection.get_all_owned_boardgames_expansions()
|
||||||
|
|
||||||
if len(owned_boardgames_from_db) != 0:
|
boardgames_to_return = []
|
||||||
return owned_boardgames_from_db
|
|
||||||
else:
|
if len(owned_boardgames_from_db) == 0 and len(owned_boardgame_expanions_from_db) == 0:
|
||||||
owned_boardgames = bgg_connection.get_user_owned_collection()
|
owned_boardgames = bgg_connection.get_user_owned_collection()
|
||||||
for boardgame in owned_boardgames:
|
for boardgame in owned_boardgames:
|
||||||
db_connection.add_boardgame(boardgame)
|
db_connection.add_boardgame(boardgame)
|
||||||
|
|
||||||
return owned_boardgames
|
return owned_boardgames
|
||||||
|
else:
|
||||||
|
return owned_boardgames_from_db
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_user_wishlist_collection() -> list[boardgame_classes.BoardGame]:
|
def get_user_wishlist_collection() -> Union[list[boardgame_classes.WishlistBoardGame], list[boardgame_classes.WishlistBoardGameExpansion]]:
|
||||||
|
|
||||||
owned_boardgames_from_db = db_connection.get_all_wishlisted_boardgames
|
owned_boardgames_from_db = db_connection.get_all_wishlisted_boardgames
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue