mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 09:51:11 -05:00
reformat
This commit is contained in:
@@ -10,7 +10,7 @@ from app.v2.notifications.notification_schemas import (
|
||||
)
|
||||
|
||||
|
||||
@v2_notification_blueprint.route("/<notification_id>", methods=['GET'])
|
||||
@v2_notification_blueprint.route("/<notification_id>", methods=["GET"])
|
||||
def get_notification_by_id(notification_id):
|
||||
_data = {"notification_id": notification_id}
|
||||
validate(_data, notification_by_id)
|
||||
@@ -20,20 +20,20 @@ def get_notification_by_id(notification_id):
|
||||
return jsonify(notification.serialize()), 200
|
||||
|
||||
|
||||
@v2_notification_blueprint.route("", methods=['GET'])
|
||||
@v2_notification_blueprint.route("", methods=["GET"])
|
||||
def get_notifications():
|
||||
_data = request.args.to_dict(flat=False)
|
||||
|
||||
# flat=False makes everything a list, but we only ever allow one value for "older_than"
|
||||
if 'older_than' in _data:
|
||||
_data['older_than'] = _data['older_than'][0]
|
||||
if "older_than" in _data:
|
||||
_data["older_than"] = _data["older_than"][0]
|
||||
|
||||
# and client reference
|
||||
if 'reference' in _data:
|
||||
_data['reference'] = _data['reference'][0]
|
||||
if "reference" in _data:
|
||||
_data["reference"] = _data["reference"][0]
|
||||
|
||||
if 'include_jobs' in _data:
|
||||
_data['include_jobs'] = _data['include_jobs'][0]
|
||||
if "include_jobs" in _data:
|
||||
_data["include_jobs"] = _data["include_jobs"][0]
|
||||
|
||||
data = validate(_data, get_notifications_request)
|
||||
|
||||
@@ -42,25 +42,33 @@ def get_notifications():
|
||||
filter_dict=data,
|
||||
key_type=api_user.key_type,
|
||||
personalisation=True,
|
||||
older_than=data.get('older_than'),
|
||||
client_reference=data.get('reference'),
|
||||
page_size=current_app.config.get('API_PAGE_SIZE'),
|
||||
include_jobs=data.get('include_jobs'),
|
||||
count_pages=False
|
||||
older_than=data.get("older_than"),
|
||||
client_reference=data.get("reference"),
|
||||
page_size=current_app.config.get("API_PAGE_SIZE"),
|
||||
include_jobs=data.get("include_jobs"),
|
||||
count_pages=False,
|
||||
)
|
||||
|
||||
def _build_links(notifications):
|
||||
_links = {
|
||||
'current': url_for(".get_notifications", _external=True, **data),
|
||||
"current": url_for(".get_notifications", _external=True, **data),
|
||||
}
|
||||
|
||||
if len(notifications):
|
||||
next_query_params = dict(data, older_than=notifications[-1].id)
|
||||
_links['next'] = url_for(".get_notifications", _external=True, **next_query_params)
|
||||
_links["next"] = url_for(
|
||||
".get_notifications", _external=True, **next_query_params
|
||||
)
|
||||
|
||||
return _links
|
||||
|
||||
return jsonify(
|
||||
notifications=[notification.serialize() for notification in paginated_notifications.items],
|
||||
links=_build_links(paginated_notifications.items)
|
||||
), 200
|
||||
return (
|
||||
jsonify(
|
||||
notifications=[
|
||||
notification.serialize()
|
||||
for notification in paginated_notifications.items
|
||||
],
|
||||
links=_build_links(paginated_notifications.items),
|
||||
),
|
||||
200,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user