From 2819487f0071e45135c9c04740b1956ca1cef987 Mon Sep 17 00:00:00 2001 From: Anish Lakhwara Date: Wed, 23 Nov 2022 23:26:58 +1000 Subject: [PATCH] we have MVP --- main.py | 20 +++++++++++++------- setup-postgres.sh | 16 ++++++++-------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/main.py b/main.py index dfa7563..466876f 100644 --- a/main.py +++ b/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 diff --git a/setup-postgres.sh b/setup-postgres.sh index 0fa5509..1c8f0b1 100755 --- a/setup-postgres.sh +++ b/setup-postgres.sh @@ -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 );