mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-09 23:02:13 -05:00
Refactored endpoints
This commit is contained in:
@@ -2,6 +2,7 @@ from flask import Blueprint, jsonify, request
|
||||
|
||||
from app.dao.inbound_numbers_dao import (
|
||||
dao_get_inbound_numbers,
|
||||
dao_get_inbound_number,
|
||||
dao_get_inbound_number_for_service,
|
||||
dao_get_available_inbound_numbers,
|
||||
dao_set_inbound_number_to_service,
|
||||
@@ -22,8 +23,15 @@ def get_inbound_numbers():
|
||||
return jsonify(data=inbound_numbers)
|
||||
|
||||
|
||||
@inbound_number_blueprint.route('/<uuid:service_id>', methods=['POST'])
|
||||
def post_allocate_or_reactivate_inbound_number(service_id):
|
||||
@inbound_number_blueprint.route('/available', methods=['GET'])
|
||||
def get_inbound_numbers_available():
|
||||
inbound_numbers = [i.serialize() for i in dao_get_available_inbound_numbers()]
|
||||
|
||||
return jsonify(data=inbound_numbers)
|
||||
|
||||
|
||||
@inbound_number_blueprint.route('/service/<uuid:service_id>', methods=['POST'])
|
||||
def post_allocate_inbound_number(service_id):
|
||||
inbound_number = dao_get_inbound_number_for_service(service_id)
|
||||
|
||||
if not inbound_number:
|
||||
@@ -39,7 +47,25 @@ def post_allocate_or_reactivate_inbound_number(service_id):
|
||||
return '', 204
|
||||
|
||||
|
||||
@inbound_number_blueprint.route('/<uuid:service_id>/off', methods=['POST'])
|
||||
def post_deactivate_inbound_number(service_id):
|
||||
dao_set_inbound_number_active_flag(service_id, active=False)
|
||||
@inbound_number_blueprint.route('/<uuid:inbound_number_id>/service/<uuid:service_id>', methods=['POST'])
|
||||
def post_set_inbound_number_for_service(inbound_number_id, service_id):
|
||||
try:
|
||||
dao_set_inbound_number_to_service(service_id, inbound_number_id)
|
||||
except TypeError as e:
|
||||
if str(e) == 'UUID objects are immutable':
|
||||
return '', 409
|
||||
else:
|
||||
raise e
|
||||
return '', 204
|
||||
|
||||
|
||||
@inbound_number_blueprint.route('/service/<uuid:inbound_number_id>/on', methods=['POST'])
|
||||
def post_set_inbound_number_on(inbound_number_id):
|
||||
dao_set_inbound_number_active_flag(inbound_number_id, active=True)
|
||||
return '', 204
|
||||
|
||||
|
||||
@inbound_number_blueprint.route('/<uuid:inbound_number_id>/off', methods=['POST'])
|
||||
def post_set_inbound_number_off(inbound_number_id):
|
||||
dao_set_inbound_number_active_flag(inbound_number_id, active=False)
|
||||
return '', 204
|
||||
|
||||
Reference in New Issue
Block a user