feat: create MVP database table, adjust api
This commit is contained in:
parent
8a4f8ef3a4
commit
cbd729d60d
18
main.py
18
main.py
@ -10,7 +10,6 @@ with open("db.secrets", "r") as f:
|
|||||||
|
|
||||||
app = FastAPI(title="cutt")
|
app = FastAPI(title="cutt")
|
||||||
engine = create_engine(db_secrets)
|
engine = create_engine(db_secrets)
|
||||||
# SQLModel.metadata.create_all(engine)
|
|
||||||
origins = [
|
origins = [
|
||||||
"*",
|
"*",
|
||||||
"http://localhost",
|
"http://localhost",
|
||||||
@ -36,6 +35,23 @@ class Chemistry(SQLModel, table=True):
|
|||||||
undecided: list[str] = Field(sa_column=Column(ARRAY(String)))
|
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)
|
@app.post("/chemistry/", status_code=status.HTTP_200_OK)
|
||||||
def submit_chemistry(chemistry: Chemistry):
|
def submit_chemistry(chemistry: Chemistry):
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
|
@ -52,8 +52,8 @@ export function Chemistry() {
|
|||||||
const [dialog, setDialog] = useState("dialog");
|
const [dialog, setDialog] = useState("dialog");
|
||||||
|
|
||||||
async function handleSubmit() {
|
async function handleSubmit() {
|
||||||
const dialog = document.querySelector("dialog");
|
const dialog = document.querySelector("dialog[id='ChemistryDialog']");
|
||||||
dialog?.showModal();
|
(dialog as HTMLDialogElement).showModal();
|
||||||
if (user.length < 1) {
|
if (user.length < 1) {
|
||||||
setDialog("who are you?");
|
setDialog("who are you?");
|
||||||
} else {
|
} else {
|
||||||
@ -148,6 +148,7 @@ export function Chemistry() {
|
|||||||
|
|
||||||
<button onClick={() => handleSubmit()}>submit</button>
|
<button onClick={() => handleSubmit()}>submit</button>
|
||||||
<dialog
|
<dialog
|
||||||
|
id="ChemistryDialog"
|
||||||
onClick={(event) => {
|
onClick={(event) => {
|
||||||
event.currentTarget.close();
|
event.currentTarget.close();
|
||||||
}}
|
}}
|
||||||
@ -167,16 +168,16 @@ export function MVP() {
|
|||||||
const [dialog, setDialog] = useState("dialog");
|
const [dialog, setDialog] = useState("dialog");
|
||||||
|
|
||||||
async function handleSubmit() {
|
async function handleSubmit() {
|
||||||
const dialog = document.querySelector("dialog");
|
const dialog = document.querySelector("dialog[id='MVPDialog']");
|
||||||
dialog?.showModal();
|
(dialog as HTMLDialogElement).showModal();
|
||||||
if (user.length < 1) {
|
if (user.length < 1) {
|
||||||
setDialog("who are you?");
|
setDialog("who are you?");
|
||||||
} else {
|
} else {
|
||||||
setDialog("sending...");
|
setDialog("sending...");
|
||||||
let _user = user.map(({ name }) => name)[0];
|
let _user = user.map(({ name }) => name)[0];
|
||||||
let mvps = rankedPlayers.map(({ name }) => name);
|
let mvps = rankedPlayers.map(({ name }) => name);
|
||||||
const data = { user: _user, rankedPlayers: mvps };
|
const data = { user: _user, mvps: mvps };
|
||||||
const response = await api("mvp", data);
|
const response = await api("mvps", data);
|
||||||
response.ok ? setDialog("success!") : setDialog("try sending again");
|
response.ok ? setDialog("success!") : setDialog("try sending again");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -258,6 +259,7 @@ export function MVP() {
|
|||||||
|
|
||||||
<button onClick={() => handleSubmit()}>submit</button>
|
<button onClick={() => handleSubmit()}>submit</button>
|
||||||
<dialog
|
<dialog
|
||||||
|
id="MVPDialog"
|
||||||
onClick={(event) => {
|
onClick={(event) => {
|
||||||
event.currentTarget.close();
|
event.currentTarget.close();
|
||||||
}}
|
}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user