diff --git a/main.py b/main.py index 7783952..dfa7563 100644 --- a/main.py +++ b/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 diff --git a/setup-postgres.sh b/setup-postgres.sh index 430f753..0fa5509 100755 --- a/setup-postgres.sh +++ b/setup-postgres.sh @@ -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 );