2
2
from collections import defaultdict
3
3
from flasgger import Swagger
4
4
import re ,os ,traceback
5
- from query import PostgresORM
5
+ # from query import PostgresORM
6
6
from utils import *
7
7
from flask_cors import CORS ,cross_origin
8
8
from v2_app import v2
9
9
from flask_sqlalchemy import SQLAlchemy
10
10
from models import db
11
+ from shared_migrations .db import get_postgres_uri
12
+ from shared_migrations .db .dmp_api import DmpAPIQueries
13
+ from sqlalchemy .ext .asyncio import create_async_engine , AsyncSession
14
+ from sqlalchemy .orm import sessionmaker
15
+ from sqlalchemy .pool import NullPool
11
16
12
17
13
18
14
19
app = Flask (__name__ )
15
20
CORS (app ,supports_credentials = True )
16
21
17
22
18
- app .config ['SQLALCHEMY_DATABASE_URI' ] = PostgresORM . get_postgres_uri ()
23
+ app .config ['SQLALCHEMY_DATABASE_URI' ] = get_postgres_uri ()
19
24
app .config ['SQLALCHEMY_TRACK_MODIFICATIONS' ] = False
20
25
26
+ # Initialize Async SQLAlchemy
27
+ engine = create_async_engine (app .config ['SQLALCHEMY_DATABASE_URI' ], echo = False ,poolclass = NullPool )
28
+ async_session = sessionmaker (autocommit = False , autoflush = False , bind = engine , class_ = AsyncSession )
29
+
30
+
21
31
db .init_app (app )
22
32
23
33
Swagger (app )
@@ -56,9 +66,9 @@ def greeting():
56
66
57
67
58
68
@app .route ('/issues' , methods = ['GET' ])
59
- @cross_origin (supports_credentials = True )
60
- @require_secret_key
61
- def get_issues ():
69
+ # @cross_origin(supports_credentials=True)
70
+ # @require_secret_key
71
+ async def get_issues ():
62
72
"""
63
73
Fetch all issues and group by owner.
64
74
---
@@ -80,8 +90,9 @@ def get_issues():
80
90
type: string
81
91
"""
82
92
try :
83
- # Fetch all issues with their details
84
- data = PostgresORM .get_issue_query ()
93
+ # Fetch all issues with their details
94
+ print ('inside get all issues' )
95
+ data = await DmpAPIQueries .get_issue_query (async_session )
85
96
response = []
86
97
87
98
for result in data :
@@ -98,9 +109,9 @@ def get_issues():
98
109
return jsonify ({'error' : str (e ), 'traceback' : error_traceback }), 500
99
110
100
111
@app .route ('/issues/<owner>' , methods = ['GET' ])
101
- @cross_origin (supports_credentials = True )
102
- @require_secret_key
103
- def get_issues_by_owner (owner ):
112
+ # @cross_origin(supports_credentials=True)
113
+ # @require_secret_key
114
+ async def get_issues_by_owner (owner ):
104
115
"""
105
116
Fetch organization details by owner's GitHub URL.
106
117
---
@@ -142,7 +153,7 @@ def get_issues_by_owner(owner):
142
153
try :
143
154
144
155
# Fetch organization details from dmp_orgs table
145
- response = PostgresORM .get_issue_owner (owner )
156
+ response = await DmpAPIQueries .get_issue_owner (async_session , owner )
146
157
if not response :
147
158
return jsonify ({'error' : "Organization not found" }), 404
148
159
@@ -192,7 +203,7 @@ def get_issues_by_owner_id(owner, issue):
192
203
"""
193
204
try :
194
205
print ('inside get issues' )
195
- SUPABASE_DB = SupabaseInterface () .get_instance ()
206
+ SUPABASE_DB = DmpAPIQueries .get_instance ()
196
207
response = SUPABASE_DB .client .table ('dmp_issue_updates' ).select ('*' ).eq ('owner' , owner ).eq ('issue_number' , issue ).execute ()
197
208
if not response .data :
198
209
return jsonify ({'error' : "No data found" }), 200
0 commit comments