mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 23:55:58 -05:00
Added free_sms_fragment_limit model, schema, dao and Rest
This commit is contained in:
@@ -11,6 +11,14 @@ from app.dao.date_util import get_financial_year, get_months_for_financial_year
|
||||
from app.errors import register_errors
|
||||
from app.models import SMS_TYPE, EMAIL_TYPE
|
||||
from app.utils import convert_utc_to_bst
|
||||
from app.dao.annual_billing_dao import (dao_get_free_sms_fragment_limit_for_year,
|
||||
dao_get_all_free_sms_fragment_limit,
|
||||
dao_create_new_annual_billing_for_year,
|
||||
dao_update_new_free_sms_fragment_limit_for_year)
|
||||
from app.billing.billing_schemas import create_or_update_free_sms_fragment_limit_schema
|
||||
from app.errors import InvalidRequest
|
||||
from app.schema_validation import validate
|
||||
from app.models import AnnualBilling
|
||||
|
||||
billing_blueprint = Blueprint(
|
||||
'billing',
|
||||
@@ -86,3 +94,55 @@ def _transform_billing_for_month(billing_for_month):
|
||||
"notification_type": billing_for_month.notification_type,
|
||||
"rate": rate
|
||||
}
|
||||
|
||||
|
||||
# @billing_blueprint.route('/annual-billing', methods=["GET"])
|
||||
# def get_annual_billing(service_id):
|
||||
#
|
||||
# results = dao_get_annual_billing(service_id)
|
||||
#
|
||||
# if len(results)==0:
|
||||
# raise InvalidRequest('no annual billing information for this service', status_code=404)
|
||||
#
|
||||
# return jsonify(data=[row.serialize() for row in results]), 200
|
||||
|
||||
|
||||
@billing_blueprint.route('/free-sms-fragment-limit', methods=["GET"])
|
||||
def get_free_sms_fragment_limit(service_id):
|
||||
|
||||
financial_year_start = request.args.get('financial_year_start')
|
||||
|
||||
if financial_year_start is None:
|
||||
results = dao_get_all_free_sms_fragment_limit(service_id)
|
||||
|
||||
if len(results) == 0:
|
||||
raise InvalidRequest('no annual billing information for this service', status_code=404)
|
||||
return jsonify(data=[row.serialize() for row in results]), 200
|
||||
else:
|
||||
result = dao_get_free_sms_fragment_limit_for_year(service_id, financial_year_start)
|
||||
if result is None:
|
||||
raise InvalidRequest('no free-sms-fragment-limit-info for this service and year', status_code=404)
|
||||
|
||||
return jsonify(data=result.serialize()), 200
|
||||
|
||||
|
||||
@billing_blueprint.route('/free-sms-fragment-limit', methods=["POST"])
|
||||
def create_or_update_free_sms_fragment_limit(service_id):
|
||||
|
||||
form = validate(request.get_json(), create_or_update_free_sms_fragment_limit_schema)
|
||||
|
||||
financial_year_start = form.get('financial_year_start')
|
||||
free_sms_fragment_limit = form.get('free_sms_fragment_limit')
|
||||
|
||||
result = dao_get_free_sms_fragment_limit_for_year(service_id, financial_year_start)
|
||||
|
||||
annual_billing = AnnualBilling(service_id=service_id, financial_year_start=financial_year_start,
|
||||
free_sms_fragment_limit=free_sms_fragment_limit)
|
||||
|
||||
if result is None:
|
||||
dao_create_new_annual_billing_for_year(annual_billing)
|
||||
|
||||
else:
|
||||
dao_update_new_free_sms_fragment_limit_for_year(annual_billing)
|
||||
|
||||
return jsonify(data=form), 201
|
||||
|
||||
Reference in New Issue
Block a user