up stuff
This commit is contained in:
parent
656c3fd414
commit
1c17b57d8a
37 changed files with 2818 additions and 469 deletions
51
oedb/resources/search.py
Normal file
51
oedb/resources/search.py
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
"""
|
||||
Search resource for the OpenEventDatabase.
|
||||
"""
|
||||
|
||||
import json
|
||||
import falcon
|
||||
from oedb.models.event import BaseEvent
|
||||
from oedb.utils.logging import logger
|
||||
|
||||
class EventSearch(BaseEvent):
|
||||
"""
|
||||
Resource for searching events by geometry.
|
||||
Handles the /event/search endpoint.
|
||||
"""
|
||||
|
||||
def on_post(self, req, resp):
|
||||
"""
|
||||
Handle POST requests to the /event/search endpoint.
|
||||
Expects a GeoJSON Feature in the request body.
|
||||
|
||||
Args:
|
||||
req: The request object.
|
||||
resp: The response object.
|
||||
"""
|
||||
logger.info("Processing POST request to /event/search")
|
||||
|
||||
try:
|
||||
# Body should contain a GeoJSON Feature
|
||||
body = req.stream.read().decode('utf-8')
|
||||
j = json.loads(body)
|
||||
|
||||
# Validate the request body
|
||||
if 'geometry' not in j:
|
||||
logger.warning("Request body missing 'geometry' field")
|
||||
resp.status = falcon.HTTP_400
|
||||
resp.body = json.dumps({"error": "Request body must contain a 'geometry' field"})
|
||||
return
|
||||
|
||||
# Pass the query with the geometry to event.on_get
|
||||
# This will be handled by the main application
|
||||
from oedb.resources.event import event
|
||||
event.on_get(req, resp, None, j['geometry'])
|
||||
logger.success("Successfully processed POST request to /event/search")
|
||||
except json.JSONDecodeError as e:
|
||||
logger.error(f"Error decoding JSON: {e}")
|
||||
resp.status = falcon.HTTP_400
|
||||
resp.body = json.dumps({"error": "Invalid JSON in request body"})
|
||||
except Exception as e:
|
||||
logger.error(f"Error processing POST request to /event/search: {e}")
|
||||
resp.status = falcon.HTTP_500
|
||||
resp.body = json.dumps({"error": str(e)})
|
||||
Loading…
Add table
Add a link
Reference in a new issue