-
Notifications
You must be signed in to change notification settings - Fork 22
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
User favorites route #38
Conversation
@@ -117,6 +117,17 @@ class EntryView(RetrieveAPIView): | |||
pagination_class = None | |||
|
|||
|
|||
class FavoriteEntries(ListAPIView): |
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.
I didn't inherit from EntriesListView
because I didn't want this to be POSTable, but we could use some of the filtering options that view has. Thoughts on this?
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.
Hmm, could we implement this as, itself, a filter? I.e. when users call /entries/favorites[?args]
Django internally serves up the result for /entries/[?args]&is_favorited=True
?
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.
Not easily, as per our chat.
def get_queryset(self): | ||
entries = set() | ||
user = self.request.user.id | ||
for f in UserFavorites.objects.filter(user=user).select_related('entry'): |
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.
small nit: the interpreter doesn't care, but maintainers do, so avoiding single letter variables is generally good practice. Can we call this what it is? (like "entry" or "favorite", although with the user_favs refactor, "bookmark")
@@ -117,6 +117,17 @@ class EntryView(RetrieveAPIView): | |||
pagination_class = None | |||
|
|||
|
|||
class FavoriteEntries(ListAPIView): |
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.
Hmm, could we implement this as, itself, a filter? I.e. when users call /entries/favorites[?args]
Django internally serves up the result for /entries/[?args]&is_favorited=True
?
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.
preeeeetty nice!
All this needs is tests then? |
I've added some tests. One more look at this? |
self.assertEqual(bookmarkResponse.status_code, 200) | ||
|
||
bookmarkJson = json.loads(str(bookmarkResponse.content, 'utf-8')) | ||
self.assertEqual(len(bookmarkJson), 1) |
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.
missing newline because github is hilarious that way
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.
R+ with a nit because github wants newlines at the end of files for... reasons...
* user/entry linking through a "favorite" construction. REST endpoint: <PUT> /entries/<id>/bookmark Behaviour: calling the endpoint, by an authenticated user, will mark the entry as bookmarked by the that user. Calling it again unbookmarks the entry. * User favorites route (#38) * User favorites route * ‘favorite’ -> ‘bookmark’ * Bookmark view tests
No description provided.