mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-20 15:31:15 -05:00
create, edit and use email branding instead of organisation
notable things that have been kept until migration is complete: * passing in `organisation` to update_service will update email branding * both `/email-branding` and `/organisation` hit the same code * service endpoints still return organisation as well as email branding
This commit is contained in:
0
app/email_branding/__init__.py
Normal file
0
app/email_branding/__init__.py
Normal file
23
app/email_branding/email_branding_schema.py
Normal file
23
app/email_branding/email_branding_schema.py
Normal file
@@ -0,0 +1,23 @@
|
||||
post_create_email_branding_schema = {
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"description": "POST schema for getting email_branding",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"colour": {"type": ["string", "null"]},
|
||||
"name": {"type": ["string", "null"]},
|
||||
"logo": {"type": ["string", "null"]}
|
||||
},
|
||||
"required": []
|
||||
}
|
||||
|
||||
post_update_email_branding_schema = {
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"description": "POST schema for getting email_branding",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"colour": {"type": ["string", "null"]},
|
||||
"name": {"type": ["string", "null"]},
|
||||
"logo": {"type": ["string", "null"]}
|
||||
},
|
||||
"required": []
|
||||
}
|
||||
54
app/email_branding/rest.py
Normal file
54
app/email_branding/rest.py
Normal file
@@ -0,0 +1,54 @@
|
||||
from flask import Blueprint, jsonify, request
|
||||
|
||||
from app.dao.email_branding_dao import (
|
||||
dao_create_email_branding,
|
||||
dao_get_email_branding_options,
|
||||
dao_get_email_branding_by_id,
|
||||
dao_update_email_branding
|
||||
)
|
||||
from app.errors import register_errors
|
||||
from app.models import EmailBranding
|
||||
from app.email_branding.email_branding_schema import (
|
||||
post_create_email_branding_schema,
|
||||
post_update_email_branding_schema
|
||||
)
|
||||
from app.schema_validation import validate
|
||||
|
||||
email_branding_blueprint = Blueprint('email_branding', __name__)
|
||||
register_errors(email_branding_blueprint)
|
||||
|
||||
|
||||
@email_branding_blueprint.route('', methods=['GET'])
|
||||
def get_email_branding_options():
|
||||
email_branding_options = [o.serialize() for o in dao_get_email_branding_options()]
|
||||
return jsonify(email_branding=email_branding_options)
|
||||
|
||||
|
||||
@email_branding_blueprint.route('/<uuid:email_branding_id>', methods=['GET'])
|
||||
def get_email_branding_by_id(email_branding_id):
|
||||
email_branding = dao_get_email_branding_by_id(email_branding_id)
|
||||
return jsonify(email_branding=email_branding.serialize())
|
||||
|
||||
|
||||
@email_branding_blueprint.route('', methods=['POST'])
|
||||
def create_email_branding():
|
||||
data = request.get_json()
|
||||
|
||||
validate(data, post_create_email_branding_schema)
|
||||
|
||||
email_branding = EmailBranding(**data)
|
||||
|
||||
dao_create_email_branding(email_branding)
|
||||
return jsonify(data=email_branding.serialize()), 201
|
||||
|
||||
|
||||
@email_branding_blueprint.route('/<uuid:email_branding_id>', methods=['POST'])
|
||||
def update_email_branding(email_branding_id):
|
||||
data = request.get_json()
|
||||
|
||||
validate(data, post_update_email_branding_schema)
|
||||
|
||||
fetched_email_branding = dao_get_email_branding_by_id(email_branding_id)
|
||||
dao_update_email_branding(fetched_email_branding, **data)
|
||||
|
||||
return jsonify(data=fetched_email_branding.serialize()), 200
|
||||
Reference in New Issue
Block a user