working with caelen
This commit is contained in:
parent
ab80adf70f
commit
08633f1288
30
main.py
30
main.py
|
@ -1,5 +1,6 @@
|
|||
from fastapi import FastAPI
|
||||
from pydantic import BaseModel
|
||||
from http import HTTPStatus
|
||||
from typing import List
|
||||
from sqlalchemy import create_engine, text
|
||||
import psycopg2.extras
|
||||
|
@ -20,13 +21,14 @@ class vector3(BaseModel):
|
|||
|
||||
|
||||
class Route(BaseModel):
|
||||
id: str
|
||||
creatorName: str
|
||||
dustPoints: list # List[Vector3]
|
||||
checkpoints: list # List[Vector3]
|
||||
startLocation: dict # Vector3
|
||||
endLocation: dict # Vector3
|
||||
creationDate: str
|
||||
route: dict
|
||||
# id: str
|
||||
# creatorName: str
|
||||
# dustPoints: list # List[Vector3]
|
||||
# checkpoints: list # List[Vector3]
|
||||
# startLocation: dict # Vector3
|
||||
# endLocation: dict # Vector3
|
||||
# creationDate: str
|
||||
|
||||
|
||||
@app.get("/route")
|
||||
|
@ -35,22 +37,24 @@ async def get_route():
|
|||
result = engine.execute(select)
|
||||
data = []
|
||||
for route in result:
|
||||
data.append(route)
|
||||
return {"data": data}
|
||||
data.append({"route": route})
|
||||
return data
|
||||
|
||||
|
||||
@app.post("/route")
|
||||
async def post_route(route: Route):
|
||||
as_dict = route.dict()
|
||||
print(route)
|
||||
as_dict = route.dict()['route']
|
||||
as_dict['id'] = "astoehsteaohus"
|
||||
insert = text(
|
||||
"""INSERT INTO
|
||||
routes (id, creatorName, creationDate, startLocation, endLocation, checkpoints, dustPoints)
|
||||
routes (id, creatorName, creationDate, name, creatorCharacter, startLocation, endLocation, checkpoints, dustPoints)
|
||||
VALUES
|
||||
(:id, :creatorName, creationDate
|
||||
(:id, :creatorName, :creationDate, :name, :creatorCharacter,
|
||||
CAST(:startLocation as jsonb),
|
||||
CAST(:endLocation as jsonb),
|
||||
CAST(:checkpoints as jsonb[]),
|
||||
CAST(:dustPoints as jsonb[]))"""
|
||||
).bindparams(**as_dict)
|
||||
engine.execute(insert)
|
||||
return
|
||||
return HTTPStatus.OK
|
||||
|
|
|
@ -15,10 +15,12 @@ fi
|
|||
psql $PGDATABASE << EOF
|
||||
CREATE TABLE routes ( \
|
||||
id text,
|
||||
name text,
|
||||
creatorName text,
|
||||
creatorCharacter int,
|
||||
dustPoints jsonb[],
|
||||
checkPoints jsonb[],
|
||||
startLocation jsonb,
|
||||
endLocation jsonb,
|
||||
createDate text
|
||||
creationDate text
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue