diff --git a/Dockerfile-postgres b/Dockerfile-postgres index 211806d..b40a111 100644 --- a/Dockerfile-postgres +++ b/Dockerfile-postgres @@ -1,4 +1,4 @@ FROM postgres:9.5 RUN apt-get update -RUN apt-get install -y postgis +RUN apt-get install -y postgis postgresql-9.5-postgis-scripts ADD /setup.sql /docker-entrypoint-initdb.d/ diff --git a/backend.py b/backend.py index c8a5d3c..9fd9f7b 100644 --- a/backend.py +++ b/backend.py @@ -99,16 +99,6 @@ class BaseEvent: } -class EventsResource(BaseEvent): - - def on_get(self, req, resp): - db = db_connect() - cur = db.cursor(cursor_factory=psycopg2.extras.DictCursor) - cur.execute("SELECT events_id, events_tags, createdate, lastupdate, st_asgeojson(geom) as geometry FROM events JOIN geo ON (hash=events_geo)") - resp.body = dumps(self.rows_to_collection(cur.fetchall())) - resp.status = falcon.HTTP_200 - - class EventResource(BaseEvent): def maybe_insert_geometry(self, geometry, cur): # insert into geo table if not existing @@ -446,13 +436,11 @@ class EventSearch(BaseEvent): app = falcon.API(middleware=[HeaderMiddleware()]) # Resources are represented by long-lived class instances -events = EventsResource() event = EventResource() stats = StatsResource() event_search = EventSearch() # things will handle all requests to the matching URL path -app.add_route('/events', events) app.add_route('/event/{id}', event) # handle single event requests app.add_route('/event', event) # handle single event requests app.add_route('/stats', stats) diff --git a/setup.sql b/setup.sql index b49f22e..587bc07 100644 --- a/setup.sql +++ b/setup.sql @@ -56,8 +56,8 @@ CREATE TABLE events_deleted ( CREATE TABLE geo ( geom geometry(Geometry,4326), - geom_center geometry(Point,4326), hash text, + geom_center geometry(Point,4326), idx geometry ); diff --git a/swagger.json b/swagger.json index dfee984..0b12ac5 100644 --- a/swagger.json +++ b/swagger.json @@ -145,7 +145,15 @@ "produces": [ "application/json" ], - "parameters": [], + "parameters": [ + { + "name": "id", + "in": "path", + "description": "Id of event", + "required": true, + "type": "string" + } + ], "responses": { "200": { "description": "Success", @@ -179,7 +187,29 @@ } }, "definitions": { - "Event": { + "EventGeometry": { + "type": "object", + "required": [ + "type" + ], + "properties": { + "type": { + "type": "string", + "description": "Geometry type: Point" + }, + "coordinates": { + "description": "Geometry coordinates (longitude; latitude)", + "type": "array", + "items": { + "type": "number", + "format": "float", + "maxItems": 2, + "minItems": 2 + } + } + } + }, + "EventProperties": { "type": "object", "required": [ "id", @@ -196,11 +226,27 @@ "type": "string", "description": "Event UUID" }, + "label": { + "type": "string", + "description": "Event label" + }, "lastupdate": { "type": "string", "format": "date", "description": "Event last modification timestamp" }, + "lat": { + "type": "number", + "description": "Event location latitude" + }, + "lon": { + "type": "number", + "description": "Event location longitude" + }, + "source": { + "type": "string", + "description": "Event source" + }, "start": { "type": "string", "format": "date", @@ -213,7 +259,8 @@ }, "type": { "type": "string", - "description": "Event type: scheduled, forecast, unscheduled" + "description": "Event type", + "enum": ["scheduled", "forecast", "unscheduled"] }, "what": { "type": "string", @@ -225,6 +272,28 @@ "description": "Event timestamp" } } + }, + "Event": { + "type": "object", + "required": [ + "geometry", + "properties", + "type" + ], + "properties": { + "geometry": { + "$ref": "#/definitions/EventGeometry" + }, + "properties": { + "$ref": "#/definitions/EventProperties" + }, + "type": + { + "description": "Type of event", + "type": "string", + "enum": ["Point"] + } + } } } }