11from flask import Flask , jsonify
22from db import SupabaseInterface
33from collections import defaultdict
4+ from flasgger import Swagger
5+
46
57app = Flask (__name__ )
68
9+ Swagger (app )
10+
711
812@app .route ('/api/greeting' , methods = ['GET' ])
913def greeting ():
14+ """
15+ A simple greeting endpoint.
16+ ---
17+ responses:
18+ 200:
19+ description: A greeting message
20+ schema:
21+ type: object
22+ properties:
23+ message:
24+ type: string
25+ example: Hello, welcome to my API!
26+ """
1027 response = {
1128 'message' : 'Hello, welcome to my API!'
1229 }
1330 return jsonify (response )
1431
1532@app .route ('/api/get-data' , methods = ['GET' ])
1633def get_data ():
17- # Fetch data from Supabase
34+ """
35+ Fetch data from Supabase.
36+ ---
37+ responses:
38+ 200:
39+ description: Data fetched successfully
40+ schema:
41+ type: array
42+ items:
43+ type: object
44+ 500:
45+ description: Error fetching data
46+ schema:
47+ type: object
48+ properties:
49+ error:
50+ type: string
51+ """
1852 try :
19- import pdb ;pdb .set_trace ()
2053 response = SupabaseInterface ().get_instance ().client .table ('dmp_pr_updates' ).select ('*' ).execute ()
2154 data = response .data
2255 return jsonify (data )
2356 except Exception as e :
2457 return jsonify ({'error' : str (e )}), 500
25-
26-
58+
2759def group_by_owner (data ):
2860 grouped_data = defaultdict (list )
2961 for record in data :
3062 owner = record ['owner' ]
3163 grouped_data [owner ].append (record )
3264 return grouped_data
3365
34- #DMP - CMS API's
35-
3666@app .route ('/api/issues' , methods = ['GET' ])
3767def get_issues ():
68+ """
69+ Fetch all issues and group by owner.
70+ ---
71+ responses:
72+ 200:
73+ description: Issues grouped by owner
74+ schema:
75+ type: object
76+ additionalProperties:
77+ type: array
78+ items:
79+ type: object
80+ 500:
81+ description: Error fetching issues
82+ schema:
83+ type: object
84+ properties:
85+ error:
86+ type: string
87+ """
3888 try :
3989 response = SupabaseInterface ().get_instance ().client .table ('dmp_issue_updates' ).select ('*' ).execute ()
4090 data = response .data
4191 grouped_data = group_by_owner (data )
4292 return jsonify (grouped_data )
4393 except Exception as e :
4494 return jsonify ({'error' : str (e )}), 500
45-
95+
4696@app .route ('/api/issues/<owner>' , methods = ['GET' ])
4797def get_issues_by_owner (owner ):
48- # Fetch data from Supabase
98+ """
99+ Fetch issues by owner.
100+ ---
101+ parameters:
102+ - name: owner
103+ in: path
104+ type: string
105+ required: true
106+ description: The owner of the issues
107+ responses:
108+ 200:
109+ description: Issues fetched successfully
110+ schema:
111+ type: array
112+ items:
113+ type: object
114+ 500:
115+ description: Error fetching issues
116+ schema:
117+ type: object
118+ properties:
119+ error:
120+ type: string
121+ """
49122 try :
50- import pdb ;pdb .set_trace ()
51123 response = SupabaseInterface ().get_instance ().client .table ('dmp_issue_updates' ).select ('*' ).eq ('owner' , owner ).execute ()
52-
53124 if not response .data :
54125 return jsonify ({'error' : "No data found" }), 500
55-
56- data = response .data
126+ data = response .data
57127 return jsonify (data )
58-
59128 except Exception as e :
60129 return jsonify ({'error' : str (e )}), 500
61-
62130
63131@app .route ('/api/issues/<owner>/<issue>' , methods = ['GET' ])
64- def get_issues_by_owner_id (owner ,issue ):
65- # Fetch data from Supabase
132+ def get_issues_by_owner_id (owner , issue ):
133+ """
134+ Fetch issues by owner and issue number.
135+ ---
136+ parameters:
137+ - name: owner
138+ in: path
139+ type: string
140+ required: true
141+ description: The owner of the issues
142+ - name: issue
143+ in: path
144+ type: string
145+ required: true
146+ description: The issue number
147+ responses:
148+ 200:
149+ description: Issues fetched successfully
150+ schema:
151+ type: array
152+ items:
153+ type: object
154+ 500:
155+ description: Error fetching issues
156+ schema:
157+ type: object
158+ properties:
159+ error:
160+ type: string
161+ """
66162 try :
67163 response = SupabaseInterface ().get_instance ().client .table ('dmp_issue_updates' ).select ('*' ).eq ('owner' , owner ).eq ('issue_number' , issue ).execute ()
68-
69164 if not response .data :
70165 return jsonify ({'error' : "No data found" }), 500
71-
72- data = response .data
166+ data = response .data
73167 return jsonify (data )
74-
75168 except Exception as e :
76169 return jsonify ({'error' : str (e )}), 500
77-
170+
78171if __name__ == '__main__' :
79- app .run (debug = True )
172+ app .run (debug = True )
0 commit comments