Merge branch 'master' of github.com:openeventdatabase/backend
This commit is contained in:
commit
5c2fc98d1a
4 changed files with 74 additions and 17 deletions
|
@ -1,4 +1,4 @@
|
||||||
FROM postgres:9.5
|
FROM postgres:9.5
|
||||||
RUN apt-get update
|
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/
|
ADD /setup.sql /docker-entrypoint-initdb.d/
|
||||||
|
|
12
backend.py
12
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):
|
class EventResource(BaseEvent):
|
||||||
def maybe_insert_geometry(self, geometry, cur):
|
def maybe_insert_geometry(self, geometry, cur):
|
||||||
# insert into geo table if not existing
|
# insert into geo table if not existing
|
||||||
|
@ -446,13 +436,11 @@ class EventSearch(BaseEvent):
|
||||||
app = falcon.API(middleware=[HeaderMiddleware()])
|
app = falcon.API(middleware=[HeaderMiddleware()])
|
||||||
|
|
||||||
# Resources are represented by long-lived class instances
|
# Resources are represented by long-lived class instances
|
||||||
events = EventsResource()
|
|
||||||
event = EventResource()
|
event = EventResource()
|
||||||
stats = StatsResource()
|
stats = StatsResource()
|
||||||
event_search = EventSearch()
|
event_search = EventSearch()
|
||||||
|
|
||||||
# things will handle all requests to the matching URL path
|
# 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/{id}', event) # handle single event requests
|
||||||
app.add_route('/event', event) # handle single event requests
|
app.add_route('/event', event) # handle single event requests
|
||||||
app.add_route('/stats', stats)
|
app.add_route('/stats', stats)
|
||||||
|
|
|
@ -56,8 +56,8 @@ CREATE TABLE events_deleted (
|
||||||
|
|
||||||
CREATE TABLE geo (
|
CREATE TABLE geo (
|
||||||
geom geometry(Geometry,4326),
|
geom geometry(Geometry,4326),
|
||||||
geom_center geometry(Point,4326),
|
|
||||||
hash text,
|
hash text,
|
||||||
|
geom_center geometry(Point,4326),
|
||||||
idx geometry
|
idx geometry
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
75
swagger.json
75
swagger.json
|
@ -145,7 +145,15 @@
|
||||||
"produces": [
|
"produces": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
"parameters": [],
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"description": "Id of event",
|
||||||
|
"required": true,
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "Success",
|
"description": "Success",
|
||||||
|
@ -179,7 +187,29 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"definitions": {
|
"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",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
"id",
|
"id",
|
||||||
|
@ -196,11 +226,27 @@
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Event UUID"
|
"description": "Event UUID"
|
||||||
},
|
},
|
||||||
|
"label": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "Event label"
|
||||||
|
},
|
||||||
"lastupdate": {
|
"lastupdate": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"format": "date",
|
"format": "date",
|
||||||
"description": "Event last modification timestamp"
|
"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": {
|
"start": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"format": "date",
|
"format": "date",
|
||||||
|
@ -213,7 +259,8 @@
|
||||||
},
|
},
|
||||||
"type": {
|
"type": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Event type: scheduled, forecast, unscheduled"
|
"description": "Event type",
|
||||||
|
"enum": ["scheduled", "forecast", "unscheduled"]
|
||||||
},
|
},
|
||||||
"what": {
|
"what": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
|
@ -225,6 +272,28 @@
|
||||||
"description": "Event timestamp"
|
"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"]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue