server/tags: output tag usage count

This commit is contained in:
rr- 2016-04-29 11:47:18 +02:00
parent 21fd25dd12
commit c55fb2ef41
6 changed files with 8 additions and 1 deletions

4
API.md
View file

@ -1273,7 +1273,8 @@ A single tag. Tags are used to let users search for posts.
"implications": <implications>, "implications": <implications>,
"suggestions": <suggestions>, "suggestions": <suggestions>,
"creationTime": <creation-time>, "creationTime": <creation-time>,
"lastEditTime": <last-edit-time> "lastEditTime": <last-edit-time>,
"usages": <usage-count>
} }
``` ```
@ -1288,6 +1289,7 @@ A single tag. Tags are used to let users search for posts.
the user by the web client on usage. the user by the web client on usage.
- `<creation-time>`: time the tag was created, formatted as per RFC 3339. - `<creation-time>`: time the tag was created, formatted as per RFC 3339.
- `<last-edit-time>`: time the tag was edited, formatted as per RFC 3339. - `<last-edit-time>`: time the tag was edited, formatted as per RFC 3339.
- `<usage-count>`: the number of posts the tag was used in.
## Detailed tag ## Detailed tag
**Description** **Description**

View file

@ -36,6 +36,7 @@ def serialize_tag(tag):
relation.names[0].name for relation in tag.implications], relation.names[0].name for relation in tag.implications],
'creationTime': tag.creation_time, 'creationTime': tag.creation_time,
'lastEditTime': tag.last_edit_time, 'lastEditTime': tag.last_edit_time,
'usages': tag.post_count,
} }
def serialize_tag_with_details(tag): def serialize_tag_with_details(tag):

View file

@ -46,6 +46,7 @@ def test_creating_simple_tags(test_ctx, fake_datetime):
'implications': [], 'implications': [],
'creationTime': datetime.datetime(1997, 12, 1), 'creationTime': datetime.datetime(1997, 12, 1),
'lastEditTime': None, 'lastEditTime': None,
'usages': 0,
} }
assert len(result['snapshots']) == 1 assert len(result['snapshots']) == 1
tag = tags.get_tag_by_name('tag1') tag = tags.get_tag_by_name('tag1')

View file

@ -41,6 +41,7 @@ def test_merging_without_usages(test_ctx, fake_datetime):
'implications': [], 'implications': [],
'creationTime': datetime.datetime(1996, 1, 1), 'creationTime': datetime.datetime(1996, 1, 1),
'lastEditTime': None, 'lastEditTime': None,
'usages': 0,
} }
assert 'snapshots' in result assert 'snapshots' in result
assert tags.try_get_tag_by_name('source') is None assert tags.try_get_tag_by_name('source') is None

View file

@ -57,6 +57,7 @@ def test_retrieving_single(test_ctx):
'lastEditTime': None, 'lastEditTime': None,
'suggestions': [], 'suggestions': [],
'implications': [], 'implications': [],
'usages': 0,
}, },
'snapshots': [], 'snapshots': [],
} }

View file

@ -53,6 +53,7 @@ def test_simple_updating(test_ctx, fake_datetime):
'implications': [], 'implications': [],
'creationTime': datetime.datetime(1996, 1, 1), 'creationTime': datetime.datetime(1996, 1, 1),
'lastEditTime': datetime.datetime(1997, 12, 1), 'lastEditTime': datetime.datetime(1997, 12, 1),
'usages': 0,
} }
assert len(result['snapshots']) == 1 assert len(result['snapshots']) == 1
assert tags.try_get_tag_by_name('tag1') is None assert tags.try_get_tag_by_name('tag1') is None