mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-21 07:51:13 -05:00
- Not sure I want to create a new classmethod on Notifications to create from v2 request. Will take another look at that.
68 lines
2.1 KiB
Python
68 lines
2.1 KiB
Python
from app.schema_validation.definitions import (uuid, personalisation)
|
|
|
|
post_sms_request = {
|
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
|
"description": "POST sms notification schema",
|
|
"type": "object",
|
|
"title": "POST v2/notifications/sms",
|
|
"properties": {
|
|
"reference": {"type": "string"},
|
|
"phone_number": {"type": "string", "format": "sms"},
|
|
"template_id": uuid,
|
|
"personalisation": personalisation
|
|
},
|
|
"required": ["phone_number", "template_id"]
|
|
}
|
|
|
|
content = {
|
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
|
"description": "POST sms notification response schema",
|
|
"type": "object",
|
|
"title": "notification content",
|
|
"properties": {
|
|
"body": {"type": "string"},
|
|
"from_number": {"type": "string"}
|
|
},
|
|
"required": ["body"]
|
|
}
|
|
|
|
# this may belong in a templates module
|
|
template = {
|
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
|
"description": "POST sms notification response schema",
|
|
"type": "object",
|
|
"title": "notification content",
|
|
"properties": {
|
|
"id": uuid,
|
|
"version": {"type": "integer"},
|
|
"uri": {"type": "string"}
|
|
},
|
|
"required": ["id", "version", "uri"]
|
|
}
|
|
|
|
post_sms_response = {
|
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
|
"description": "POST sms notification response schema",
|
|
"type": "object",
|
|
"title": "response v2/notifications/sms",
|
|
"properties": {
|
|
"id": uuid,
|
|
"reference": {"type": "string"},
|
|
"content": content,
|
|
"uri": {"type": "string"},
|
|
"template": template
|
|
},
|
|
"required": ["id", "content", "uri", "template"]
|
|
}
|
|
|
|
|
|
def create_post_sms_response_from_notification(notification, content):
|
|
return {"id": notification.id,
|
|
"reference": None, # not yet implemented
|
|
"content": content,
|
|
"uri": "v2/notifications/{}".format(notification.id),
|
|
"template": {"id": notification.template_id,
|
|
"version": notification.template_version,
|
|
"uri": "v2/templates/{}".format(notification.template_id)}
|
|
}
|