Add WinType and Game
This commit is contained in:
parent
92aa031eba
commit
4517b4e31f
5
NOTES.md
5
NOTES.md
@ -1,15 +1,16 @@
|
|||||||
# Development plan
|
# Development plan
|
||||||
|
|
||||||
- [X] Basic Game Definition
|
|
||||||
- [X] Basic Player Definition
|
- [X] Basic Player Definition
|
||||||
- [X] Basic Deck Definition
|
- [X] Basic Deck Definition
|
||||||
- [X] Figure out how to return JSON or html (`render_template`)
|
- [X] Figure out how to return JSON or html (`render_template`)
|
||||||
- [X] Basic testing
|
- [X] Basic testing
|
||||||
- [X] ruff
|
- [X] ruff
|
||||||
- [X] GitHub Actions for tests and linters
|
- [X] GitHub Actions for tests and linters
|
||||||
- [ ] Basic List pages for entities
|
- [X] Basic List pages for entities
|
||||||
- [X] Swagger API
|
- [X] Swagger API
|
||||||
- [ ] Local development tool to clear/seed database
|
- [ ] Local development tool to clear/seed database
|
||||||
|
- [ ] CRUD APIs for Games
|
||||||
|
- [ ] Load Game-history from file
|
||||||
...
|
...
|
||||||
- [ ] Authentication (will need to link `user` table to `player`)
|
- [ ] Authentication (will need to link `user` table to `player`)
|
||||||
...
|
...
|
||||||
|
@ -2,6 +2,7 @@ from fastapi import FastAPI
|
|||||||
from fastapi.staticfiles import StaticFiles
|
from fastapi.staticfiles import StaticFiles
|
||||||
|
|
||||||
from .routers import api_router, html_router
|
from .routers import api_router, html_router
|
||||||
|
from .sql import prime_database
|
||||||
from .sql.models import Base
|
from .sql.models import Base
|
||||||
from .sql.database import engine
|
from .sql.database import engine
|
||||||
|
|
||||||
@ -12,3 +13,5 @@ app.mount("/static", StaticFiles(directory="app/static"), name="static")
|
|||||||
|
|
||||||
app.include_router(api_router)
|
app.include_router(api_router)
|
||||||
app.include_router(html_router)
|
app.include_router(html_router)
|
||||||
|
|
||||||
|
prime_database()
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
from . import models
|
||||||
|
from .database import SessionLocal
|
||||||
|
|
||||||
|
def prime_database():
|
||||||
|
db = SessionLocal()
|
||||||
|
win_types = db.query(models.WinType).all()
|
||||||
|
print('Win types are:')
|
||||||
|
print(win_types)
|
||||||
|
if not win_types:
|
||||||
|
db.add(models.WinType(name="Combat Damage"))
|
||||||
|
db.add(models.WinType(name="Commander Damage"))
|
||||||
|
db.add(models.WinType(name="Direct Damage"))
|
||||||
|
db.add(models.WinType(name="Poison"))
|
||||||
|
db.add(models.WinType(name="Decking"))
|
||||||
|
db.add(models.WinType(name="other"))
|
||||||
|
db.commit()
|
@ -22,3 +22,27 @@ class Deck(Base):
|
|||||||
owner_id = Column(Integer, ForeignKey("players.id"))
|
owner_id = Column(Integer, ForeignKey("players.id"))
|
||||||
|
|
||||||
owner = relationship("Player", back_populates="decks")
|
owner = relationship("Player", back_populates="decks")
|
||||||
|
|
||||||
|
|
||||||
|
class WinType(Base):
|
||||||
|
__tablename__ = 'wintypes'
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True)
|
||||||
|
name = Column(String, nullable=False)
|
||||||
|
|
||||||
|
|
||||||
|
class Game(Base):
|
||||||
|
__tablename__ = "games"
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True)
|
||||||
|
deck_id_1 = Column(Integer, ForeignKey("decks.id"), nullable=False)
|
||||||
|
deck_id_2 = Column(Integer, ForeignKey("decks.id"), nullable=False)
|
||||||
|
deck_id_3 = Column(Integer, ForeignKey("decks.id"))
|
||||||
|
deck_id_4 = Column(Integer, ForeignKey("decks.id"))
|
||||||
|
deck_id_5 = Column(Integer, ForeignKey("decks.id"))
|
||||||
|
deck_id_6 = Column(Integer, ForeignKey("decks.id"))
|
||||||
|
winning_deck_id = Column(Integer, ForeignKey("decks.id"), nullable=False)
|
||||||
|
number_of_turns = Column(Integer, nullable=False)
|
||||||
|
first_player_out_turn = Column(Integer, nullable=False)
|
||||||
|
win_type_id = Column(Integer, ForeignKey("wintypes.id"), nullable=False)
|
||||||
|
description = Column(String)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from typing import Optional
|
from typing import List, Optional
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
|
||||||
@ -30,3 +30,41 @@ class Deck(DeckBase):
|
|||||||
id: int
|
id: int
|
||||||
|
|
||||||
model_config = {"from_attributes": True}
|
model_config = {"from_attributes": True}
|
||||||
|
|
||||||
|
|
||||||
|
class WinTypeBase(BaseModel):
|
||||||
|
name: str
|
||||||
|
|
||||||
|
|
||||||
|
class WinTypeCreate(WinTypeBase):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class WinType(WinTypeBase):
|
||||||
|
id: int
|
||||||
|
|
||||||
|
model_config = {"from_attributes": True}
|
||||||
|
|
||||||
|
|
||||||
|
class GameBase(BaseModel):
|
||||||
|
deck_id_1: int
|
||||||
|
deck_id_2: int
|
||||||
|
deck_id_3: int
|
||||||
|
deck_id_4: int
|
||||||
|
deck_id_5: int
|
||||||
|
deck_id_6: int
|
||||||
|
winning_deck_id: int
|
||||||
|
number_of_turns: int
|
||||||
|
first_player_out_turn: int
|
||||||
|
win_type_id: int
|
||||||
|
description: str
|
||||||
|
|
||||||
|
|
||||||
|
class GameCreate(GameBase):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class Game(GameBase):
|
||||||
|
id: int
|
||||||
|
|
||||||
|
model_config = {"from_attributes": True}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user