Skip to content

Commit

Permalink
Get graph data (#10)
Browse files Browse the repository at this point in the history
Graph data does not need pagination so a different end point is provided for this
  • Loading branch information
erssebaggala committed May 16, 2019
1 parent 732cb04 commit a592d58
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions btsapi/modules/reports/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ def create_or_update_report():
report = Report(name=content['name'],
category_pk=content['category_id'],
query=content['qry'],
notes=content['notes'])
notes=content['notes'],
options=content['options'])

db.session.add(report)
db.session.commit()
Expand Down Expand Up @@ -381,4 +382,26 @@ def delete_category(id):
return jsonify({}), 200
except Exception as e:
db.session.rollback()
return jsonify(str(e)), 400
return jsonify(str(e)), 400


@mod_reports.route('/graphdata/<int:report_id>', methods=['GET'])
@login_required
def get_graph_data(report_id):
"""
Get graph data for report of type Graph
:param report_id:
:return:
"""
report = db.session.query(Report).filter_by(pk=report_id).first()

#@TODO: Add check for report type

table_columns = db.engine.execute(text(report.query)).keys()
result = db.engine.execute(text(report.query))

data_results = [{k: v for k, v in zip(
table_columns, row)} for row in result.fetchall()]

return jsonify(data_results)

0 comments on commit a592d58

Please sign in to comment.