Started work on Player class

This commit is contained in:
Yarne Coppens 2024-08-24 17:39:13 +02:00
parent c6075b7949
commit 7719f879ba
5 changed files with 36 additions and 69 deletions

View file

@ -31,15 +31,6 @@ class BoardGameBase(SQLModel):
'validate_assignment':True
}
# class OwnedBoardGameBase(BoardGameBase):
# 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
@ -135,55 +126,6 @@ class WishlistInfoPublicNoGame(SQLModel):
wishlist_priority: int
# class BoardGamePublic(BoardGameBase):
# id: int
# type: BoardgameType
# plays: list["Play"]
# designers: list["Designer"]
# class BoardGameNoPlays(BoardGameBase):
# id: int
# designers: list["Designer"]
# type: BoardgameType = BoardgameType.BOARDGAME
# 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"]
# type: BoardgameType = BoardgameType.BOARDGAMEEXPANSION
# class OwnedBoardGame(OwnedBoardGameBase, table=True):
# id: int = Field(primary_key=True)
# type: BoardgameType = BoardgameType.OWNEDBOARDGAME
# 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
# 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, PlayPublicNoGame
from src.classes.people_classes import Designer, DesignerPublicNoGames
BoardGame.model_rebuild()
# BoardGameExpansion.model_rebuild()
# BoardGameNoPlays.model_rebuild()
# BoardGameExpansionNoPlays.model_rebuild()
BoardGame.model_rebuild()

View file

@ -3,7 +3,4 @@ from sqlmodel import Field,SQLModel
class DesignerBoardGameLink(SQLModel, table=True):
boardgame_id: int | None = Field(default=None, foreign_key="boardgame.id", primary_key=True)
designer_id: int | None = Field(default=None, foreign_key="designer.id", primary_key=True)
# class DesignerBoardGameExpansionLink(SQLModel, table=True):
# boardgame_id: int | None = Field(default=None, foreign_key="boardgameexpansion.id", primary_key=True)
# designer_id: int | None = Field(default=None, foreign_key="designer.id", primary_key=True)

View file

@ -3,7 +3,6 @@ from typing import Union
from datetime import date
class PlayPlayerBase(SQLModel):
name: str
username: str
score: Union[float, None]
first_play : bool
@ -13,14 +12,19 @@ class PlayPlayerBase(SQLModel):
class PlayPlayer(PlayPlayerBase, table=True):
id: int | None = Field(default=None, primary_key=True)
name: str = Field(default=None, foreign_key="player.name")
play: "Play" = Relationship(back_populates="players")
player: "Player" = Relationship(back_populates="playplayers")
class PlayPlayerPublic(PlayPlayerBase):
id: int
name: str
player: "PlayerPublicNoPlayPlayers"
class PlayPlayerPublicWithPlay(PlayPlayerPublic):
name: str
play: "PlayPublic"
@ -52,6 +56,5 @@ class PlayPublicNoGame(PlayBase):
from src.classes.boardgame_classes import BoardGame, BoardGamePublicNoPlays
from src.classes.people_classes import Designer
Play.model_rebuild()
# PlayPublicWithPlayers.model_rebuild()
from src.classes.player_classes import Player, PlayerPublic, PlayerPublicNoPlayPlayers
Play.model_rebuild()

View file

@ -0,0 +1,14 @@
from sqlmodel import SQLModel, Field, Relationship
from src.classes.play_classes import PlayPlayer
class Player(SQLModel, table=True):
name: str | None = Field(default=None, primary_key=True)
playplayers: list[PlayPlayer] = Relationship(back_populates="player")
class PlayerPublic(SQLModel):
name: str
class PlayerPublicNoPlayPlayers(SQLModel):
name: str

View file

@ -7,7 +7,7 @@ import copy
critical_function_lock = Lock()
from src.classes import boardgame_classes, play_classes, people_classes
from src.classes import boardgame_classes, play_classes, people_classes, player_classes
sqlite_url = definitions.SQLITE_URL
@ -188,6 +188,17 @@ def add_multiple_plays(session: Session, play_list: list[play_classes.Play]):
with critical_function_lock:
for play in play_list:
for playplayer in play.players:
is_player_present = len(session.exec(select(player_classes.Player).where(player_classes.Player.name == playplayer.name)).all()) != 0
if not is_player_present:
new_player = player_classes.Player(name=playplayer.name)
session.add(new_player)
is_play_present = len(session.exec(select(play_classes.Play).where(play_classes.Play.id == play.id)).all()) != 0
if not is_play_present: