we have MVP

This commit is contained in:
Anish Lakhwara 2022-11-23 23:26:58 +10:00
parent 08633f1288
commit 2819487f00
2 changed files with 21 additions and 15 deletions

20
main.py
View file

@ -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

View file

@ -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
);