Class: Api::V2::PickListResource
- Inherits:
-
BaseResource
- Object
- JSONAPI::Resource
- BaseResource
- Api::V2::PickListResource
- Defined in:
- app/resources/api/v2/pick_list_resource.rb
Overview
This documentation does not yet include a detailed description of what this resource represents.
This documentation does not yet include detailed descriptions for relationships, attributes and filters.
This documentation does not yet include any example usage of the API via cURL or similar.
Access this resource via the /api/v2/pick_lists/
endpoint.
Provides a JSON:API representation of PickList.
For more information about JSON:API see the JSON:API Specifications or look at the JSONAPI::Resources package for Sequencescape’s implementation of the JSON:API standard.
Constant Summary collapse
- PERMITTED_PICK_ATTRIBUTES =
Constants…
%i[source_receptacle_id study_id project_id].freeze
- PERMITTED_LABWARE_PICK_ATTRIBUTES =
%i[source_labware_id source_labware_barcode study_id project_id].freeze
Instance Method Summary collapse
-
#labware_pick_attributes=(labware_picks) ⇒ Object
This provides an alternative API for passing in a list of labware, either by ids or barcodes.
- #pick_attributes ⇒ Object
-
#pick_attributes=(picks) ⇒ Object
JSON API v1.0 doesn’t have native support for creating nested resources in a single request.
Methods inherited from BaseResource
apply_includes, creatable_fields, default_includes, #fetchable_fields, inclusions, resolve_relationship_names_to_relations, updatable_fields
Instance Method Details
#labware_pick_attributes=(labware_picks) ⇒ Object
This provides an alternative API for passing in a list of labware, either by ids or barcodes. This avoids the need to make additional requests for the receptacle ids. We keep this as a separate accessor to avoid the confusion of passing in a list of 12 picks, and receiving more back.
62 63 64 65 66 67 68 69 70 71 |
# File 'app/resources/api/v2/pick_list_resource.rb', line 62 def labware_pick_attributes=(labware_picks) # Extract and look up records here before passing through cache = PickList::RecordCache::ByLabware.new(labware_picks) @model.pick_attributes = labware_picks.flat_map { |pick| cache.convert(pick.permit(PERMITTED_LABWARE_PICK_ATTRIBUTES)) } rescue KeyError => e # We'll see this if one of the attributes passed in doesn't match an actual record, # such as a non-existent study id. raise JSONAPI::Exceptions::BadRequest, e. end |
#pick_attributes ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'app/resources/api/v2/pick_list_resource.rb', line 73 def pick_attributes @model.pick_attributes.map do |pick| { source_receptacle_id: pick[:source_receptacle].id, study_id: pick[:study]&.id, project_id: pick[:project]&.id } end end |
#pick_attributes=(picks) ⇒ Object
JSON API v1.0 doesn’t have native support for creating nested resources in a single request. In addition, as picks are not backed by real database records yet we could expect to run into issues anyway. So we just expose our pick attributes. However, as we can’t expect to receive actual receptacles/studies/projects over the API, we convert them from the ids. The RecordCache allows us to do this with a single database query.
48 49 50 51 52 53 54 55 56 |
# File 'app/resources/api/v2/pick_list_resource.rb', line 48 def pick_attributes=(picks) # Extract and look up records here before passing through cache = PickList::RecordCache::ByReceptacle.new(picks) @model.pick_attributes = picks.map { |pick| cache.convert(pick.permit(PERMITTED_PICK_ATTRIBUTES)) } rescue KeyError => e # We'll see this if one of the attributes passed in doesn't match an actual record, # such as a non-existent study id. raise JSONAPI::Exceptions::BadRequest, e. end |