server/posts: include thumbnail URLs in relations
This commit is contained in:
parent
5800f0ebc7
commit
48d6fb6b43
2 changed files with 23 additions and 2 deletions
9
API.md
9
API.md
|
@ -68,6 +68,7 @@
|
||||||
- [Tag category](#tag-category)
|
- [Tag category](#tag-category)
|
||||||
- [Tag](#tag)
|
- [Tag](#tag)
|
||||||
- [Post](#post)
|
- [Post](#post)
|
||||||
|
- [Micro post](#micro-post)
|
||||||
- [Note](#note)
|
- [Note](#note)
|
||||||
- [Comment](#comment)
|
- [Comment](#comment)
|
||||||
- [Snapshot](#snapshot)
|
- [Snapshot](#snapshot)
|
||||||
|
@ -1625,7 +1626,8 @@ One file together with its metadata posted to the site.
|
||||||
- `<flags>`: various flags such as whether the post is looped, represented as
|
- `<flags>`: various flags such as whether the post is looped, represented as
|
||||||
array of plain strings.
|
array of plain strings.
|
||||||
- `<tags>`: list of tag names the post is tagged with.
|
- `<tags>`: list of tag names the post is tagged with.
|
||||||
- `<relations>`: a list of related post IDs. Links to related posts are shown
|
- `<relations>`: a list of related posts, serialized as [micro post
|
||||||
|
resources](#micro-post). Links to related posts are shown
|
||||||
to the user by the web client.
|
to the user by the web client.
|
||||||
- `<notes>`: a list of post annotations, serialized as list of [note
|
- `<notes>`: a list of post annotations, serialized as list of [note
|
||||||
resources](#note).
|
resources](#note).
|
||||||
|
@ -1650,6 +1652,11 @@ One file together with its metadata posted to the site.
|
||||||
earlier versions.
|
earlier versions.
|
||||||
- `<comment>`: a [comment resource](#comment) for given post.
|
- `<comment>`: a [comment resource](#comment) for given post.
|
||||||
|
|
||||||
|
## Micro post
|
||||||
|
**Description**
|
||||||
|
|
||||||
|
A [post resource](#post) stripped down to `name` and `thumbnailUrl` fields.
|
||||||
|
|
||||||
## Note
|
## Note
|
||||||
**Description**
|
**Description**
|
||||||
|
|
||||||
|
|
|
@ -90,7 +90,15 @@ def serialize_post(post, authenticated_user, options=None):
|
||||||
tag.category.name,
|
tag.category.name,
|
||||||
tag.names[0].name)
|
tag.names[0].name)
|
||||||
)],
|
)],
|
||||||
'relations': lambda: [rel.post_id for rel in post.relations],
|
'relations': lambda: sorted(
|
||||||
|
{
|
||||||
|
post['id']:
|
||||||
|
post for post in [
|
||||||
|
serialize_micro_post(rel) \
|
||||||
|
for rel in post.related_by + post.relating_to
|
||||||
|
]
|
||||||
|
}.values(),
|
||||||
|
key=lambda post: post['id']),
|
||||||
'user': lambda: users.serialize_micro_user(post.user),
|
'user': lambda: users.serialize_micro_user(post.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),
|
||||||
|
@ -120,6 +128,12 @@ def serialize_post(post, authenticated_user, options=None):
|
||||||
},
|
},
|
||||||
options)
|
options)
|
||||||
|
|
||||||
|
def serialize_micro_post(post):
|
||||||
|
return serialize_post(
|
||||||
|
post,
|
||||||
|
authenticated_user=None,
|
||||||
|
options=['id', 'thumbnailUrl'])
|
||||||
|
|
||||||
def get_post_count():
|
def get_post_count():
|
||||||
return db.session.query(sqlalchemy.func.count(db.Post.post_id)).one()[0]
|
return db.session.query(sqlalchemy.func.count(db.Post.post_id)).one()[0]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue