mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-31 06:52:06 -05:00
Add notification_type to query
This commit is contained in:
@@ -3,6 +3,7 @@ import json
|
||||
|
||||
from flask import Blueprint, jsonify, request
|
||||
|
||||
from app.dao.fact_billing_dao import fetch_monthly_billing_for_year
|
||||
from app.dao.monthly_billing_dao import (
|
||||
get_billing_data_for_financial_year,
|
||||
get_monthly_billing_by_notification_type
|
||||
@@ -30,6 +31,16 @@ billing_blueprint = Blueprint(
|
||||
register_errors(billing_blueprint)
|
||||
|
||||
|
||||
@billing_blueprint.route('/ft-monthly-usage')
|
||||
def get_yearly_usage_by_monthy_from_ft_billing(service_id):
|
||||
try:
|
||||
year = int(request.args.get('year'))
|
||||
results = fetch_monthly_billing_for_year(service_id=service_id, year=year)
|
||||
serialize_ft_billing(results)
|
||||
except TypeError:
|
||||
return jsonify(result='error', message='No valid year provided'), 400
|
||||
|
||||
|
||||
@billing_blueprint.route('/monthly-usage')
|
||||
def get_yearly_usage_by_month(service_id):
|
||||
try:
|
||||
@@ -192,3 +203,21 @@ def update_free_sms_fragment_limit_data(service_id, free_sms_fragment_limit, fin
|
||||
free_sms_fragment_limit,
|
||||
financial_year_start
|
||||
)
|
||||
|
||||
|
||||
def serialize_ft_billing(data):
|
||||
results = []
|
||||
|
||||
for d in data:
|
||||
j = {
|
||||
"Month": d.month,
|
||||
"service_id": d.service_id,
|
||||
"notifications_type": d.notification_type,
|
||||
"notifications_sent": d.notifications_sent,
|
||||
"billable_units": d.billable_units,
|
||||
"rate": d.rate,
|
||||
"rate_multiplier": d.rate_multiplier,
|
||||
"international": d.international,
|
||||
}
|
||||
results.append(j)
|
||||
return results
|
||||
|
||||
@@ -20,7 +20,7 @@ from app.models import (
|
||||
from app.utils import convert_utc_to_bst, convert_bst_to_utc
|
||||
|
||||
|
||||
def fetch_montly_billing_for_year(service_id, year):
|
||||
def fetch_monthly_billing_for_year(service_id, year):
|
||||
year_start_date, year_end_date = get_financial_year(year)
|
||||
utcnow = datetime.utcnow()
|
||||
today = convert_utc_to_bst(utcnow).date()
|
||||
@@ -39,7 +39,8 @@ def fetch_montly_billing_for_year(service_id, year):
|
||||
FactBilling.service_id,
|
||||
FactBilling.rate,
|
||||
FactBilling.rate_multiplier,
|
||||
FactBilling.international
|
||||
FactBilling.international,
|
||||
FactBilling.notification_type
|
||||
).filter(
|
||||
FactBilling.service_id == service_id,
|
||||
FactBilling.bst_date >= year_start_date,
|
||||
@@ -49,7 +50,12 @@ def fetch_montly_billing_for_year(service_id, year):
|
||||
FactBilling.service_id,
|
||||
FactBilling.rate,
|
||||
FactBilling.rate_multiplier,
|
||||
FactBilling.international
|
||||
FactBilling.international,
|
||||
FactBilling.notification_type
|
||||
).order_by(
|
||||
FactBilling.service_id,
|
||||
'Month',
|
||||
FactBilling.notification_type
|
||||
).all()
|
||||
|
||||
return yearly_data
|
||||
|
||||
Reference in New Issue
Block a user