1
1
from flask import Flask , jsonify
2
2
from db import SupabaseInterface
3
3
from collections import defaultdict
4
+ from flasgger import Swagger
5
+
4
6
5
7
app = Flask (__name__ )
6
8
9
+ Swagger (app )
10
+
7
11
8
12
@app .route ('/api/greeting' , methods = ['GET' ])
9
13
def 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
+ """
10
27
response = {
11
28
'message' : 'Hello, welcome to my API!'
12
29
}
13
30
return jsonify (response )
14
31
15
32
@app .route ('/api/get-data' , methods = ['GET' ])
16
33
def 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
+ """
18
52
try :
19
- import pdb ;pdb .set_trace ()
20
53
response = SupabaseInterface ().get_instance ().client .table ('dmp_pr_updates' ).select ('*' ).execute ()
21
54
data = response .data
22
55
return jsonify (data )
23
56
except Exception as e :
24
57
return jsonify ({'error' : str (e )}), 500
25
-
26
-
58
+
27
59
def group_by_owner (data ):
28
60
grouped_data = defaultdict (list )
29
61
for record in data :
30
62
owner = record ['owner' ]
31
63
grouped_data [owner ].append (record )
32
64
return grouped_data
33
65
34
- #DMP - CMS API's
35
-
36
66
@app .route ('/api/issues' , methods = ['GET' ])
37
67
def 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
+ """
38
88
try :
39
89
response = SupabaseInterface ().get_instance ().client .table ('dmp_issue_updates' ).select ('*' ).execute ()
40
90
data = response .data
41
91
grouped_data = group_by_owner (data )
42
92
return jsonify (grouped_data )
43
93
except Exception as e :
44
94
return jsonify ({'error' : str (e )}), 500
45
-
95
+
46
96
@app .route ('/api/issues/<owner>' , methods = ['GET' ])
47
97
def 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
+ """
49
122
try :
50
- import pdb ;pdb .set_trace ()
51
123
response = SupabaseInterface ().get_instance ().client .table ('dmp_issue_updates' ).select ('*' ).eq ('owner' , owner ).execute ()
52
-
53
124
if not response .data :
54
125
return jsonify ({'error' : "No data found" }), 500
55
-
56
- data = response .data
126
+ data = response .data
57
127
return jsonify (data )
58
-
59
128
except Exception as e :
60
129
return jsonify ({'error' : str (e )}), 500
61
-
62
130
63
131
@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
+ """
66
162
try :
67
163
response = SupabaseInterface ().get_instance ().client .table ('dmp_issue_updates' ).select ('*' ).eq ('owner' , owner ).eq ('issue_number' , issue ).execute ()
68
-
69
164
if not response .data :
70
165
return jsonify ({'error' : "No data found" }), 500
71
-
72
- data = response .data
166
+ data = response .data
73
167
return jsonify (data )
74
-
75
168
except Exception as e :
76
169
return jsonify ({'error' : str (e )}), 500
77
-
170
+
78
171
if __name__ == '__main__' :
79
- app .run (debug = True )
172
+ app .run (debug = True )
0 commit comments