server/posts: add ownFavorite field to posts

This commit is contained in:
rr- 2016-06-06 20:57:12 +02:00
parent 93a5af2097
commit b28f689077
3 changed files with 7 additions and 0 deletions

3
API.md
View file

@ -1549,6 +1549,7 @@ One file together with its metadata posted to the site.
"user": <user>,
"score": <score>,
"ownScore": <own-score>,
"ownFavorite": <own-favorite>,
"tagCount": <tag-count>,
"favoriteCount": <favorite-count>,
"commentCount": <comment-count>,
@ -1612,6 +1613,8 @@ One file together with its metadata posted to the site.
- `<score>`: the collective score (+1/-1 rating) of the given post.
- `<own-score>`: the score (+1/-1 rating) of the given post by the
authenticated user.
- `<own-favorite>`: whether the authenticated user has given post in their
favorites.
- `<tag-count>`: how many tags the post is tagged with
- `<favorite-count>`: how many users have the post in their favorites
- `<comment-count>`: how many comments are filed under that post

View file

@ -93,6 +93,9 @@ def serialize_post(post, authenticated_user, options=None):
'user': lambda: users.serialize_micro_user(post.user),
'score': lambda: post.score,
'ownScore': lambda: scores.get_score(post, authenticated_user),
'ownFavorite': lambda: len(
[user for user in post.favorited_by \
if user.user_id == authenticated_user.user_id]) > 0,
'tagCount': lambda: post.tag_count,
'favoriteCount': lambda: post.favorite_count,
'commentCount': lambda: post.comment_count,

View file

@ -147,6 +147,7 @@ def test_serialize_post(
'notes': [],
'user': 'post author',
'score': 1,
'ownFavorite': False,
'ownScore': -1,
'tagCount': 2,
'favoriteCount': 1,