Skip to content

Commit

Permalink
[ENH] add studyset-references endpoint (#596)
Browse files Browse the repository at this point in the history
* add studyset-references endpoint

* allow version to be none
  • Loading branch information
jdkent authored Sep 22, 2023
1 parent 636438c commit b0d35b2
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 7 deletions.
4 changes: 3 additions & 1 deletion compose/neurosynth_compose/models/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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"))

Expand Down
2 changes: 1 addition & 1 deletion compose/neurosynth_compose/openapi
4 changes: 2 additions & 2 deletions compose/neurosynth_compose/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
AnnotationsView,
StudysetsView,
SpecificationsView,
StudysetReferencesResource,
StudysetReferencesView,
AnnotationReferencesResource,
NeurostoreStudiesView,
ProjectsView,
Expand All @@ -21,7 +21,7 @@
"NeurovaultFilesView",
"AnnotationsView",
"StudysetsView",
"StudysetReferencesResource",
"StudysetReferencesView",
"AnnotationReferencesResource",
"SpecificationsView",
"UsersView",
Expand Down
4 changes: 2 additions & 2 deletions compose/neurosynth_compose/resources/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ class AnnotationsView(ObjectView, ListView):

@view_maker
class StudysetsView(ObjectView, ListView):
_nested = {"studyset_reference": "StudysetReferencesResource"}
_nested = {"studyset_reference": "StudysetReferencesView"}


@view_maker
Expand All @@ -378,7 +378,7 @@ class SpecificationsView(ObjectView, ListView):


@view_maker
class StudysetReferencesResource(ObjectView):
class StudysetReferencesView(ObjectView, ListView):
pass


Expand Down
10 changes: 10 additions & 0 deletions compose/neurosynth_compose/schemas/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion store/neurostore/openapi

0 comments on commit b0d35b2

Please sign in to comment.