bgg_api/src/classes/boardgame_classes.py

105 lines
3.3 KiB
Python
Raw Normal View History

2024-08-01 11:48:29 +02:00
from datetime import date
2024-08-01 12:05:51 +02:00
from enum import Enum
from sqlmodel import Field, SQLModel, Relationship
from src.classes import many_to_many_links
2024-08-01 12:05:51 +02:00
class BoardgameType(Enum):
2024-08-01 12:16:50 +02:00
BOARDGAME = 'boardgame'
BOARDGAMEEXPANSION = 'boardgameexpansion'
OWNEDBOARDGAME = 'ownedboardgame'
OWNEDBOARDGAMEEXPANSION = 'ownedboardgameexpansion'
2024-08-01 12:16:50 +02:00
WISHLISTBOARDGAME = 'wishlistboardgame'
WISHLISTBOARDGAMEEXPANSION = 'wishlistboardgameexpansion'
2024-08-01 12:05:51 +02:00
class BoardGameBase(SQLModel):
2024-08-03 14:18:54 +02:00
name: str
description: str
2024-08-08 16:50:42 +02:00
weight: float
2024-08-03 14:18:54 +02:00
image_url : str
thumbnail_url : str
year_published: int
min_players: int
max_players: int
min_playing_time: int
max_playing_time: int
min_age: int
model_config = {
'validate_assignment':True
}
2024-08-03 14:18:54 +02:00
class OwnedBoardGameBase(BoardGameBase):
2024-08-01 11:48:29 +02:00
price_paid: float
acquisition_date: date
acquired_from: str
class WishlistBoardGameBase(BoardGameBase):
wishlist_priority: int
class BoardGame(BoardGameBase, table=True):
id: int = Field(primary_key=True)
type: BoardgameType = BoardgameType.BOARDGAME
plays: list["Play"] = Relationship(back_populates='boardgame')
designers: list["Designer"] = Relationship(back_populates="designed_boardgames", link_model=many_to_many_links.DesignerBoardGameLink)
class BoardGamePublic(BoardGameBase):
id: int
type: BoardgameType
plays: list["Play"]
designers: list["Designer"]
class BoardGameNoPlays(BoardGameBase):
id: int
designers: list["Designer"]
2024-08-13 10:35:25 +02:00
type: BoardgameType = BoardgameType.BOARDGAME
class BoardGameExpansion(BoardGameBase, table=True):
id: int = Field(primary_key=True)
expansion_for: int = Field(default=None, foreign_key="boardgame.id")
type: BoardgameType = BoardgameType.BOARDGAMEEXPANSION
2024-08-13 10:35:25 +02:00
plays: list["Play"] = Relationship(back_populates='boardgameexpansion')
designers: list["Designer"] = Relationship(back_populates="designed_expansions", link_model=many_to_many_links.DesignerBoardGameExpansionLink)
class BoardGameExpansionPublic(BoardGameBase):
id: int
expansion_for: int
type: BoardgameType
plays: list["Play"]
designers: list["Designer"]
class BoardGameExpansionNoPlays(BoardGameBase):
id: int
expansion_for: int
designers: list["Designer"]
2024-08-13 10:35:25 +02:00
type: BoardgameType = BoardgameType.BOARDGAMEEXPANSION
class OwnedBoardGame(OwnedBoardGameBase, table=True):
id: int = Field(primary_key=True)
type: BoardgameType = BoardgameType.OWNEDBOARDGAME
2024-08-01 11:48:29 +02:00
class OwnedBoardGameExpansion(OwnedBoardGameBase, table=True):
id: int = Field(primary_key=True)
expansion_for: int = Field(default=None, foreign_key="boardgame.id")
type: BoardgameType = BoardgameType.OWNEDBOARDGAMEEXPANSION
2024-08-01 11:48:29 +02:00
class WishlistBoardGame(WishlistBoardGameBase, table=True):
id: int = Field(primary_key=True)
type: BoardgameType = BoardgameType.WISHLISTBOARDGAME
class WishlistBoardGameExpansion(WishlistBoardGameBase, table=True):
id: int = Field(primary_key=True)
expansion_for: int = Field(default=None, foreign_key="boardgame.id")
type: BoardgameType = BoardgameType.WISHLISTBOARDGAMEEXPANSION
from src.classes.play_classes import Play, PlayPublic
from src.classes.people_classes import Designer
BoardGame.model_rebuild()
BoardGameExpansion.model_rebuild()
BoardGameNoPlays.model_rebuild()
BoardGameExpansionNoPlays.model_rebuild()