Skip to content

Commit

Permalink
Merge pull request #14 from admtlab/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
marksilvis authored Dec 7, 2017
2 parents 3a4aa93 + 08b9e7c commit 2d81706
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pittgrub/handlers/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def get(self, event_id, path):
else:
event_image = EventImage.get_by_event(event_id)
if event_image is None:
self.success(status=200)
self.write_error(404, 'Event does not have an image')
else:
image = self.image_store.fetch_image(event_image.id)
if image is None:
Expand Down
23 changes: 16 additions & 7 deletions pittgrub/handlers/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import dateutil.parser
from copy import deepcopy
from __init__ import __version__
from db import User, FoodPreference, Event, EventFoodPreference, UserAcceptedEvent, UserRecommendedEvent, health_check
from db import User, FoodPreference, Event, EventFoodPreference, EventImage, UserAcceptedEvent, UserRecommendedEvent, health_check
from handlers.response import Payload, ErrorResponse
from handlers.base import BaseHandler, SecureHandler
from requests.exceptions import ConnectionError, HTTPError
Expand Down Expand Up @@ -225,16 +225,25 @@ class EventHandler(BaseHandler):
def get(self, path):
path = path.replace('/', '')

# get data
if path:
# get single event
value = Event.get_by_id(path)
if value is None:
# event not found
self.write_error(404, f'Event not found with id: {path}')
else:
# event found
self.set_status(200)
payload = Payload(value)
event_image = EventImage.get_by_event(value.id)
# attach image link if available
if event_image is not None:
payload.add("image", f"/events/{path}/images")
# send response
self.finish(payload)
else:
# get event list
value = Event.get_all_newest()

# response
if value is None:
self.write_error(404, f'Event not found with id: {id}')
else:
self.set_status(200)
payload = Payload(value)
self.finish(payload)
Expand Down

0 comments on commit 2d81706

Please sign in to comment.