Verified Commit aa9637eb authored by Maciej Lenartowicz's avatar Maciej Lenartowicz
Browse files

Added sort parameter to notifications endpoint

parent 639d8e8c
Pipeline #51379 passed with stage
in 1 minute and 57 seconds
......@@ -10,6 +10,9 @@ def notifications():
See `foris-controller JSON schema
<https://gitlab.labs.nic.cz/turris/foris-controller/blob/master/foris_controller_modules/router_notifications/schema/router_notifications.json>`_.
Notifications are sorted by ``created_at`` in descending order (newest first). You can change the order with the
`sort` parameter, i.e. ``notifications?sort=asc``.
**Example response**:
.. sourcecode:: http
......@@ -40,8 +43,9 @@ def notifications():
if request.method == 'GET':
request_data = {'lang': _get_locale_from_backend(current_app)}
response = current_app.backend.perform('router_notifications', 'list', request_data)
if response.get("notifications"):
response["notifications"].reverse()
sort = request.args.get('sort')
if sort != 'asc':
response['notifications'].reverse()
elif request.method == 'POST':
data = request.json
response = current_app.backend.perform('router_notifications', 'mark_as_displayed', data)
......
......@@ -33,6 +33,9 @@ def send_mock(module, action, data, timeout=None, controller_id=None):
'get_settings': {
'reboots': {}
},
'list': {
'notifications': []
}
},
'networks': {
'get_settings': {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment