mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-16 18:22:17 -05:00
or param errors to raise invalid data exception. That will cause those responses to be handled in by errors.py, which will log the errors. Set most of schemas to strict mode so that marshmallow will raise exception rather than checking for errors in return tuple from load. Added handler to errors.py for marshmallow validation errors.
47 lines
1.6 KiB
Python
47 lines
1.6 KiB
Python
from flask import Blueprint, jsonify, request
|
|
|
|
from app.schemas import provider_details_schema
|
|
|
|
from app.dao.provider_details_dao import (
|
|
get_provider_details,
|
|
get_provider_details_by_id,
|
|
dao_update_provider_details
|
|
)
|
|
|
|
from app.errors import (
|
|
register_errors,
|
|
InvalidRequest
|
|
)
|
|
|
|
provider_details = Blueprint('provider_details', __name__)
|
|
register_errors(provider_details)
|
|
|
|
|
|
@provider_details.route('', methods=['GET'])
|
|
def get_providers():
|
|
data = provider_details_schema.dump(get_provider_details(), many=True).data
|
|
return jsonify(provider_details=data)
|
|
|
|
|
|
@provider_details.route('/<uuid:provider_details_id>', methods=['GET'])
|
|
def get_provider_by_id(provider_details_id):
|
|
data = provider_details_schema.dump(get_provider_details_by_id(provider_details_id)).data
|
|
return jsonify(provider_details=data)
|
|
|
|
|
|
@provider_details.route('/<uuid:provider_details_id>', methods=['POST'])
|
|
def update_provider_details(provider_details_id):
|
|
fetched_provider_details = get_provider_details_by_id(provider_details_id)
|
|
|
|
current_data = dict(provider_details_schema.dump(fetched_provider_details).data.items())
|
|
current_data.update(request.get_json())
|
|
update_dict = provider_details_schema.load(current_data).data
|
|
|
|
if "identifier" in request.get_json().keys():
|
|
message = "Not permitted to be updated"
|
|
errors = {'identifier': [message]}
|
|
raise InvalidRequest(errors, status_code=400)
|
|
|
|
dao_update_provider_details(update_dict)
|
|
return jsonify(provider_details=provider_details_schema.dump(fetched_provider_details).data), 200
|