-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix: Get and delete event favourite using event_id #6063
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 12 commits
13d5ed8
fd25014
f9e835f
2a615ba
14a1647
2703742
b6ccadf
e582254
0744c78
c744603
e873d95
1f60d59
a19271a
5e370a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,16 @@ | ||
| from flask_rest_jsonapi import ResourceDetail, ResourceList, ResourceRelationship | ||
| from flask import request, current_app as app | ||
| from flask_jwt import current_identity as current_user, _jwt_required | ||
| from flask_jwt import current_identity as current_user, _jwt_required, jwt_required | ||
| from flask_rest_jsonapi import ResourceDetail, ResourceList, ResourceRelationship | ||
| from flask_rest_jsonapi.exceptions import ObjectNotFound | ||
| from sqlalchemy.orm.exc import NoResultFound | ||
|
|
||
| from app.models.user import User | ||
| from app.api.helpers.db import safe_query | ||
| from app.api.helpers.permission_manager import has_access | ||
| from app.api.helpers.exceptions import ForbiddenException, ConflictException | ||
| from app.api.helpers.permission_manager import has_access | ||
| from app.api.helpers.utilities import require_relationship | ||
| from app.api.schema.user_favourite_events import UserFavouriteEventSchema | ||
| from app.models import db | ||
| from app.models.user import User | ||
| from app.models.user_favourite_event import UserFavouriteEvent | ||
|
|
||
|
|
||
|
|
@@ -79,11 +81,45 @@ class UserFavouriteEventDetail(ResourceDetail): | |
| """ | ||
| User Favourite Events detail by id | ||
| """ | ||
| @jwt_required() | ||
| 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() | ||
| except NoResultFound: | ||
| raise ObjectNotFound({'source': ''}, "Object: not found") | ||
|
||
| else: | ||
| if user_favourite_event is not None: | ||
| view_kwargs['id'] = user_favourite_event.id | ||
| else: | ||
| view_kwargs['id'] = None | ||
|
|
||
| @jwt_required() | ||
| def before_delete_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() | ||
| except NoResultFound: | ||
| raise ObjectNotFound({'source': ''}, "Object: not found") | ||
| else: | ||
| if user_favourite_event: | ||
| if user_favourite_event.event_id is not None: | ||
prateekj117 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| view_kwargs['id'] = user_favourite_event.id | ||
| else: | ||
| view_kwargs['id'] = None | ||
|
|
||
| methods = ['GET', 'DELETE'] | ||
| schema = UserFavouriteEventSchema | ||
| data_layer = {'session': db.session, | ||
| 'model': UserFavouriteEvent} | ||
| 'model': UserFavouriteEvent, | ||
| 'methods': { | ||
| 'before_delete_object': before_delete_object, | ||
| 'before_get_object': before_get_object, | ||
| }} | ||
|
|
||
|
|
||
| class UserFavouriteEventRelationship(ResourceRelationship): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25594,9 +25594,9 @@ This Group's APIs can be used for adding a particular event to the favourite lis | |
| } | ||
| } | ||
|
|
||
| ## Favourite Events Detail [/v1/user-favourite-events/{user_favourite_event_id}] | ||
| ## Favourite Events Detail [/v1/user-favourite-events/{event_id}] | ||
| + Parameters | ||
| + user_favourite_event_id: 1 (integer) - ID of the Favourite Event | ||
| + event_id: 1 (integer) - ID of the Event in the form of an integer | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changing name of parameters won't fix anything.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @iamareebjamal But it should be changed, right?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, your version is more explicit, but if you changed it in hopes that it'll fix the error, then it won't |
||
|
|
||
| ### Get Details [GET] | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
paranthesis is redundant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iamareebjamal It shows error when not using paranthesis.

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK