From 632566097c173a211b0e76da06f222e71f1631c7 Mon Sep 17 00:00:00 2001 From: James Kent Date: Fri, 22 Sep 2023 14:20:02 -0500 Subject: [PATCH] add studyset-references endpoint --- compose/neurosynth_compose/models/analysis.py | 4 +++- compose/neurosynth_compose/openapi | 2 +- compose/neurosynth_compose/resources/__init__.py | 4 ++-- compose/neurosynth_compose/resources/analysis.py | 4 ++-- compose/neurosynth_compose/schemas/analysis.py | 10 ++++++++++ .../tests/api/test_studyset_reference.py | 8 ++++++++ store/neurostore/openapi | 2 +- 7 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 compose/neurosynth_compose/tests/api/test_studyset_reference.py diff --git a/compose/neurosynth_compose/models/analysis.py b/compose/neurosynth_compose/models/analysis.py index 999f2e12e..6f9c41d7b 100644 --- a/compose/neurosynth_compose/models/analysis.py +++ b/compose/neurosynth_compose/models/analysis.py @@ -47,6 +47,8 @@ class Specification(BaseMixin, db.Model): class StudysetReference(db.Model): __tablename__ = "studyset_references" id = db.Column(db.Text, primary_key=True) + created_at = db.Column(db.DateTime(timezone=True), server_default=func.now()) + updated_at = db.Column(db.DateTime(timezone=True), onupdate=func.now()) class Studyset(BaseMixin, db.Model): @@ -55,7 +57,7 @@ class Studyset(BaseMixin, db.Model): snapshot = db.Column(db.JSON) user_id = db.Column(db.Text, db.ForeignKey("users.external_id")) neurostore_id = db.Column(db.Text, db.ForeignKey("studyset_references.id")) - + version = db.Column(db.Text) studyset_reference = relationship("StudysetReference", backref=backref("studysets")) user = relationship("User", backref=backref("studysets")) diff --git a/compose/neurosynth_compose/openapi b/compose/neurosynth_compose/openapi index 85e9c2cbb..c091885e9 160000 --- a/compose/neurosynth_compose/openapi +++ b/compose/neurosynth_compose/openapi @@ -1 +1 @@ -Subproject commit 85e9c2cbb4ef306183306c5b651b964e35ca4171 +Subproject commit c091885e9c2f1303b0d61bb5b38a21aa2c5869f3 diff --git a/compose/neurosynth_compose/resources/__init__.py b/compose/neurosynth_compose/resources/__init__.py index 7790598a9..ada5500b0 100644 --- a/compose/neurosynth_compose/resources/__init__.py +++ b/compose/neurosynth_compose/resources/__init__.py @@ -6,7 +6,7 @@ AnnotationsView, StudysetsView, SpecificationsView, - StudysetReferencesResource, + StudysetReferencesView, AnnotationReferencesResource, NeurostoreStudiesView, ProjectsView, @@ -21,7 +21,7 @@ "NeurovaultFilesView", "AnnotationsView", "StudysetsView", - "StudysetReferencesResource", + "StudysetReferencesView", "AnnotationReferencesResource", "SpecificationsView", "UsersView", diff --git a/compose/neurosynth_compose/resources/analysis.py b/compose/neurosynth_compose/resources/analysis.py index 44b09fdc2..b46bbe077 100644 --- a/compose/neurosynth_compose/resources/analysis.py +++ b/compose/neurosynth_compose/resources/analysis.py @@ -369,7 +369,7 @@ class AnnotationsView(ObjectView, ListView): @view_maker class StudysetsView(ObjectView, ListView): - _nested = {"studyset_reference": "StudysetReferencesResource"} + _nested = {"studyset_reference": "StudysetReferencesView"} @view_maker @@ -378,7 +378,7 @@ class SpecificationsView(ObjectView, ListView): @view_maker -class StudysetReferencesResource(ObjectView): +class StudysetReferencesView(ObjectView, ListView): pass diff --git a/compose/neurosynth_compose/schemas/analysis.py b/compose/neurosynth_compose/schemas/analysis.py index a3072f2ea..40710a18d 100644 --- a/compose/neurosynth_compose/schemas/analysis.py +++ b/compose/neurosynth_compose/schemas/analysis.py @@ -129,6 +129,15 @@ class EstimatorSchema(Schema): class StudysetReferenceSchema(Schema): id = PGSQLString() + created_at = fields.DateTime() + updated_at = fields.DateTime(allow_none=True) + studysets = StringOrNested( + "StudysetSchema", + exclude=("snapshot",), + metadata={"pluck": "id"}, + many=True, + dump_only=True + ) class AnnotationReferenceSchema(Schema): @@ -154,6 +163,7 @@ class StudysetSchema(BaseSchema): neurostore_id = fields.Pluck( StudysetReferenceSchema, "id", attribute="studyset_reference" ) + version = fields.String() url = fields.String(dump_only=True) @post_dump diff --git a/compose/neurosynth_compose/tests/api/test_studyset_reference.py b/compose/neurosynth_compose/tests/api/test_studyset_reference.py new file mode 100644 index 000000000..bd2752989 --- /dev/null +++ b/compose/neurosynth_compose/tests/api/test_studyset_reference.py @@ -0,0 +1,8 @@ + +def test_studyset_references(session, app, auth_client, user_data): + nonnested = auth_client.get("/api/studyset-references?nested=false") + nested = auth_client.get("/api/studyset-references?nested=true") + + assert nonnested.status_code == nested.status_code == 200 + assert isinstance(nonnested.json['results'][0]['studysets'][0], str) + assert isinstance(nested.json['results'][0]['studysets'][0], dict) diff --git a/store/neurostore/openapi b/store/neurostore/openapi index 198069f10..c091885e9 160000 --- a/store/neurostore/openapi +++ b/store/neurostore/openapi @@ -1 +1 @@ -Subproject commit 198069f108eaf86ec5ff48cb27e7e944a078ca47 +Subproject commit c091885e9c2f1303b0d61bb5b38a21aa2c5869f3