server/posts: add new fields
This commit is contained in:
parent
037fbc61ec
commit
78612e1da1
8
API.md
8
API.md
|
@ -1523,6 +1523,10 @@ One file together with its metadata posted to the site.
|
|||
"user": <user>,
|
||||
"score": <score>,
|
||||
"ownScore": <own-score>,
|
||||
"tagCount": <tag-count>,
|
||||
"favoriteCount": <favorite-count>,
|
||||
"commentCount": <comment-count>,
|
||||
"noteCount": <note-count>,
|
||||
"featureCount": <feature-count>,
|
||||
"lastFeatureTime": <last-feature-time>,
|
||||
"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.
|
||||
- `<own-score>`: the score (+1/-1 rating) of the given post by the
|
||||
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.
|
||||
- `<last-feature-time>`: the last time the post was featured, formatted as per
|
||||
RFC 3339.
|
||||
|
|
|
@ -84,6 +84,10 @@ def serialize_post(post, authenticated_user, options=None):
|
|||
'user': lambda: users.serialize_user(post.user, authenticated_user),
|
||||
'score': lambda: post.score,
|
||||
'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,
|
||||
'lastFeatureTime': lambda: post.last_feature_time,
|
||||
'favoritedBy': lambda: [
|
||||
|
|
|
@ -96,13 +96,11 @@ def test_serialize_post(
|
|||
post.canvas_height = 300
|
||||
post.flags = ['loop']
|
||||
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.add_all([
|
||||
comment_factory(user=user_factory(name='commenter1'), post=post),
|
||||
comment_factory(user=user_factory(name='commenter2'), post=post),
|
||||
db.PostFavorite(
|
||||
post=post,
|
||||
user=user_factory(name='fav1'),
|
||||
|
@ -150,6 +148,10 @@ def test_serialize_post(
|
|||
'user': 'post author',
|
||||
'score': 1,
|
||||
'ownScore': -1,
|
||||
'tagCount': 2,
|
||||
'favoriteCount': 1,
|
||||
'commentCount': 2,
|
||||
'noteCount': 0,
|
||||
'featureCount': 1,
|
||||
'lastFeatureTime': datetime.datetime(1999, 1, 1),
|
||||
'favoritedBy': ['fav1'],
|
||||
|
|
Loading…
Reference in New Issue