Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sample definition routes #248

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Sample definition routes #248

wants to merge 3 commits into from

Conversation

mgaonach
Copy link
Collaborator

Routes for ssx sample definition:

  • Sample create/update/delete
  • With sample composition and crystal composition declaration

@mgaonach mgaonach requested a review from stufisher January 24, 2023 13:52
res = query.count()
if res == 0:
raise HTTPException(
status_code=403, detail="User is not authorized for proposal"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here i would return 404 Proposal not found and log that the user was attempting to access a proposal for which they didn't have access

old_sample.Crystal = crystal

proposal = crystal.Protein.Proposal
authorize_for_proposal(proposal.proposalId)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think you should need this.

old_sample = get_samples(blSampleId=blSampleId, skip=0, limit=1).first

will check the authorization of the current user vs the sample and return an empty list if they dont have access, thus throwing IndexError which the route function will catch

)


@router.get("/components/types", response_model=list[schema.ComponentType])
Copy link
Collaborator

@stufisher stufisher Feb 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning a list is technically not a valid REST response. It should be encapsulated in a dict. Could be solved by simply paginating this response

return Paged(total=total, results=results, skip=skip, limit=limit)


def get_component_types() -> list[models.ComponentType]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe paginate these responses, if only for consistency?

return results


def get_concentration_types() -> list[models.ConcentrationType]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, maybe paginate these responses, if only for consistency?

sample = crud.update_sample(blSampleId=blSampleId, sample=sample)
return sample
except IndexError:
raise HTTPException(status_code=404, detail="Sample not found")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might like a final except Exception to catch anything else that might go wrong as is done on the shipment route:

    except Exception:
        logger.exception(
            f"Could not update shipping `{shippingId}` with payload `{shipping}`"
        )
        raise HTTPException(status_code=400, detail="Could not update shipment")

) -> models.BLSample:
"""create a sample"""
sample = crud.create_sample(sample=sample)
return sample
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can concat this onto a single line

Copy link
Collaborator

@stufisher stufisher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks.

Would you like to return the sample_compositions with the sample? The query is a bit involved and some parsing faff, but its doable

@stufisher
Copy link
Collaborator

Probably also need a couple of checks for
hasattr(models, 'Component')
to not break the app where this (and other new) tables are not deployed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants