diff --git a/crc/api.yml b/crc/api.yml index 52abbde4..35c12862 100644 --- a/crc/api.yml +++ b/crc/api.yml @@ -110,6 +110,19 @@ paths: application/json: schema: $ref: "#/components/schemas/Study" + /study-files: + get: + operationId: crc.api.study.all_studies_and_files + summary: Provides a list of studies with submitted files + tags: + - Studies + responses: + '200': + description: An array of studies, with submitted files, ordered by the last modified date. + content: + application/json: + schema: + $ref: "#/components/schemas/Study" /study/{study_id}: parameters: - name: study_id diff --git a/crc/api/study.py b/crc/api/study.py index c162e15a..88a68b58 100644 --- a/crc/api/study.py +++ b/crc/api/study.py @@ -7,7 +7,7 @@ from sqlalchemy.exc import IntegrityError from crc import session from crc.api.common import ApiError, ApiErrorSchema from crc.models.protocol_builder import ProtocolBuilderStatus, ProtocolBuilderStudy -from crc.models.study import StudySchema, StudyModel, Study +from crc.models.study import StudySchema, StudyFilesSchema, StudyModel, Study from crc.services.protocol_builder import ProtocolBuilderService from crc.services.study_service import StudyService @@ -67,6 +67,13 @@ def all_studies(): return results +def all_studies_and_files(): + """Returns all studies with submitted files""" + studies = StudyService.get_studies_with_files() + results = StudyFilesSchema(many=True).dump(studies) + return results + + def post_update_study_from_protocol_builder(study_id): """Update a single study based on data received from the protocol builder.""" diff --git a/crc/services/study_service.py b/crc/services/study_service.py index 6d1f4bc5..8e1fd9c6 100644 --- a/crc/services/study_service.py +++ b/crc/services/study_service.py @@ -32,6 +32,12 @@ class StudyService(object): studies.append(StudyService.get_study(study_model.id, study_model)) return studies + @staticmethod + def get_studies_with_files(): + """Returns a list of all studies""" + db_studies = session.query(StudyModel).all() + return db_studies + @staticmethod def get_study(study_id, study_model: StudyModel = None): """Returns a study model that contains all the workflows organized by category.