mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 10:21:14 -05:00
Capture the count of sent notifications for a job
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
from flask import current_app
|
||||
from app import db
|
||||
from app.models import Notification
|
||||
from app.models import Notification, Job
|
||||
from sqlalchemy import desc
|
||||
|
||||
|
||||
def dao_create_notification(notification):
|
||||
if notification.job_id:
|
||||
db.session.query(Job).update({Job.notifications_sent: Job.notifications_sent + 1})
|
||||
db.session.add(notification)
|
||||
db.session.commit()
|
||||
|
||||
@@ -19,12 +21,12 @@ def get_notification_for_job(service_id, job_id, notification_id):
|
||||
|
||||
|
||||
def get_notifications_for_job(service_id, job_id, page=1):
|
||||
query = Notification.query.filter_by(service_id=service_id, job_id=job_id)\
|
||||
.order_by(desc(Notification.created_at))\
|
||||
query = Notification.query.filter_by(service_id=service_id, job_id=job_id) \
|
||||
.order_by(desc(Notification.created_at)) \
|
||||
.paginate(
|
||||
page=page,
|
||||
per_page=current_app.config['PAGE_SIZE']
|
||||
)
|
||||
page=page,
|
||||
per_page=current_app.config['PAGE_SIZE']
|
||||
)
|
||||
return query
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user