From cbd729d60db2293a1f198112471d3000ecee2671 Mon Sep 17 00:00:00 2001 From: julius Date: Sat, 25 Jan 2025 19:35:34 +0100 Subject: [PATCH] feat: create MVP database table, adjust api --- main.py | 18 +++++++++++++++++- src/Rankings.tsx | 14 ++++++++------ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index bed6b72..fb84d27 100644 --- a/main.py +++ b/main.py @@ -10,7 +10,6 @@ with open("db.secrets", "r") as f: app = FastAPI(title="cutt") engine = create_engine(db_secrets) -# SQLModel.metadata.create_all(engine) origins = [ "*", "http://localhost", @@ -36,6 +35,23 @@ class Chemistry(SQLModel, table=True): undecided: list[str] = Field(sa_column=Column(ARRAY(String))) +class MVPRanking(SQLModel, table=True): + id: int | None = Field(default=None, primary_key=True) + time: datetime | None = Field(default_factory=datetime.now) + user: str + mvps: list[str] = Field(sa_column=Column(ARRAY(String))) + + +SQLModel.metadata.create_all(engine) + + +@app.post("/mvps/", status_code=status.HTTP_200_OK) +def submit_mvps(mvps: MVPRanking): + with Session(engine) as session: + session.add(mvps) + session.commit() + + @app.post("/chemistry/", status_code=status.HTTP_200_OK) def submit_chemistry(chemistry: Chemistry): with Session(engine) as session: diff --git a/src/Rankings.tsx b/src/Rankings.tsx index 9e9bf1c..1b127e8 100644 --- a/src/Rankings.tsx +++ b/src/Rankings.tsx @@ -52,8 +52,8 @@ export function Chemistry() { const [dialog, setDialog] = useState("dialog"); async function handleSubmit() { - const dialog = document.querySelector("dialog"); - dialog?.showModal(); + const dialog = document.querySelector("dialog[id='ChemistryDialog']"); + (dialog as HTMLDialogElement).showModal(); if (user.length < 1) { setDialog("who are you?"); } else { @@ -148,6 +148,7 @@ export function Chemistry() { { event.currentTarget.close(); }} @@ -167,16 +168,16 @@ export function MVP() { const [dialog, setDialog] = useState("dialog"); async function handleSubmit() { - const dialog = document.querySelector("dialog"); - dialog?.showModal(); + const dialog = document.querySelector("dialog[id='MVPDialog']"); + (dialog as HTMLDialogElement).showModal(); if (user.length < 1) { setDialog("who are you?"); } else { setDialog("sending..."); let _user = user.map(({ name }) => name)[0]; let mvps = rankedPlayers.map(({ name }) => name); - const data = { user: _user, rankedPlayers: mvps }; - const response = await api("mvp", data); + const data = { user: _user, mvps: mvps }; + const response = await api("mvps", data); response.ok ? setDialog("success!") : setDialog("try sending again"); } } @@ -258,6 +259,7 @@ export function MVP() { { event.currentTarget.close(); }}