mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 15:46:07 -05:00
Fixed up the get_notitication endpoint
- returns a notification
This commit is contained in:
@@ -30,9 +30,9 @@ def create_app(config_name, config_overrides=None):
|
||||
application.config['NOTIFY_API_ENVIRONMENT'] = config_name
|
||||
application.config.from_object(configs[config_name])
|
||||
|
||||
init_app(application, config_overrides)
|
||||
db.init_app(application)
|
||||
ma.init_app(application)
|
||||
init_app(application, config_overrides)
|
||||
logging.init_app(application)
|
||||
twilio_client.init_app(application)
|
||||
celery.init_app(application)
|
||||
|
||||
@@ -22,8 +22,6 @@ class TwilioClient(SmsClient):
|
||||
config.config.get('TWILIO_ACCOUNT_SID'),
|
||||
config.config.get('TWILIO_AUTH_TOKEN'))
|
||||
self.from_number = config.config.get('TWILIO_NUMBER')
|
||||
print(config.config)
|
||||
|
||||
|
||||
def send_sms(self, notification, content):
|
||||
try:
|
||||
|
||||
@@ -14,9 +14,13 @@ def save_notification(notification, update_dict={}):
|
||||
db.session.commit()
|
||||
|
||||
|
||||
def get_notification(service_id, job_id, notification_id):
|
||||
def get_notification_for_job(service_id, job_id, notification_id):
|
||||
return Notification.query.filter_by(service_id=service_id, job_id=job_id, id=notification_id).one()
|
||||
|
||||
|
||||
def get_notifications(service_id, job_id):
|
||||
def get_notifications_for_job(service_id, job_id):
|
||||
return Notification.query.filter_by(service_id=service_id, job_id=job_id).all()
|
||||
|
||||
|
||||
def get_notification(service_id, notification_id):
|
||||
return Notification.query.filter_by(service_id=service_id, id=notification_id).one()
|
||||
|
||||
@@ -17,11 +17,7 @@ from app.dao.jobs_dao import (
|
||||
get_jobs_by_service
|
||||
)
|
||||
|
||||
from app.dao.notifications_dao import (
|
||||
save_notification,
|
||||
get_notification,
|
||||
get_notifications
|
||||
)
|
||||
from app.dao import notifications_dao
|
||||
|
||||
from app.schemas import (
|
||||
job_schema,
|
||||
@@ -89,7 +85,7 @@ def create_notification_for_job(service_id, job_id):
|
||||
if errors:
|
||||
return jsonify(result="error", message=errors), 400
|
||||
try:
|
||||
save_notification(notification)
|
||||
notifications_dao.save_notification(notification)
|
||||
except Exception as e:
|
||||
return jsonify(result="error", message=str(e)), 500
|
||||
return jsonify(data=notification_status_schema.dump(notification).data), 201
|
||||
@@ -100,7 +96,7 @@ def create_notification_for_job(service_id, job_id):
|
||||
def get_notification_for_job(service_id, job_id, notification_id=None):
|
||||
if notification_id:
|
||||
try:
|
||||
notification = get_notification(service_id, job_id, notification_id)
|
||||
notification = notifications_dao.get_notification_for_job(service_id, job_id, notification_id)
|
||||
data, errors = notification_status_schema.dump(notification)
|
||||
return jsonify(data=data)
|
||||
except DataError:
|
||||
@@ -108,7 +104,7 @@ def get_notification_for_job(service_id, job_id, notification_id=None):
|
||||
except NoResultFound:
|
||||
return jsonify(result="error", message="Notification not found"), 404
|
||||
else:
|
||||
notifications = get_notifications(service_id, job_id)
|
||||
notifications = notifications_dao.get_notifications_for_job(service_id, job_id)
|
||||
data, errors = notifications_status_schema.dump(notifications)
|
||||
return jsonify(data=data)
|
||||
|
||||
@@ -116,13 +112,13 @@ def get_notification_for_job(service_id, job_id, notification_id=None):
|
||||
@job.route('/<job_id>/notification/<notification_id>', methods=['PUT'])
|
||||
def update_notification_for_job(service_id, job_id, notification_id):
|
||||
|
||||
notification = get_notification(service_id, job_id, notification_id)
|
||||
notification = notifications_dao.get_notification_for_job(service_id, job_id, notification_id)
|
||||
update_dict, errors = notification_status_schema_load_json.load(request.get_json())
|
||||
|
||||
if errors:
|
||||
return jsonify(result="error", message=errors), 400
|
||||
try:
|
||||
save_notification(notification, update_dict=update_dict)
|
||||
notifications_dao.save_notification(notification, update_dict=update_dict)
|
||||
except Exception as e:
|
||||
return jsonify(result="error", message=str(e)), 400
|
||||
|
||||
|
||||
@@ -4,16 +4,20 @@ from flask import (
|
||||
Blueprint,
|
||||
jsonify,
|
||||
request,
|
||||
current_app)
|
||||
from itsdangerous import URLSafeSerializer
|
||||
current_app
|
||||
)
|
||||
|
||||
from itsdangerous import URLSafeSerializer
|
||||
from app import api_user
|
||||
from app.aws_sqs import add_notification_to_queue
|
||||
from app.dao import (templates_dao)
|
||||
from app.dao import (templates_dao, notifications_dao)
|
||||
from app.schemas import (
|
||||
email_notification_schema, sms_template_notification_schema)
|
||||
email_notification_schema,
|
||||
sms_template_notification_schema,
|
||||
notification_status_schema
|
||||
)
|
||||
from app.celery.tasks import send_sms
|
||||
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
|
||||
notifications = Blueprint('notifications', __name__)
|
||||
|
||||
@@ -22,10 +26,13 @@ def create_notification_id():
|
||||
return str(uuid.uuid4())
|
||||
|
||||
|
||||
@notifications.route('/<notification_id>', methods=['GET'])
|
||||
@notifications.route('/<string:notification_id>', methods=['GET'])
|
||||
def get_notifications(notification_id):
|
||||
# TODO return notification id details
|
||||
return jsonify({'id': notification_id}), 200
|
||||
try:
|
||||
notification = notifications_dao.get_notification(api_user['client'], notification_id)
|
||||
return jsonify({'notification': notification_status_schema.dump(notification).data}), 200
|
||||
except NoResultFound:
|
||||
return jsonify(result="error", message="not found"), 404
|
||||
|
||||
|
||||
@notifications.route('/sms', methods=['POST'])
|
||||
|
||||
@@ -141,7 +141,7 @@ class EmailNotificationSchema(NotificationSchema):
|
||||
class NotificationStatusSchema(BaseSchema):
|
||||
|
||||
class Meta:
|
||||
model = models.Notification
|
||||
model = models.Noti∫~fication
|
||||
|
||||
|
||||
user_schema = UserSchema()
|
||||
|
||||
Reference in New Issue
Block a user