Skip to content

Commit

Permalink
Switch to use new user submission resource
Browse files Browse the repository at this point in the history
  • Loading branch information
munrojm committed May 26, 2021
1 parent b579747 commit fabb1a4
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 22 deletions.
2 changes: 1 addition & 1 deletion app.py
Expand Up @@ -288,7 +288,7 @@
mpcomplete_store = MongoURIStore(
uri=f"mongodb+srv://{db_uri}",
database="mp_consumers",
key="snl_id",
key="submission_id",
collection_name="mpcomplete",
)

Expand Down
13 changes: 3 additions & 10 deletions src/mp_api/routes/mpcomplete/models.py
@@ -1,16 +1,13 @@
from pydantic import BaseModel, Field
from pydantic import Field
from pymatgen.core.structure import Structure
from maggma.api.models import UserSubmissionDataModel


class MPCompleteDoc(BaseModel):
class MPCompleteDoc(UserSubmissionDataModel):
"""
Defines data for MPComplete structure submissions
"""

snl_id: str = Field(
None, title="SNL ID", description="ID for the submission.",
)

structure: Structure = Field(
None,
title="Submitted structure",
Expand All @@ -24,7 +21,3 @@ class MPCompleteDoc(BaseModel):
public_email: str = Field(
None, title="Public email", description="Public email of submitter.",
)

comment: str = Field(
None, title="Submission comment", description="User comment for submission.",
)
30 changes: 23 additions & 7 deletions src/mp_api/routes/mpcomplete/query_operator.py
Expand Up @@ -13,21 +13,16 @@ def query(
structure: Structure = Body(..., title="Structure submission"),
public_name: str = Query(..., title="Public name"),
public_email: str = Query(..., title="Public email"),
comment: str = Query(..., title="Submission comment"),
) -> STORE_PARAMS:

self.structure = structure
self.public_name = public_name
self.public_email = public_email
self.comment = comment
self.snl_id = str(uuid4())

crit = {
"snl_id": self.snl_id,
"structure": structure,
"public_email": public_email,
"public_name": public_name,
"comment": comment,
}

return {"criteria": crit}
Expand All @@ -36,12 +31,33 @@ def post_process(self, written):

d = [
{
"snl_id": self.snl_id,
"structure": self.structure,
"public_email": self.public_email,
"public_name": self.public_name,
"comment": self.comment,
}
]

return d


class MPCompleteGetQuery(QueryOperator):
"""Query operators for querying on MPComplete data"""

def query(
self,
public_name: str = Query(None, title="Public name"),
public_email: str = Query(None, title="Public email"),
) -> STORE_PARAMS:

self.public_name = public_name
self.public_email = public_email

crit = {}

if public_name is not None:
crit.update({"public_name": public_name})

if public_email is not None:
crit.update({"public_name": public_email})

return {"criteria": crit}
13 changes: 9 additions & 4 deletions src/mp_api/routes/mpcomplete/resources.py
@@ -1,13 +1,18 @@
from mp_api.core.resource import ConsumerPostResource
from maggma.api.resource import UserSubmissionResource
from maggma.api.query_operator import PaginationQuery
from mp_api.routes.mpcomplete.models import MPCompleteDoc
from mp_api.routes.mpcomplete.query_operator import MPCompletePostQuery
from mp_api.routes.mpcomplete.query_operator import (
MPCompletePostQuery,
MPCompleteGetQuery,
)


def mpcomplete_resource(mpcomplete_store):
resource = ConsumerPostResource(
resource = UserSubmissionResource(
mpcomplete_store,
MPCompleteDoc,
query_operators=[MPCompletePostQuery()],
post_query_operators=[MPCompletePostQuery()],
get_query_operators=[MPCompleteGetQuery(), PaginationQuery()],
tags=["MPComplete"],
include_in_schema=True,
)
Expand Down

0 comments on commit fabb1a4

Please sign in to comment.