server/posts: add new fields

This commit is contained in:
rr- 2016-05-30 23:23:22 +02:00
parent 037fbc61ec
commit 78612e1da1
3 changed files with 18 additions and 4 deletions

8
API.md
View File

@ -1523,6 +1523,10 @@ One file together with its metadata posted to the site.
"user": <user>, "user": <user>,
"score": <score>, "score": <score>,
"ownScore": <own-score>, "ownScore": <own-score>,
"tagCount": <tag-count>,
"favoriteCount": <favorite-count>,
"commentCount": <comment-count>,
"noteCount": <note-count>,
"featureCount": <feature-count>, "featureCount": <feature-count>,
"lastFeatureTime": <last-feature-time>, "lastFeatureTime": <last-feature-time>,
"favoritedBy": <favorited-by>, "favoritedBy": <favorited-by>,
@ -1582,6 +1586,10 @@ One file together with its metadata posted to the site.
- `<score>`: the collective score (+1/-1 rating) of the given post. - `<score>`: the collective score (+1/-1 rating) of the given post.
- `<own-score>`: the score (+1/-1 rating) of the given post by the - `<own-score>`: the score (+1/-1 rating) of the given post by the
authenticated user. authenticated user.
- `<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
- `<note-count>`: how many notes the post has
- `<feature-count>`: how many times has the post been featured. - `<feature-count>`: how many times has the post been featured.
- `<last-feature-time>`: the last time the post was featured, formatted as per - `<last-feature-time>`: the last time the post was featured, formatted as per
RFC 3339. RFC 3339.

View File

@ -84,6 +84,10 @@ def serialize_post(post, authenticated_user, options=None):
'user': lambda: users.serialize_user(post.user, authenticated_user), 'user': lambda: users.serialize_user(post.user, authenticated_user),
'score': lambda: post.score, 'score': lambda: post.score,
'ownScore': lambda: scores.get_score(post, authenticated_user), 'ownScore': lambda: scores.get_score(post, authenticated_user),
'tagCount': lambda: post.tag_count,
'favoriteCount': lambda: post.favorite_count,
'commentCount': lambda: post.comment_count,
'noteCount': lambda: post.note_count,
'featureCount': lambda: post.feature_count, 'featureCount': lambda: post.feature_count,
'lastFeatureTime': lambda: post.last_feature_time, 'lastFeatureTime': lambda: post.last_feature_time,
'favoritedBy': lambda: [ 'favoritedBy': lambda: [

View File

@ -96,13 +96,11 @@ def test_serialize_post(
post.canvas_height = 300 post.canvas_height = 300
post.flags = ['loop'] post.flags = ['loop']
db.session.add(post) db.session.add(post)
post.comments = [
comment_factory(user=user_factory(name='commenter1')),
comment_factory(user=user_factory(name='commenter2')),
]
db.session.flush() db.session.flush()
db.session.add_all([ db.session.add_all([
comment_factory(user=user_factory(name='commenter1'), post=post),
comment_factory(user=user_factory(name='commenter2'), post=post),
db.PostFavorite( db.PostFavorite(
post=post, post=post,
user=user_factory(name='fav1'), user=user_factory(name='fav1'),
@ -150,6 +148,10 @@ def test_serialize_post(
'user': 'post author', 'user': 'post author',
'score': 1, 'score': 1,
'ownScore': -1, 'ownScore': -1,
'tagCount': 2,
'favoriteCount': 1,
'commentCount': 2,
'noteCount': 0,
'featureCount': 1, 'featureCount': 1,
'lastFeatureTime': datetime.datetime(1999, 1, 1), 'lastFeatureTime': datetime.datetime(1999, 1, 1),
'favoritedBy': ['fav1'], 'favoritedBy': ['fav1'],