mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 01:41:05 -05:00
[WIP] New model class and dao for notification. This will be used for
recording status and outcome of sending notifications.
This commit is contained in:
22
app/dao/notifications_dao.py
Normal file
22
app/dao/notifications_dao.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from app import db
|
||||
from app.models import Notification
|
||||
|
||||
|
||||
def save_notification(notification, update_dict={}):
|
||||
if update_dict:
|
||||
update_dict.pop('id', None)
|
||||
update_dict.pop('job', None)
|
||||
update_dict.pop('service_id', None)
|
||||
update_dict.pop('template_id', None)
|
||||
Notification.query.filter_by(id=notification.id).update(update_dict)
|
||||
else:
|
||||
db.session.add(notification)
|
||||
db.session.commit()
|
||||
|
||||
|
||||
def get_notification(job_id, notification_id):
|
||||
return Notification.query.filter_by(job_id=job_id, id=notification_id).one()
|
||||
|
||||
|
||||
def get_notifications_by_job(job_id):
|
||||
return Notification.query.filter_by(job_id=job_id).all()
|
||||
@@ -189,3 +189,32 @@ class VerifyCode(db.Model):
|
||||
|
||||
def check_code(self, cde):
|
||||
return check_hash(cde, self._code)
|
||||
|
||||
|
||||
NOTIFICATION_STATUS_TYPES = ['sent', 'failed']
|
||||
|
||||
|
||||
class Notification(db.Model):
|
||||
|
||||
__tablename__ = 'notifications'
|
||||
|
||||
id = db.Column(UUID(as_uuid=True), primary_key=True)
|
||||
to = db.Column(db.String, nullable=False)
|
||||
job_id = db.Column(UUID(as_uuid=True), db.ForeignKey('jobs.id'), index=True, unique=False, nullable=False)
|
||||
job = db.relationship('Job', backref=db.backref('notifications', lazy='dynamic'))
|
||||
service_id = db.Column(UUID(as_uuid=True), db.ForeignKey('services.id'), index=True, unique=False)
|
||||
template_id = db.Column(db.BigInteger, db.ForeignKey('templates.id'), index=True, unique=False)
|
||||
created_at = db.Column(
|
||||
db.DateTime,
|
||||
index=False,
|
||||
unique=False,
|
||||
nullable=False,
|
||||
default=datetime.datetime.now)
|
||||
updated_at = db.Column(
|
||||
db.DateTime,
|
||||
index=False,
|
||||
unique=False,
|
||||
nullable=True,
|
||||
onupdate=datetime.datetime.now)
|
||||
status = db.Column(
|
||||
db.Enum(*NOTIFICATION_STATUS_TYPES, name='notification_status_types'), nullable=False, default='sent')
|
||||
|
||||
Reference in New Issue
Block a user