mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 07:35:34 -05:00
New package structure for the version 2 of the public api.
Start building up the validators required for post notificaiton. The app/v2/errors.py is a rough sketch, will be passed a code, the error can look up the message and link for the error message.
This commit is contained in:
14
app/notifications/process_notifications.py
Normal file
14
app/notifications/process_notifications.py
Normal file
@@ -0,0 +1,14 @@
|
||||
def persist_notification():
|
||||
'''
|
||||
persist the notification
|
||||
:return:
|
||||
'''
|
||||
pass
|
||||
|
||||
|
||||
def send_notificaiton_to_queue():
|
||||
'''
|
||||
send the notification to the queue
|
||||
:return:
|
||||
'''
|
||||
pass
|
||||
25
app/notifications/validators.py
Normal file
25
app/notifications/validators.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from app.dao import services_dao
|
||||
from app.errors import InvalidRequest
|
||||
from app.models import KEY_TYPE_TEST
|
||||
|
||||
|
||||
def check_service_message_limit(key_type, service):
|
||||
if all((key_type != KEY_TYPE_TEST,
|
||||
service.restricted)):
|
||||
service_stats = services_dao.fetch_todays_total_message_count(service.id)
|
||||
if service_stats >= service.message_limit:
|
||||
error = 'Exceeded send limits ({}) for today'.format(service.message_limit)
|
||||
|
||||
raise InvalidRequest(error, status_code=429)
|
||||
|
||||
|
||||
def check_template_is_for_notification_type(notification_type, template_type):
|
||||
if notification_type != template_type:
|
||||
raise InvalidRequest("{0} template is not suitable for {1} notification".format(template_type,
|
||||
notification_type),
|
||||
status_code=400)
|
||||
|
||||
|
||||
def check_template_is_active(template):
|
||||
if template.archived:
|
||||
raise InvalidRequest('Template has been deleted', status_code=400)
|
||||
Reference in New Issue
Block a user