2017-08-14 12:17:14 +01:00
|
|
|
from flask import Blueprint, jsonify
|
2017-08-04 19:26:51 +01:00
|
|
|
|
|
|
|
|
from app.dao.inbound_numbers_dao import (
|
|
|
|
|
dao_get_available_inbound_numbers,
|
2021-03-10 13:55:06 +00:00
|
|
|
dao_get_inbound_number_for_service,
|
|
|
|
|
dao_get_inbound_numbers,
|
|
|
|
|
dao_set_inbound_number_active_flag,
|
2017-11-07 14:26:18 +00:00
|
|
|
)
|
|
|
|
|
from app.errors import register_errors
|
2017-08-04 19:26:51 +01:00
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
inbound_number_blueprint = Blueprint(
|
|
|
|
|
"inbound_number", __name__, url_prefix="/inbound-number"
|
|
|
|
|
)
|
2017-08-04 19:26:51 +01:00
|
|
|
register_errors(inbound_number_blueprint)
|
|
|
|
|
|
|
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
@inbound_number_blueprint.route("", methods=["GET"])
|
2017-08-04 19:26:51 +01:00
|
|
|
def get_inbound_numbers():
|
|
|
|
|
inbound_numbers = [i.serialize() for i in dao_get_inbound_numbers()]
|
|
|
|
|
|
2017-08-14 12:17:14 +01:00
|
|
|
return jsonify(data=inbound_numbers if inbound_numbers else [])
|
2017-08-10 18:35:57 +01:00
|
|
|
|
|
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
@inbound_number_blueprint.route("/service/<uuid:service_id>", methods=["GET"])
|
2017-08-11 12:51:52 +01:00
|
|
|
def get_inbound_number_for_service(service_id):
|
2017-08-04 19:26:51 +01:00
|
|
|
inbound_number = dao_get_inbound_number_for_service(service_id)
|
|
|
|
|
|
2017-08-14 12:17:14 +01:00
|
|
|
return jsonify(data=inbound_number.serialize() if inbound_number else {})
|
2017-08-04 19:26:51 +01:00
|
|
|
|
|
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
@inbound_number_blueprint.route("/service/<uuid:service_id>/off", methods=["POST"])
|
2017-08-14 18:20:25 +01:00
|
|
|
def post_set_inbound_number_off(service_id):
|
|
|
|
|
dao_set_inbound_number_active_flag(service_id, active=False)
|
2017-08-15 14:11:00 +01:00
|
|
|
return jsonify(), 204
|
2017-09-21 15:18:52 +01:00
|
|
|
|
|
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
@inbound_number_blueprint.route("/available", methods=["GET"])
|
2017-09-21 15:18:52 +01:00
|
|
|
def get_available_inbound_numbers():
|
|
|
|
|
inbound_numbers = [i.serialize() for i in dao_get_available_inbound_numbers()]
|
|
|
|
|
|
|
|
|
|
return jsonify(data=inbound_numbers if inbound_numbers else [])
|