we have MVP
This commit is contained in:
parent
08633f1288
commit
2819487f00
20
main.py
20
main.py
|
@ -37,24 +37,30 @@ async def get_route():
|
|||
result = engine.execute(select)
|
||||
data = []
|
||||
for route in result:
|
||||
data.append({"route": route})
|
||||
data.append(route)
|
||||
return data
|
||||
|
||||
|
||||
@app.post("/route")
|
||||
async def post_route(route: Route):
|
||||
async def post_route(route: dict):
|
||||
print(route)
|
||||
as_dict = route.dict()['route']
|
||||
as_dict['id'] = "astoehsteaohus"
|
||||
# as_dict = route.dict()
|
||||
insert = text(
|
||||
"""INSERT INTO
|
||||
routes (id, creatorName, creationDate, name, creatorCharacter, startLocation, endLocation, checkpoints, dustPoints)
|
||||
routes (id, "creatorName", "creationDate", name, "creatorCharacter", "startLocation", "endLocation", checkpoints, dustpoints)
|
||||
VALUES
|
||||
(:id, :creatorName, :creationDate, :name, :creatorCharacter,
|
||||
CAST(:startLocation as jsonb),
|
||||
CAST(:endLocation as jsonb),
|
||||
CAST(:checkpoints as jsonb[]),
|
||||
CAST(:dustPoints as jsonb[]))"""
|
||||
).bindparams(**as_dict)
|
||||
CAST(:dustpoints as jsonb[]))"""
|
||||
).bindparams(**route)
|
||||
engine.execute(insert)
|
||||
return HTTPStatus.OK
|
||||
|
||||
|
||||
@app.get("/route/delete")
|
||||
async def delete_routes():
|
||||
delete = text("TRUNCATE TABLE routes")
|
||||
engine.execute(delete)
|
||||
return HTTPStatus.OK
|
||||
|
|
|
@ -14,13 +14,13 @@ fi
|
|||
# TODO move to alembic migrations
|
||||
psql $PGDATABASE << EOF
|
||||
CREATE TABLE routes ( \
|
||||
id text,
|
||||
id text PRIMARY KEY,
|
||||
name text,
|
||||
creatorName text,
|
||||
creatorCharacter int,
|
||||
dustPoints jsonb[],
|
||||
checkPoints jsonb[],
|
||||
startLocation jsonb,
|
||||
endLocation jsonb,
|
||||
creationDate text
|
||||
"creatorName" text,
|
||||
"creatorCharacter" int,
|
||||
dustpoints jsonb[],
|
||||
checkpoints jsonb[],
|
||||
"startLocation" jsonb,
|
||||
"endLocation" jsonb,
|
||||
"creationDate" text
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue