Skip to content

Commit

Permalink
fix: filtered deleted entities from user favourite events (#6764)
Browse files Browse the repository at this point in the history
  • Loading branch information
codedsun authored and iamareebjamal committed Jan 22, 2020
1 parent 494608c commit 1c71c6d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions app/api/user_favourite_events.py
Expand Up @@ -35,8 +35,7 @@ def before_post(self, args, kwargs, data):
raise ForbiddenException({'source': ''}, 'Only Authorized Users can favourite an event')

data['user'] = current_user.id
user_favourite_event = UserFavouriteEvent.query.filter_by(
user=current_user, event_id=int(data['event'])).first()
user_favourite_event = find_user_favourite_event_by_id(event_id=data['event'])
if user_favourite_event:
raise ConflictException({'pointer': '/data/relationships/event'}, "Event already favourited")

Expand Down Expand Up @@ -86,8 +85,7 @@ def before_get_object(self, view_kwargs):

if view_kwargs.get('id') is not None:
try:
user_favourite_event = UserFavouriteEvent.query.filter_by(
user=current_user, event_id=view_kwargs['id']).first()
user_favourite_event = find_user_favourite_event_by_id(event_id=view_kwargs['id'])
except NoResultFound:
raise ObjectNotFound({'source': '/data/relationships/event'}, "Object: not found")
else:
Expand All @@ -113,3 +111,9 @@ class UserFavouriteEventRelationship(ResourceRelationship):
methods = ['GET']
data_layer = {'session': db.session,
'model': UserFavouriteEvent}


def find_user_favourite_event_by_id(event_id):
return UserFavouriteEvent.query.filter_by(deleted_at=None,
user=current_user,
event_id=event_id).first()

0 comments on commit 1c71c6d

Please sign in to comment.