|
| 1 | +from flask import Flask, jsonify |
| 2 | +from db import SupabaseInterface |
| 3 | +from collections import defaultdict |
| 4 | + |
| 5 | +app = Flask(__name__) |
| 6 | + |
| 7 | + |
| 8 | +@app.route('/api/greeting', methods=['GET']) |
| 9 | +def greeting(): |
| 10 | + response = { |
| 11 | + 'message': 'Hello, welcome to my API!' |
| 12 | + } |
| 13 | + return jsonify(response) |
| 14 | + |
| 15 | +@app.route('/api/get-data', methods=['GET']) |
| 16 | +def get_data(): |
| 17 | + # Fetch data from Supabase |
| 18 | + try: |
| 19 | + import pdb;pdb.set_trace() |
| 20 | + response = SupabaseInterface().get_instance().client.table('dmp_pr_updates').select('*').execute() |
| 21 | + data = response.data |
| 22 | + return jsonify(data) |
| 23 | + except Exception as e: |
| 24 | + return jsonify({'error': str(e)}), 500 |
| 25 | + |
| 26 | + |
| 27 | +def group_by_owner(data): |
| 28 | + grouped_data = defaultdict(list) |
| 29 | + for record in data: |
| 30 | + owner = record['owner'] |
| 31 | + grouped_data[owner].append(record) |
| 32 | + return grouped_data |
| 33 | + |
| 34 | +#DMP - CMS API's |
| 35 | + |
| 36 | +@app.route('/api/issues', methods=['GET']) |
| 37 | +def get_issues(): |
| 38 | + try: |
| 39 | + response = SupabaseInterface().get_instance().client.table('dmp_issue_updates').select('*').execute() |
| 40 | + data = response.data |
| 41 | + grouped_data = group_by_owner(data) |
| 42 | + return jsonify(grouped_data) |
| 43 | + except Exception as e: |
| 44 | + return jsonify({'error': str(e)}), 500 |
| 45 | + |
| 46 | +@app.route('/api/issues/<owner>', methods=['GET']) |
| 47 | +def get_issues_by_owner(owner): |
| 48 | + # Fetch data from Supabase |
| 49 | + try: |
| 50 | + import pdb;pdb.set_trace() |
| 51 | + response = SupabaseInterface().get_instance().client.table('dmp_issue_updates').select('*').eq('owner', owner).execute() |
| 52 | + |
| 53 | + if not response.data: |
| 54 | + return jsonify({'error': "No data found"}), 500 |
| 55 | + |
| 56 | + data = response.data |
| 57 | + return jsonify(data) |
| 58 | + |
| 59 | + except Exception as e: |
| 60 | + return jsonify({'error': str(e)}), 500 |
| 61 | + |
| 62 | + |
| 63 | +@app.route('/api/issues/<owner>/<issue>', methods=['GET']) |
| 64 | +def get_issues_by_owner_id(owner,issue): |
| 65 | + # Fetch data from Supabase |
| 66 | + try: |
| 67 | + response = SupabaseInterface().get_instance().client.table('dmp_issue_updates').select('*').eq('owner', owner).eq('issue_number', issue).execute() |
| 68 | + |
| 69 | + if not response.data: |
| 70 | + return jsonify({'error': "No data found"}), 500 |
| 71 | + |
| 72 | + data = response.data |
| 73 | + return jsonify(data) |
| 74 | + |
| 75 | + except Exception as e: |
| 76 | + return jsonify({'error': str(e)}), 500 |
| 77 | + |
| 78 | +if __name__ == '__main__': |
| 79 | + app.run(debug=True) |
0 commit comments