diff --git a/API.md b/API.md index da2edd6..9c87a13 100644 --- a/API.md +++ b/API.md @@ -1523,6 +1523,10 @@ One file together with its metadata posted to the site. "user": , "score": , "ownScore": , + "tagCount": , + "favoriteCount": , + "commentCount": , + "noteCount": , "featureCount": , "lastFeatureTime": , "favoritedBy": , @@ -1582,6 +1586,10 @@ One file together with its metadata posted to the site. - ``: the collective score (+1/-1 rating) of the given post. - ``: the score (+1/-1 rating) of the given post by the authenticated user. +- ``: how many tags the post is tagged with +- ``: how many users have the post in their favorites +- ``: how many comments are filed under that post +- ``: how many notes the post has - ``: how many times has the post been featured. - ``: the last time the post was featured, formatted as per RFC 3339. diff --git a/server/szurubooru/func/posts.py b/server/szurubooru/func/posts.py index 99ff36d..498bad3 100644 --- a/server/szurubooru/func/posts.py +++ b/server/szurubooru/func/posts.py @@ -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: [ diff --git a/server/szurubooru/tests/func/test_posts.py b/server/szurubooru/tests/func/test_posts.py index 4d45a97..fa8abc4 100644 --- a/server/szurubooru/tests/func/test_posts.py +++ b/server/szurubooru/tests/func/test_posts.py @@ -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'],