can now get information about a single boardgame

This commit is contained in:
Yarne Coppens 2024-07-26 10:46:46 +02:00
parent 7b94d0074d
commit 719eb363a9
2 changed files with 22 additions and 2 deletions

View file

@ -13,3 +13,22 @@ def url_to_xml_object(url: HttpUrl) -> ET.Element:
def get_boardgame(boardgame_id: int) -> BoardGame:
url : str = "https://boardgamegeek.com/xmlapi2/thing?id={}&stats=true".format(boardgame_id)
boardgame_xml_object : ET.Element = url_to_xml_object(url)
boardgame_name = boardgame_xml_object.find('item').find('name').get('value')
requested_boardgame = BoardGame(
id = boardgame_id,
name = boardgame_name,
description = 'Some description',
image_url = 'https://bordspellen.yarnecoppens.com/static/favicon.ico',
thumbnail_url = 'https://bordspellen.yarnecoppens.com/static/favicon.ico',
year_published = 9999,
min_players = 0,
max_players = 99,
min_playing_time = 0,
max_playing_time = 99,
min_age = 0,
all_expansion_ids = [0,1,2,3]
)
return requested_boardgame

View file

@ -2,6 +2,7 @@ from typing import Union
from fastapi import FastAPI
from classes.boardgame import BoardGame, BoardGameExpansion
from bgg_connection import get_boardgame
app = FastAPI()
@ -17,4 +18,4 @@ def read_item(item_id: int, q: Union[str, None] = None):
@app.get("/boardgame/{boardgame_id}", response_model=BoardGame)
def get_boardgame_by_id(boardgame_id: int):
pass
return get_boardgame(boardgame_id)