Skip to content

Commit ff33010

Browse files
authored
Merge pull request #192 from OpenUpSA/admin
admin endpoints
2 parents 129dc0c + d4fd0a8 commit ff33010

File tree

1 file changed

+64
-6
lines changed

1 file changed

+64
-6
lines changed

app.py

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,6 +2008,69 @@ def put(self, project_id, submission_id):
20082008
return {'error': f'Database error: {str(e)}'}, 500
20092009

20102010

2011+
@project_ns.route('/<string:project_id>/submissions/<string:submission_id>/isolates')
2012+
class ProjectSubmissionIsolates2(Resource):
2013+
2014+
### GET /projects/<project_id>/submissions2/<submission_id>/isolates
2015+
2016+
@api.doc('list_submission_isolates_v2')
2017+
@require_auth(keycloak_auth)
2018+
@require_permission('view_project_submissions', resource_type='project', resource_id_arg='project_id')
2019+
def get(self, project_id, submission_id):
2020+
2021+
"""List all isolates associated with a submission"""
2022+
2023+
try:
2024+
with get_db_cursor() as cursor:
2025+
cursor.execute("""
2026+
SELECT * FROM isolates
2027+
WHERE submission_id = %s
2028+
ORDER BY created_at DESC
2029+
""", (submission_id,))
2030+
2031+
isolates = cursor.fetchall()
2032+
2033+
return {
2034+
'submission_id': submission_id,
2035+
'isolates': isolates,
2036+
'total': len(isolates)
2037+
}
2038+
2039+
except Exception as e:
2040+
logger.exception(f"Error listing isolates for submission {submission_id}: {str(e)}")
2041+
return {'error': f'Failed to list isolates: {str(e)}'}, 500
2042+
2043+
@project_ns.route('/<string:project_id>/submissions/<string:submission_id>/isolates/<string:isolate_id>')
2044+
class ProjectSubmissionIsolate2(Resource):
2045+
2046+
### GET /projects/<project_id>/submissions2/<submission_id>/isolates/<isolate_id>
2047+
2048+
@api.doc('get_submission_isolate_v2')
2049+
@require_auth(keycloak_auth)
2050+
@require_permission('view_project_submissions', resource_type='project', resource_id_arg='project_id')
2051+
def get(self, project_id, submission_id, isolate_id):
2052+
2053+
"""Get details of a specific isolate associated with a submission"""
2054+
2055+
try:
2056+
with get_db_cursor() as cursor:
2057+
cursor.execute("""
2058+
SELECT * FROM isolates
2059+
WHERE id = %s AND submission_id = %s
2060+
""", (isolate_id, submission_id))
2061+
2062+
isolate = cursor.fetchone()
2063+
2064+
if not isolate:
2065+
return {'error': 'Isolate not found'}, 404
2066+
2067+
return isolate
2068+
2069+
except Exception as e:
2070+
logger.exception(f"Error retrieving isolate {isolate_id}: {str(e)}")
2071+
return {'error': f'Failed to retrieve isolate: {str(e)}'}, 500
2072+
2073+
20112074
@project_ns.route('/<string:project_id>/submissions/<string:submission_id>/upload2')
20122075
class ProjectSubmissionFiles2(Resource):
20132076

@@ -2697,8 +2760,6 @@ class Search(Resource):
26972760
@require_auth(keycloak_auth)
26982761
def post(self):
26992762

2700-
print("Search samples called")
2701-
27022763
"""Search published samples in Elasticsearch"""
27032764

27042765
try:
@@ -2730,8 +2791,7 @@ def post(self):
27302791
"minimum_should_match": 1
27312792
}
27322793
}
2733-
2734-
print(f"Access filter: {access_filter}")
2794+
27352795

27362796
# Add access filter to the query
27372797
if 'query' in data and 'bool' in data['query']:
@@ -2760,8 +2820,6 @@ def post(self):
27602820

27612821
results = query_elastic(data)
27622822

2763-
print(results)
2764-
27652823
return results, 200
27662824

27672825
except Exception as e:

0 commit comments

Comments
 (0)