server/pools: serialize pools as micro resource within post resources
Fixes #348
This commit is contained in:
parent
802051399f
commit
1ef0419dc2
4 changed files with 15 additions and 22 deletions
|
@ -99,6 +99,7 @@
|
|||
- [Micro post](#micro-post)
|
||||
- [Pool category](#pool-category)
|
||||
- [Pool](#pool)
|
||||
- [Micro pool](#micro-pool)
|
||||
- [Note](#note)
|
||||
- [Comment](#comment)
|
||||
- [Snapshot](#snapshot)
|
||||
|
@ -2455,7 +2456,7 @@ One file together with its metadata posted to the site.
|
|||
- `<mime-type>`: subsidiary to `<type>`, used to tell exact content format;
|
||||
useful for `<video>` tags for instance.
|
||||
- `<comment>`: a [comment resource](#comment) for given post.
|
||||
- `<pool>`: a [pool resource](#pool) for given post.
|
||||
- `<pool>`: a [micro pool resource](#micro-pool) in which the post is a member of.
|
||||
|
||||
## Micro post
|
||||
**Description**
|
||||
|
@ -2545,6 +2546,12 @@ An ordered list of posts, with a description and category.
|
|||
- `<description>`: the pool description (instructions how to use, history etc.)
|
||||
The client should render it as Markdown.
|
||||
|
||||
## Micro pool
|
||||
**Description**
|
||||
|
||||
A [pool resource](#pool) stripped down to `id`, `names`, `category`,
|
||||
`description` and `postCount` fields.
|
||||
|
||||
## Comment
|
||||
**Description**
|
||||
|
||||
|
|
|
@ -152,6 +152,12 @@ def serialize_pool(
|
|||
return PoolSerializer(pool).serialize(options)
|
||||
|
||||
|
||||
def serialize_micro_pool(pool: model.Pool) -> Optional[rest.Response]:
|
||||
return serialize_pool(
|
||||
pool, options=["id", "names", "category", "description", "postCount"]
|
||||
)
|
||||
|
||||
|
||||
def try_get_pool_by_id(pool_id: int) -> Optional[model.Pool]:
|
||||
return (
|
||||
db.session.query(model.Pool)
|
||||
|
|
|
@ -334,7 +334,7 @@ class PostSerializer(serialization.BaseSerializer):
|
|||
|
||||
def serialize_pools(self) -> List[Any]:
|
||||
return [
|
||||
pools.serialize_pool(pool)
|
||||
pools.serialize_micro_pool(pool)
|
||||
for pool in sorted(
|
||||
self.post.pools, key=lambda pool: pool.creation_time
|
||||
)
|
||||
|
|
|
@ -247,16 +247,6 @@ def test_serialize_post(
|
|||
"description": "desc",
|
||||
"category": "test-cat1",
|
||||
"postCount": 1,
|
||||
"posts": [
|
||||
{
|
||||
"id": 1,
|
||||
"thumbnailUrl": "http://example.com/"
|
||||
"generated-thumbnails/1_244c8840887984c4.jpg",
|
||||
}
|
||||
],
|
||||
"version": 1,
|
||||
"creationTime": datetime(1996, 1, 1),
|
||||
"lastEditTime": datetime(1998, 1, 1),
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
|
@ -264,16 +254,6 @@ def test_serialize_post(
|
|||
"description": "desc2",
|
||||
"category": "test-cat2",
|
||||
"postCount": 1,
|
||||
"posts": [
|
||||
{
|
||||
"id": 1,
|
||||
"thumbnailUrl": "http://example.com/"
|
||||
"generated-thumbnails/1_244c8840887984c4.jpg",
|
||||
}
|
||||
],
|
||||
"version": 1,
|
||||
"creationTime": datetime(1996, 1, 1),
|
||||
"lastEditTime": datetime(1998, 1, 1),
|
||||
},
|
||||
],
|
||||
"user": "post author",
|
||||
|
|
Loading…
Reference in a new issue