Create 'v2' get notifications route

Return multiple notifications for a service.
Choosing a page_size or a page_number is no longer allowed.
Instead, there is a `next` link included with will return the
next {default_page_size} notifications in the sequence.

Query parameters accepted are:

 - template_type: filter by specific template types
 - status: filter by specific statuses
 - older_than: return a chronological list of notifications older
   than this one. The notification with the id that is passed in
   is _not_ returned.

Note that both `template_type` and `status` can accept multiple
parameters.  Thus it is possible to call
`/v2/notifications?status=created&status=sending&status=delivered`
This commit is contained in:
Paul Craig
2016-11-23 11:44:38 +00:00
parent 1fce30aaa7
commit effbd315e0
3 changed files with 36 additions and 7 deletions

View File

@@ -262,7 +262,8 @@ def get_notifications_for_service(
key_type=None,
personalisation=False,
include_jobs=False,
include_from_test_key=False
include_from_test_key=False,
older_than=None
):
if page_size is None:
page_size = current_app.config['PAGE_SIZE']
@@ -273,6 +274,11 @@ def get_notifications_for_service(
days_ago = date.today() - timedelta(days=limit_days)
filters.append(func.date(Notification.created_at) >= days_ago)
if older_than is not None:
older_than_created_at = db.session.query(
Notification.created_at).filter(Notification.id == older_than).as_scalar()
filters.append(Notification.created_at < older_than_created_at)
if not include_jobs or (key_type and key_type != KEY_TYPE_NORMAL):
filters.append(Notification.job_id.is_(None))