Started work on db connection. data_connection will control where data will be returned from
This commit is contained in:
parent
82694d84ed
commit
ec30a9c364
3 changed files with 27 additions and 5 deletions
10
src/main.py
10
src/main.py
|
|
@ -2,7 +2,7 @@ from typing import Union
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
|
|
||||||
from src.classes import boardgame_classes, play_classes
|
from src.classes import boardgame_classes, play_classes
|
||||||
from src.modules import bgg_connection
|
from src.modules import data_connection
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
|
|
@ -13,23 +13,23 @@ def read_root():
|
||||||
|
|
||||||
@app.get("/boardgame/{boardgame_id}", response_model=boardgame_classes.BoardGame)
|
@app.get("/boardgame/{boardgame_id}", response_model=boardgame_classes.BoardGame)
|
||||||
def get_boardgame_by_id(boardgame_id: int):
|
def get_boardgame_by_id(boardgame_id: int):
|
||||||
requested_boardgame: boardgame_classes.BoardGame = bgg_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=list[boardgame_classes.OwnedBoardGame])
|
@app.get("/owned", response_model=list[boardgame_classes.OwnedBoardGame])
|
||||||
def get_owned_collection():
|
def get_owned_collection():
|
||||||
requested_collection: list[boardgame_classes.OwnedBoardGame] = bgg_connection.get_user_owned_collection()
|
requested_collection: list[boardgame_classes.OwnedBoardGame] = data_connection.get_user_owned_collection()
|
||||||
return requested_collection
|
return requested_collection
|
||||||
|
|
||||||
|
|
||||||
@app.get("/wishlist", response_model=list[boardgame_classes.WishlistBoardGame])
|
@app.get("/wishlist", response_model=list[boardgame_classes.WishlistBoardGame])
|
||||||
def get_wishlist_collection():
|
def get_wishlist_collection():
|
||||||
requested_collection: list[boardgame_classes.WishlistBoardGame] = bgg_connection.get_user_wishlist_collection()
|
requested_collection: list[boardgame_classes.WishlistBoardGame] = data_connection.get_user_wishlist_collection()
|
||||||
return requested_collection
|
return requested_collection
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/plays", response_model=list[play_classes.Play])
|
@app.get("/plays", response_model=list[play_classes.Play])
|
||||||
def get_plays():
|
def get_plays():
|
||||||
requested_plays: list[play_classes.Play] = bgg_connection.get_plays()
|
requested_plays: list[play_classes.Play] = data_connection.get_plays()
|
||||||
return requested_plays
|
return requested_plays
|
||||||
22
src/modules/data_connection.py
Normal file
22
src/modules/data_connection.py
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
from src.modules import bgg_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
|
||||||
|
|
||||||
|
return bgg_connection.get_boardgame(boardgame_id)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def get_user_owned_collection() -> list[boardgame_classes.BoardGame]:
|
||||||
|
|
||||||
|
return bgg_connection.get_user_owned_collection()
|
||||||
|
|
||||||
|
|
||||||
|
def get_user_wishlist_collection() -> list[boardgame_classes.BoardGame]:
|
||||||
|
|
||||||
|
return bgg_connection.get_user_wishlist_collection()
|
||||||
|
|
||||||
|
def get_plays() -> list[play_classes.Play]:
|
||||||
|
return bgg_connection.get_plays()
|
||||||
0
src/modules/db_connection.py
Normal file
0
src/modules/db_connection.py
Normal file
Loading…
Reference in a new issue