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 4be989e69..c091885e9 160000 --- a/compose/neurosynth_compose/openapi +++ b/compose/neurosynth_compose/openapi @@ -1 +1 @@ -Subproject commit 4be989e697d603a9c3534de561c786b565c6aa80 +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..2295b8f66 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(allow_none=True) 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 4be989e69..c091885e9 160000 --- a/store/neurostore/openapi +++ b/store/neurostore/openapi @@ -1 +1 @@ -Subproject commit 4be989e697d603a9c3534de561c786b565c6aa80 +Subproject commit c091885e9c2f1303b0d61bb5b38a21aa2c5869f3