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")
|
||||
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:
|
||||
|
@ -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() {
|
||||
|
||||
<button onClick={() => handleSubmit()}>submit</button>
|
||||
<dialog
|
||||
id="ChemistryDialog"
|
||||
onClick={(event) => {
|
||||
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() {
|
||||
|
||||
<button onClick={() => handleSubmit()}>submit</button>
|
||||
<dialog
|
||||
id="MVPDialog"
|
||||
onClick={(event) => {
|
||||
event.currentTarget.close();
|
||||
}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user