And an endpoint to get uploaded letters for a day

Because we won’t be showing uploaded letters individually on the uploads
page any more we need a way of listing them. This should be by printing
day, to match how we’re grouping them on the uploads page.

The response matches a normal `get_notifications` response so we can
reuse the same code in the admin app.
This commit is contained in:
Chris Hill-Scott
2020-05-11 10:51:40 +01:00
parent 421c1aac96
commit 864c6772b3
4 changed files with 185 additions and 2 deletions

View File

@@ -1,5 +1,7 @@
from datetime import datetime
from flask import (
Blueprint,
abort,
jsonify,
request,
current_app
@@ -9,10 +11,14 @@ from app.dao.fact_notification_status_dao import fetch_notification_statuses_for
from app.dao.jobs_dao import (
dao_get_notification_outcomes_for_job
)
from app.dao.uploads_dao import dao_get_uploads_by_service_id
from app.dao.uploads_dao import (
dao_get_uploaded_letters_by_print_date,
dao_get_uploads_by_service_id,
)
from app.errors import (
register_errors,
)
from app.schemas import notification_with_template_schema
from app.utils import pagination_links, midnight_n_days_ago
upload_blueprint = Blueprint('upload', __name__, url_prefix='/service/<uuid:service_id>/upload')
@@ -74,3 +80,31 @@ def get_paginated_uploads(service_id, limit_days, page):
service_id=service_id
)
}
@upload_blueprint.route('/uploaded-letters/<letter_print_date>', methods=['GET'])
def get_uploaded_letter_by_service_and_print_day(service_id, letter_print_date):
try:
letter_print_datetime = datetime.strptime(letter_print_date, '%Y-%m-%d')
except ValueError:
abort(404)
pagination = dao_get_uploaded_letters_by_print_date(
service_id,
letter_print_date=letter_print_datetime,
page=request.args.get('page', type=int),
page_size=current_app.config['PAGE_SIZE']
)
return jsonify({
'notifications': notification_with_template_schema.dump(
pagination.items,
many=True,
).data,
'page_size': pagination.per_page,
'total': pagination.total,
'links': pagination_links(
pagination,
'.get_uploaded_letter_by_service_and_print_day',
service_id=service_id,
letter_print_date=letter_print_date,
),
})