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
|
||||
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/
|
||||
|
|
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):
|
||||
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)
|
||||
|
|
|
@ -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
|
||||
);
|
||||
|
||||
|
|
75
swagger.json
75
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"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue