Skip to content

Commit 5b957c7

Browse files
committed
DMP API migration changes
1 parent d0f6d80 commit 5b957c7

File tree

4 files changed

+43
-19
lines changed

4 files changed

+43
-19
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "shared_migrations"]
2+
path = shared_migrations
3+
url = [email protected]:Code4GovTech/shared-models-migrations.git

app.py

+23-12
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,32 @@
22
from collections import defaultdict
33
from flasgger import Swagger
44
import re,os,traceback
5-
from query import PostgresORM
5+
# from query import PostgresORM
66
from utils import *
77
from flask_cors import CORS,cross_origin
88
from v2_app import v2
99
from flask_sqlalchemy import SQLAlchemy
1010
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
1116

1217

1318

1419
app = Flask(__name__)
1520
CORS(app,supports_credentials=True)
1621

1722

18-
app.config['SQLALCHEMY_DATABASE_URI'] = PostgresORM.get_postgres_uri()
23+
app.config['SQLALCHEMY_DATABASE_URI'] = get_postgres_uri()
1924
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
2025

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+
2131
db.init_app(app)
2232

2333
Swagger(app)
@@ -56,9 +66,9 @@ def greeting():
5666

5767

5868
@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():
6272
"""
6373
Fetch all issues and group by owner.
6474
---
@@ -80,8 +90,9 @@ def get_issues():
8090
type: string
8191
"""
8292
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)
8596
response = []
8697

8798
for result in data:
@@ -98,9 +109,9 @@ def get_issues():
98109
return jsonify({'error': str(e), 'traceback': error_traceback}), 500
99110

100111
@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):
104115
"""
105116
Fetch organization details by owner's GitHub URL.
106117
---
@@ -142,7 +153,7 @@ def get_issues_by_owner(owner):
142153
try:
143154

144155
# Fetch organization details from dmp_orgs table
145-
response = PostgresORM.get_issue_owner(owner)
156+
response = await DmpAPIQueries.get_issue_owner(async_session, owner)
146157
if not response:
147158
return jsonify({'error': "Organization not found"}), 404
148159

@@ -192,7 +203,7 @@ def get_issues_by_owner_id(owner, issue):
192203
"""
193204
try:
194205
print('inside get issues')
195-
SUPABASE_DB = SupabaseInterface().get_instance()
206+
SUPABASE_DB = DmpAPIQueries.get_instance()
196207
response = SUPABASE_DB.client.table('dmp_issue_updates').select('*').eq('owner', owner).eq('issue_number', issue).execute()
197208
if not response.data:
198209
return jsonify({'error': "No data found"}), 200

shared_migrations

Submodule shared_migrations added at 8ca6de8

v2_app.py

+16-7
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,44 @@
44
from utils import require_secret_key
55
from utils import determine_week
66
from v2_utils import calculate_overall_progress, define_link_data, week_data_formatter
7-
from query import PostgresORM
7+
# from query import PostgresORM
8+
from shared_migrations.db.dmp_api import DmpAPIQueries
9+
# from app import async_session
10+
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
11+
from sqlalchemy.orm import sessionmaker
12+
from sqlalchemy.pool import NullPool
13+
from shared_migrations.db import get_postgres_uri
814

915

1016
v2 = Blueprint('v2', __name__)
1117

1218

19+
engine = create_async_engine(get_postgres_uri(), echo=False,poolclass=NullPool)
20+
async_session = sessionmaker(autocommit=False, autoflush=False, bind=engine, class_=AsyncSession)
21+
1322
@v2.route('/issues/<owner>/<issue>', methods=['GET'])
14-
@require_secret_key
15-
def get_issues_by_owner_id_v2(owner, issue):
23+
# @require_secret_key
24+
async def get_issues_by_owner_id_v2(owner, issue):
1625

1726
try:
1827
# Fetch issue updates based on owner and issue number
1928

2029
url = f"https://github.com/{owner}"
2130

2231
# import pdb;pdb.set_trace()
23-
actual_owner = PostgresORM.get_actual_owner_query(owner)
32+
actual_owner = await DmpAPIQueries.get_actual_owner_query(async_session, owner)
2433
repo_owner =actual_owner[0]['repo_owner'] if actual_owner else ""
2534
#create url with repo owner
2635
url = f"https://github.com/{repo_owner}" if repo_owner else None
2736

28-
dmp_issue_id = PostgresORM.get_dmp_issues(issue)
37+
dmp_issue_id = await DmpAPIQueries.get_dmp_issues(async_session, issue)
2938
if not dmp_issue_id:
3039
print(f"url....{url}....{issue}")
3140
return jsonify({'error': "No data found in dmp_issue"}), 500
3241

3342
dmp_issue_id = dmp_issue_id[0]
3443

35-
response = PostgresORM.get_dmp_issue_updates(dmp_issue_id['id'])
44+
response = await DmpAPIQueries.get_dmp_issue_updates(async_session, dmp_issue_id['id'])
3645
if not response:
3746
print(f"dmp_issue_id....{response}....{dmp_issue_id}")
3847
return jsonify({'error': "No data found in dmp_issue_updates"}), 500
@@ -85,7 +94,7 @@ def get_issues_by_owner_id_v2(owner, issue):
8594
}
8695

8796

88-
pr_Data = PostgresORM.get_pr_data(dmp_issue_id['id'])
97+
pr_Data = await DmpAPIQueries.get_pr_data(async_session, dmp_issue_id['id'])
8998
transformed = {"pr_details": []}
9099
if pr_Data:
91100
for pr in pr_Data:

0 commit comments

Comments
 (0)