diff --git a/.github/workflows/generate_pages.yml b/.github/workflows/generate_pages.yml new file mode 100644 index 0000000000..1ed6afaaa4 --- /dev/null +++ b/.github/workflows/generate_pages.yml @@ -0,0 +1,41 @@ +name: Deploy Yard to GitHub Pages + +on: + push: + branches: + - "master" + workflow_dispatch: + +permissions: + pages: write # Allow writing to the GitHub Pages + id-token: write # Allow OIDC token to be issued + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + + - name: Generate Yard documentation + run: | + bundle exec yard doc + + - name: Upload artifact to GitHub Pages + uses: actions/upload-pages-artifact@v3 + with: + path: doc # Path to the folder containing the Yard documentation (default is 'doc') + + deploy: + runs-on: ubuntu-latest + needs: build # The deploy job will only run if the build job is successful + + steps: + - name: Deploy to GitHub Pages + uses: actions/deploy-pages@v4 diff --git a/.release-version b/.release-version index b1a8b7b864..648c04b679 100644 --- a/.release-version +++ b/.release-version @@ -1 +1 @@ -14.40.0 +14.41.0 diff --git a/.yardopts b/.yardopts index c73c24f784..2c9584f080 100644 --- a/.yardopts +++ b/.yardopts @@ -1,4 +1,7 @@ +--markup=markdown --asset docs/images:images +--exclude app/controllers/api/v2/[^/]*\.rb +--exclude app/controllers/api/v2/concerns/.* - LICENSE docs/*.md diff --git a/README.md b/README.md index 4630426d0e..a433bcccb2 100644 --- a/README.md +++ b/README.md @@ -67,12 +67,19 @@ a organisation of 900 people. In addition to the [externally hosted YARD docs](https://www.rubydoc.info/github/sanger/sequencescape), you can also run a local server: ```shell -yard server -r --gems -m sequencescape . +yard server --reload sequencescape ``` -You can then access the Sequencescape documentation through: [http://localhost:8808/docs/sequencescape](http://localhost:8808/docs/sequencescape) +You can then access the Sequencescape documentation through: [http://localhost:8808/docs](http://localhost:8808/docs) -Yard will also try and document the installed gems: [http://localhost:8808/docs](http://localhost:8808/docs) +If the server complains that the stack depth is too deep, this only appears to be a problem when you try to view the documentation without pre-compiling it. +Precompiling is the simple solution and can be achieved with the following. + +```shell +yard doc sequencescape +``` + +This will pre-fill the cache and allow the server command above to display the documentation without complaining about stack depths. ### Linting diff --git a/app/controllers/api/v2/tag_group_adapter_types_controller.rb b/app/controllers/api/v2/tag_group_adapter_types_controller.rb new file mode 100644 index 0000000000..e622884326 --- /dev/null +++ b/app/controllers/api/v2/tag_group_adapter_types_controller.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +module Api + module V2 + # Provides a JSON API controller for TagGroup::AdapterType + # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + class TagGroupAdapterTypesController < JSONAPI::ResourceController + # By default JSONAPI::ResourceController provides most the standard + # behaviour, and in many cases this file may be left empty. + end + end +end diff --git a/app/controllers/api/v2/tube_rack_statuses_controller.rb b/app/controllers/api/v2/tube_rack_statuses_controller.rb new file mode 100644 index 0000000000..e3744f8227 --- /dev/null +++ b/app/controllers/api/v2/tube_rack_statuses_controller.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +module Api + module V2 + # Provides a JSON API controller for TubeRackStatus + # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + class TubeRackStatusesController < JSONAPI::ResourceController + # By default JSONAPI::ResourceController provides most the standard + # behaviour, and in many cases this file may be left empty. + end + end +end diff --git a/app/models/api/study_io.rb b/app/models/api/study_io.rb index 0df0050d15..46a1cc14e5 100644 --- a/app/models/api/study_io.rb +++ b/app/models/api/study_io.rb @@ -100,6 +100,6 @@ def render_class map_attribute_to_json_attribute(:s3_email_list) map_attribute_to_json_attribute(:data_deletion_period) map_attribute_to_json_attribute(:contaminated_human_data_access_group) - with_association(:program, lookup_by: :id) { map_attribute_to_json_attribute(:name, 'program') } + with_association(:program, lookup_by: :id) { map_attribute_to_json_attribute(:name, 'programme') } end end diff --git a/app/models/tag_set.rb b/app/models/tag_set.rb new file mode 100644 index 0000000000..5bbee37cd5 --- /dev/null +++ b/app/models/tag_set.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +# Links together two related tag groups - i7 and i5 - to represent a dual index tag set +# It can also be used to represent single index tag sets +# Background explained in Y24-170 (https://github.com/sanger/sequencescape/issues/4160) +class TagSet < ApplicationRecord + # For dual index tags, tag_group is i7 oligos and tag2_group is i5 oligos + belongs_to :tag_group, class_name: 'TagGroup', optional: false + belongs_to :tag2_group, class_name: 'TagGroup', optional: true + + # We can assume adapter_type is the same for both tag groups + # But tag2_group may not be present so we delegate to tag_group + delegate :adapter_type, to: :tag_group + + validates :name, presence: true, uniqueness: true + validate :tag_group_adapter_types_must_match + + # Dynamic method to determine the visibility of a tag_set based on the visibility of its tag_groups + def visible + tag_group.visible && (tag2_group.nil? || tag2_group.visible) + end + + # Method to determine that both tag groups have the same adapter type + def tag_group_adapter_types_must_match + return unless tag2_group && tag_group.adapter_type != tag2_group.adapter_type + errors.add(:tag_group, 'Adapter types of tag groups must match') + end + + def tag_group_name=(name) + self.tag_group = TagGroup.find_by!(name: name) + end + + def tag2_group_name=(name) + self.tag2_group = TagGroup.find_by!(name: name) + end +end diff --git a/app/resources/api/v2/aliquot_resource.rb b/app/resources/api/v2/aliquot_resource.rb index 639f081ee7..fae4ea85dd 100644 --- a/app/resources/api/v2/aliquot_resource.rb +++ b/app/resources/api/v2/aliquot_resource.rb @@ -2,11 +2,18 @@ module Api module V2 - # Provides a JSON API representation of aliquot - # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note Access this resource via the `/api/v2/aliquots/` endpoint. + # + # Provides a JSON:API representation of {Aliquot}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class AliquotResource < BaseResource - # immutable # comment to make the resource mutable - default_includes :tag, :tag2 # Associations diff --git a/app/resources/api/v2/asset_audit_resource.rb b/app/resources/api/v2/asset_audit_resource.rb index a68ec83fb0..b224d7d8e6 100644 --- a/app/resources/api/v2/asset_audit_resource.rb +++ b/app/resources/api/v2/asset_audit_resource.rb @@ -2,33 +2,42 @@ module Api module V2 - # Provides a JSON API representation of AssetAudit - # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note Access this resource via the `/api/v2/asset_audits/` endpoint. + # + # Provides a JSON:API representation of {AssetAudit}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class AssetAuditResource < BaseResource model_name 'AssetAudit' # @!attribute key - # @return [String] the key of the asset audit. + # @return [String] the key of the asset audit. attribute :key # @!attribute message - # @return [String] the message of the asset audit. + # @return [String] the message of the asset audit. attribute :message # @!attribute created_by - # @return [String] the user who created the asset audit. + # @return [String] the user who created the asset audit. attribute :created_by # @!attribute asset_uuid - # @return [String] the uuid of the asset associated with the asset audit. + # @return [String] the uuid of the asset associated with the asset audit. attribute :asset_uuid # @!attribute witnessed_by - # @return [String] the user who witnessed the asset audit. + # @return [String] the user who witnessed the asset audit. attribute :witnessed_by # @!attribute metadata - # @return [Hash] the metadata of the asset audit. + # @return [Hash] the metadata of the asset audit. attribute :metadata # Currently known clients (AssetAudits app) are sending null; unsure of the expected format. # Sets the Asset on the model using the UUID provided in the API create/update request. diff --git a/app/resources/api/v2/asset_resource.rb b/app/resources/api/v2/asset_resource.rb index d763e7e6ca..543572da58 100644 --- a/app/resources/api/v2/asset_resource.rb +++ b/app/resources/api/v2/asset_resource.rb @@ -2,7 +2,17 @@ module Api module V2 - # AssetResource + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note Access this resource via the `/api/v2/assets/` endpoint. + # + # Provides a JSON:API representation of {Asset}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class AssetResource < BaseResource attributes :uuid diff --git a/app/resources/api/v2/base_resource.rb b/app/resources/api/v2/base_resource.rb index a5471641d1..9b43fe9940 100644 --- a/app/resources/api/v2/base_resource.rb +++ b/app/resources/api/v2/base_resource.rb @@ -2,8 +2,17 @@ module Api module V2 - # Provides extensions to JSONAPI::Resource as well as global behaviour - # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + # @api V2 + # @abstract + # + # @todo This documentation does not yet include complete descriptions of methods and what this class offers to its + # sub-classes. + # + # Provides a base class for JSON:API representations of {ApplicationRecord} sub-classes. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class BaseResource < JSONAPI::Resource abstract diff --git a/app/resources/api/v2/comment_resource.rb b/app/resources/api/v2/comment_resource.rb index 135513b3e3..19f8a3c9b0 100644 --- a/app/resources/api/v2/comment_resource.rb +++ b/app/resources/api/v2/comment_resource.rb @@ -2,13 +2,20 @@ module Api module V2 - # Provides a JSON API representation of Comment - # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note Access this resource via the `/api/v2/comments/` endpoint. + # + # Provides a JSON:API representation of {Comment}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class CommentResource < BaseResource # Constants... - # immutable # uncomment to make the resource immutable - # model_name / model_hint if required # Associations: diff --git a/app/resources/api/v2/custom_metadatum_collection_resource.rb b/app/resources/api/v2/custom_metadatum_collection_resource.rb index 407e60b68b..15739cce22 100644 --- a/app/resources/api/v2/custom_metadatum_collection_resource.rb +++ b/app/resources/api/v2/custom_metadatum_collection_resource.rb @@ -2,13 +2,20 @@ module Api module V2 - # Provides a JSON API representation of custom_metadatum_collection - # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note Access this resource via the `/api/v2/custom_metadatum_collections/` endpoint. + # + # Provides a JSON:API representation of {CustomMetadatumCollection}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class CustomMetadatumCollectionResource < BaseResource # Constants... - # immutable # uncomment to make the resource immutable - # model_name / model_hint if required default_includes :uuid_object, :custom_metadata diff --git a/app/resources/api/v2/fragment_resource.rb b/app/resources/api/v2/fragment_resource.rb index e7d00e33f0..8d7102c5ae 100644 --- a/app/resources/api/v2/fragment_resource.rb +++ b/app/resources/api/v2/fragment_resource.rb @@ -2,7 +2,17 @@ module Api module V2 - # Fragment + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note Access this resource via the `/api/v2/fragments/` endpoint. + # + # Provides a JSON:API representation of {Fragment}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class FragmentResource < JSONAPI::Resource attributes :uuid end diff --git a/app/resources/api/v2/labware_resource.rb b/app/resources/api/v2/labware_resource.rb index 9401bffeff..0856dd4f6f 100644 --- a/app/resources/api/v2/labware_resource.rb +++ b/app/resources/api/v2/labware_resource.rb @@ -2,7 +2,17 @@ module Api module V2 - # LabwareResource + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note Access this resource via the `/api/v2/labware/` endpoint. + # + # Provides a JSON:API representation of {Labware}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class LabwareResource < BaseResource # We import most labware shared behaviour, this includes associations, # attributes and filters. By adding behaviour here we ensure that it diff --git a/app/resources/api/v2/lane_resource.rb b/app/resources/api/v2/lane_resource.rb index 734a6d34eb..e87a2fc3eb 100644 --- a/app/resources/api/v2/lane_resource.rb +++ b/app/resources/api/v2/lane_resource.rb @@ -2,12 +2,22 @@ module Api module V2 - # Provides a JSON API representation of receptacle - # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note This resource is immutable: its endpoint will not accept `POST`, `PATCH`, or `DELETE` requests. + # @note Access this resource via the `/api/v2/lanes/` endpoint. + # + # Provides a JSON:API representation of {Lane}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class LaneResource < BaseResource # Constants... - immutable # comment to make the resource mutable + immutable # Associations: has_many :samples diff --git a/app/resources/api/v2/lot_resource.rb b/app/resources/api/v2/lot_resource.rb index 86ad91ef94..20c8ee55b5 100644 --- a/app/resources/api/v2/lot_resource.rb +++ b/app/resources/api/v2/lot_resource.rb @@ -2,13 +2,20 @@ module Api module V2 - # Provides a JSON API representation of Lot - # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note Access this resource via the `/api/v2/lots/` endpoint. + # + # Provides a JSON:API representation of {Lot}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class LotResource < BaseResource # Constants... - # immutable # uncomment to make the resource immutable - # model_name / model_hint if required default_includes :uuid_object diff --git a/app/resources/api/v2/lot_type_resource.rb b/app/resources/api/v2/lot_type_resource.rb index f842daec54..c0eceeccfd 100644 --- a/app/resources/api/v2/lot_type_resource.rb +++ b/app/resources/api/v2/lot_type_resource.rb @@ -2,12 +2,22 @@ module Api module V2 - # Provides a JSON API representation of LotType - # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note This resource is immutable: its endpoint will not accept `POST`, `PATCH`, or `DELETE` requests. + # @note Access this resource via the `/api/v2/lot_types/` endpoint. + # + # Provides a JSON:API representation of {LotType}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class LotTypeResource < BaseResource # Constants... - immutable # comment to make the resource mutable + immutable # model_name / model_hint if required diff --git a/app/resources/api/v2/order_resource.rb b/app/resources/api/v2/order_resource.rb index 08561b164f..e603d7e8a2 100644 --- a/app/resources/api/v2/order_resource.rb +++ b/app/resources/api/v2/order_resource.rb @@ -2,13 +2,20 @@ module Api module V2 - # Provides a JSON API representation of order - # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note Access this resource via the `/api/v2/orders/` endpoint. + # + # Provides a JSON:API representation of {Order}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class OrderResource < BaseResource # Constants... - # immutable # uncomment to make the resource immutable - # model_name / model_hint if required default_includes :uuid_object diff --git a/app/resources/api/v2/pick_list_resource.rb b/app/resources/api/v2/pick_list_resource.rb index 8aa78d5245..874c1e163d 100644 --- a/app/resources/api/v2/pick_list_resource.rb +++ b/app/resources/api/v2/pick_list_resource.rb @@ -2,15 +2,22 @@ module Api module V2 - # Provides a JSON API representation of PickList - # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note 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](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class PickListResource < BaseResource # Constants... PERMITTED_PICK_ATTRIBUTES = %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 - # immutable # uncomment to make the resource immutable - # model_name / model_hint if required # Associations diff --git a/app/resources/api/v2/plate_purpose_resource.rb b/app/resources/api/v2/plate_purpose_resource.rb index f4ba76f83e..138e929181 100644 --- a/app/resources/api/v2/plate_purpose_resource.rb +++ b/app/resources/api/v2/plate_purpose_resource.rb @@ -2,8 +2,17 @@ module Api module V2 - # Provides a JSON API representation of PlatePurpose - # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note Access this resource via the `/api/v2/plate_purposes/` endpoint. + # + # Provides a JSON:API representation of {PlatePurpose}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class PlatePurposeResource < BaseResource model_name 'PlatePurpose' @@ -13,34 +22,34 @@ class PlatePurposeResource < BaseResource # The following attributes are sent by Limber for a new plate purpose. - # @!attribute [rw] - # @return [String] The name of the plate purpose. + # @!attribute [rw] name + # @return [String] the name of the plate purpose. attribute :name - # @!attribute [rw] - # @return [Boolean] Whether the plates of this purpose are stock plates. + # @!attribute [rw] stock_plate + # @return [Boolean] whether the plates of this purpose are stock plates. attribute :stock_plate - # @!attribute [rw] - # @return [Boolean] Whether the plates of this purpose are cherrypickable. + # @!attribute [rw] cherrypickable_target + # @return [Boolean] whether the plates of this purpose are cherrypickable. attribute :cherrypickable_target - # @!attribute [rw] - # @return [Boolean] Whether the plates of this purpose are input plates. + # @!attribute [rw] input_plate + # @return [Boolean] whether the plates of this purpose are input plates. attribute :input_plate - # @!attribute [rw] - # @return [Integer] The size of the plates of this purpose. + # @!attribute [rw] size + # @return [Integer] the size of the plates of this purpose. attribute :size - # @!attribute [rw] - # @return [String] The name of the shape of the plates of this purpose. + # @!attribute [rw] asset_shape + # @return [String] the name of the shape of the plates of this purpose. attribute :asset_shape # The following attribute is required by Limber to store purposes. - # @!attribute [r] - # @return [String] gets the UUID of the plate purpose. + # @!attribute [r] uuid + # @return [String] the UUID of the plate purpose. attribute :uuid # Sets the asset shape of the plate purpose by name if given. diff --git a/app/resources/api/v2/plate_resource.rb b/app/resources/api/v2/plate_resource.rb index 6747f6be0b..9a0cfc13cf 100644 --- a/app/resources/api/v2/plate_resource.rb +++ b/app/resources/api/v2/plate_resource.rb @@ -2,8 +2,17 @@ module Api module V2 - # Provides a JSON API representation of Plate - # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note Access this resource via the `/api/v2/plates/` endpoint. + # + # Provides a JSON:API representation of {Plate}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class PlateResource < BaseResource # We import most labware shared behaviour, this includes associations, # attributes and filters @@ -13,8 +22,6 @@ class PlateResource < BaseResource # Constants... - # immutable # comment to make the resource mutable - default_includes :uuid_object, :barcodes, :plate_purpose, :transfer_requests # Associations: diff --git a/app/resources/api/v2/plate_template_resource.rb b/app/resources/api/v2/plate_template_resource.rb index 5e4ebef7bd..abdb47375d 100644 --- a/app/resources/api/v2/plate_template_resource.rb +++ b/app/resources/api/v2/plate_template_resource.rb @@ -2,13 +2,20 @@ module Api module V2 - # Provides a JSON API representation of PlateTemplate - # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note Access this resource via the `/api/v2/plate_templates/` endpoint. + # + # Provides a JSON:API representation of {PlateTemplate}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class PlateTemplateResource < BaseResource # Constants... - # immutable # uncomment to make the resource immutable - # model_name / model_hint if required default_includes :uuid_object diff --git a/app/resources/api/v2/poly_metadatum_resource.rb b/app/resources/api/v2/poly_metadatum_resource.rb index 031f444c6d..32e69b6ece 100644 --- a/app/resources/api/v2/poly_metadatum_resource.rb +++ b/app/resources/api/v2/poly_metadatum_resource.rb @@ -2,13 +2,20 @@ module Api module V2 - # Provides a JSON API representation of PolyMetadatum - # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note Access this resource via the `/api/v2/poly_metadata/` endpoint. + # + # Provides a JSON:API representation of {PolyMetadatum}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class PolyMetadatumResource < BaseResource # Constants... - # immutable # uncomment to make the resource immutable - # model_name / model_hint if required # Associations: diff --git a/app/resources/api/v2/pre_capture_pool_resource.rb b/app/resources/api/v2/pre_capture_pool_resource.rb index 6d181fe879..c3755d0102 100644 --- a/app/resources/api/v2/pre_capture_pool_resource.rb +++ b/app/resources/api/v2/pre_capture_pool_resource.rb @@ -2,13 +2,20 @@ module Api module V2 - # Provides a JSON API representation of pre_capture_pool - # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note Access this resource via the `/api/v2/pre_capture_pools/` endpoint. + # + # Provides a JSON:API representation of {PreCapturePool}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class PreCapturePoolResource < BaseResource # Constants... - # immutable # uncomment to make the resource immutable - # model_name / model_hint if required default_includes :uuid_object diff --git a/app/resources/api/v2/primer_panel_resource.rb b/app/resources/api/v2/primer_panel_resource.rb index aa45bb63ab..f273a97f80 100644 --- a/app/resources/api/v2/primer_panel_resource.rb +++ b/app/resources/api/v2/primer_panel_resource.rb @@ -2,13 +2,20 @@ module Api module V2 - # Provides a JSON API representation of primer_panel - # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note Access this resource via the `/api/v2/primer_panels/` endpoint. + # + # Provides a JSON:API representation of {PrimerPanel}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class PrimerPanelResource < BaseResource # Constants... - # immutable # uncomment to make the resource immutable - # model_name / model_hint if required attribute :name, readonly: true attribute :programs, readonly: true diff --git a/app/resources/api/v2/project_resource.rb b/app/resources/api/v2/project_resource.rb index 6cb3d19b39..25fdb44d63 100644 --- a/app/resources/api/v2/project_resource.rb +++ b/app/resources/api/v2/project_resource.rb @@ -2,8 +2,20 @@ module Api module V2 + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note This resource is immutable: its endpoint will not accept `POST`, `PATCH`, or `DELETE` requests. + # @note Access this resource via the `/api/v2/projects/` endpoint. + # + # Provides a JSON:API representation of {Project}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class ProjectResource < BaseResource - immutable # comment to make the resource mutable + immutable default_includes :uuid_object diff --git a/app/resources/api/v2/purpose_resource.rb b/app/resources/api/v2/purpose_resource.rb index a9b4a0afcd..0c26a6b88d 100644 --- a/app/resources/api/v2/purpose_resource.rb +++ b/app/resources/api/v2/purpose_resource.rb @@ -2,13 +2,20 @@ module Api module V2 - # Provides a JSON API representation of purpose - # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note Access this resource via the `/api/v2/purposes/` endpoint. + # + # Provides a JSON:API representation of {Purpose}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class PurposeResource < BaseResource # Constants... - # immutable # uncomment to make the resource immutable - # model_name / model_hint if required default_includes :uuid_object diff --git a/app/resources/api/v2/qc_assay_resource.rb b/app/resources/api/v2/qc_assay_resource.rb index 06fdb08bba..7dae2e1d1d 100644 --- a/app/resources/api/v2/qc_assay_resource.rb +++ b/app/resources/api/v2/qc_assay_resource.rb @@ -2,8 +2,17 @@ module Api module V2 - # Provides a JSON API representation of QC Assay - # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note Access this resource via the `/api/v2/qc_assays/` endpoint. + # + # Provides a JSON:API representation of {QcAssay}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class QcAssayResource < BaseResource attribute :lot_number attribute :qc_results diff --git a/app/resources/api/v2/qc_result_resource.rb b/app/resources/api/v2/qc_result_resource.rb index 3a5166ea5b..1e20037179 100644 --- a/app/resources/api/v2/qc_result_resource.rb +++ b/app/resources/api/v2/qc_result_resource.rb @@ -2,8 +2,17 @@ module Api module V2 - # Provides a JSON API representation of QC Result - # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note Access this resource via the `/api/v2/qc_results/` endpoint. + # + # Provides a JSON:API representation of {QcResult}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class QcResultResource < BaseResource attributes :key, :value, :units, :cv, :assay_type, :assay_version diff --git a/app/resources/api/v2/qcable_resource.rb b/app/resources/api/v2/qcable_resource.rb index c1c1d8dfc0..5e9f45e178 100644 --- a/app/resources/api/v2/qcable_resource.rb +++ b/app/resources/api/v2/qcable_resource.rb @@ -2,13 +2,20 @@ module Api module V2 - # Provides a JSON API representation of Qcable - # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note Access this resource via the `/api/v2/qcables/` endpoint. + # + # Provides a JSON:API representation of {Qcable}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class QcableResource < BaseResource # Constants... - # immutable # uncomment to make the resource immutable - # model_name / model_hint if required default_includes :uuid_object, :barcodes diff --git a/app/resources/api/v2/racked_tube_resource.rb b/app/resources/api/v2/racked_tube_resource.rb index 16e7b2eb5e..452c60fd22 100644 --- a/app/resources/api/v2/racked_tube_resource.rb +++ b/app/resources/api/v2/racked_tube_resource.rb @@ -2,13 +2,20 @@ module Api module V2 - # Provides a JSON API representation of a RackedTube - # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note Access this resource via the `/api/v2/racked_tubes/` endpoint. + # + # Provides a JSON:API representation of {RackedTube}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class RackedTubeResource < BaseResource # Constants... - # immutable # uncomment to make the resource immutable - # model_name / model_hint if required # Associations: diff --git a/app/resources/api/v2/receptacle_resource.rb b/app/resources/api/v2/receptacle_resource.rb index be010bc6a1..f42b677e43 100644 --- a/app/resources/api/v2/receptacle_resource.rb +++ b/app/resources/api/v2/receptacle_resource.rb @@ -2,16 +2,23 @@ module Api module V2 - # Provides a JSON API representation of a receptacle - # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note Access this resource via the `/api/v2/receptacles/` endpoint. + # + # Provides a JSON:API representation of {Receptacle}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class ReceptacleResource < BaseResource # We import most receptacle shared behaviour, this includes associations, # attributes and filters. By adding behaviour here we ensure that it # is automatically available on well. include Api::V2::SharedBehaviour::Receptacle - # immutable # uncomment to make the resource immutable - default_includes :uuid_object # Associations: diff --git a/app/resources/api/v2/request_resource.rb b/app/resources/api/v2/request_resource.rb index 968bcba398..1c5788ed2f 100644 --- a/app/resources/api/v2/request_resource.rb +++ b/app/resources/api/v2/request_resource.rb @@ -2,13 +2,20 @@ module Api module V2 - # Provides a JSON API representation of request - # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note Access this resource via the `/api/v2/requests/` endpoint. + # + # Provides a JSON:API representation of {Request}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class RequestResource < BaseResource # Constants... - # immutable # comment to make the resource mutable - # model_name / model_hint if required default_includes :uuid_object, diff --git a/app/resources/api/v2/request_type_resource.rb b/app/resources/api/v2/request_type_resource.rb index ce7d0f3ff0..8b70c4569d 100644 --- a/app/resources/api/v2/request_type_resource.rb +++ b/app/resources/api/v2/request_type_resource.rb @@ -2,12 +2,22 @@ module Api module V2 - # Provides a JSON API representation of request_type - # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note This resource is immutable: its endpoint will not accept `POST`, `PATCH`, or `DELETE` requests. + # @note Access this resource via the `/api/v2/request_types/` endpoint. + # + # Provides a JSON:API representation of {RequestType}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class RequestTypeResource < BaseResource # Constants... - immutable # comment to make the resource mutable + immutable # model_name / model_hint if required diff --git a/app/resources/api/v2/sample_manifest_resource.rb b/app/resources/api/v2/sample_manifest_resource.rb index c8c8d5dd2b..7ca8d7eb9f 100644 --- a/app/resources/api/v2/sample_manifest_resource.rb +++ b/app/resources/api/v2/sample_manifest_resource.rb @@ -2,10 +2,20 @@ module Api module V2 - # Class required by json-api-resources gem to support serving the information from - # a sample manifest. + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note This resource is immutable: its endpoint will not accept `POST`, `PATCH`, or `DELETE` requests. + # @note Access this resource via the `/api/v2/sample_manifests/` endpoint. + # + # Provides a JSON:API representation of {SampleManifest}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class SampleManifestResource < BaseResource - immutable # comment to make the resource mutable + immutable default_includes :uuid_object diff --git a/app/resources/api/v2/sample_metadata_resource.rb b/app/resources/api/v2/sample_metadata_resource.rb index f96d48393e..200bf8c489 100644 --- a/app/resources/api/v2/sample_metadata_resource.rb +++ b/app/resources/api/v2/sample_metadata_resource.rb @@ -2,7 +2,18 @@ module Api module V2 - # SampleMetadataResource + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note This resource is immutable: its endpoint will not accept `POST`, `PATCH`, or `DELETE` requests. + # @note Access this resource via the `/api/v2/sample_metadata/` endpoint. + # + # Provides a JSON:API representation of {Sample::Metadata}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class SampleMetadataResource < BaseResource # Set add_model_hint true to allow updates from Limber, otherwise get a # 500 error as it looks for resource Api::V2::MetadatumResource @@ -12,40 +23,40 @@ class SampleMetadataResource < BaseResource # Attributes ### - # @!attribute [rw] - # @return [String] The sample cohort. + # @!attribute [rw] cohort + # @return [String] the sample cohort. attribute :cohort - # @!attribute [rw] - # @return [String] The name of the body collecting the sample. + # @!attribute [rw] collected_by + # @return [String] the name of the body collecting the sample. attribute :collected_by - # @!attribute [rw] - # @return [String] The sample concentration. + # @!attribute [rw] concentration + # @return [String] the sample concentration. attribute :concentration - # @!attribute [rw] - # @return [String] The ID of the sample donor. + # @!attribute [rw] donor_id + # @return [String] the ID of the sample donor. attribute :donor_id - # @!attribute [rw] - # @return [String] The gender of the organism providing the sample. + # @!attribute [rw] gender + # @return [String] the gender of the organism providing the sample. attribute :gender - # @!attribute [rw] - # @return [String] The common name for the sample. + # @!attribute [rw] sample_common_name + # @return [String] the common name for the sample. attribute :sample_common_name - # @!attribute [rw] - # @return [String] A description of the sample. + # @!attribute [rw] sample_description + # @return [String] a description of the sample. attribute :sample_description - # @!attribute [rw] - # @return [String] The supplier name for the sample. + # @!attribute [rw] supplier_name + # @return [String] the supplier name for the sample. attribute :supplier_name - # @!attribute [rw] - # @return [String] The volume of the sample. + # @!attribute [rw] volume + # @return [String] the volume of the sample. attribute :volume ### diff --git a/app/resources/api/v2/sample_resource.rb b/app/resources/api/v2/sample_resource.rb index bce06ed299..c831493d20 100644 --- a/app/resources/api/v2/sample_resource.rb +++ b/app/resources/api/v2/sample_resource.rb @@ -2,11 +2,18 @@ module Api module V2 - # Class required by json-api-resources gem to be able to read the information of - # a sample + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note Access this resource via the `/api/v2/samples/` endpoint. + # + # Provides a JSON:API representation of {Sample}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class SampleResource < BaseResource - # immutable # comment to make the resource mutable - default_includes :uuid_object has_one :sample_metadata, class_name: 'SampleMetadata', foreign_key_on: :related diff --git a/app/resources/api/v2/shared_behaviour/labware.rb b/app/resources/api/v2/shared_behaviour/labware.rb index 37417dbdc5..6f0858fa1d 100644 --- a/app/resources/api/v2/shared_behaviour/labware.rb +++ b/app/resources/api/v2/shared_behaviour/labware.rb @@ -7,62 +7,75 @@ # on its effective subclasses (Liskov Substitution Principle) this is especially # true for relationships, as it means we support pre-loading those relationships # on mixed endpoints -module Api::V2::SharedBehaviour::Labware - extend ActiveSupport::Concern +module Api + module V2 + module SharedBehaviour + module Labware + extend ActiveSupport::Concern - included do - # Associations: - has_one :purpose, readonly: true, foreign_key: :plate_purpose_id, class_name: 'Purpose' - has_one :custom_metadatum_collection, foreign_key_on: :related + included do + # Associations: + has_one :purpose, readonly: true, foreign_key: :plate_purpose_id, class_name: 'Purpose' + has_one :custom_metadatum_collection, foreign_key_on: :related - has_many :samples, readonly: true - has_many :studies, readonly: true - has_many :projects, readonly: true - has_many :comments, readonly: true + has_many :samples, readonly: true + has_many :studies, readonly: true + has_many :projects, readonly: true + has_many :comments, readonly: true - # If we are using api/v2/labware to pull back a list of labware, we may - # expect a mix of plates and tubes. If we want to eager load their - # contents we use the generic 'receptacles' association. - has_many :receptacles, readonly: true, polymorphic: true - has_many :ancestors, readonly: true, polymorphic: true - has_many :descendants, readonly: true, polymorphic: true - has_many :parents, readonly: true, polymorphic: true - has_many :children, readonly: true, polymorphic: true - has_many :child_plates, readonly: true - has_many :child_tubes, readonly: true - has_many :direct_submissions, readonly: true - has_many :state_changes, readonly: true + # If we are using api/v2/labware to pull back a list of labware, we may + # expect a mix of plates and tubes. If we want to eager load their + # contents we use the generic 'receptacles' association. + has_many :receptacles, readonly: true, polymorphic: true + has_many :ancestors, readonly: true, polymorphic: true + has_many :descendants, readonly: true, polymorphic: true + has_many :parents, readonly: true, polymorphic: true + has_many :children, readonly: true, polymorphic: true + has_many :child_plates, readonly: true + has_many :child_tubes, readonly: true + has_many :direct_submissions, readonly: true + has_many :state_changes, readonly: true - # Attributes - attribute :uuid, readonly: true - attribute :name, delegate: :display_name, readonly: true - attribute :labware_barcode, readonly: true - attribute :state, readonly: true - attribute :created_at, readonly: true - attribute :updated_at, readonly: true + # Attributes + attribute :uuid, readonly: true + attribute :name, delegate: :display_name, readonly: true + attribute :labware_barcode, readonly: true + attribute :state, readonly: true + attribute :created_at, readonly: true + attribute :updated_at, readonly: true - # Scopes - filter :barcode, apply: ->(records, value, _options) { records.with_barcode(value) } - filter :uuid, apply: ->(records, value, _options) { records.with_uuid(value) } - filter :purpose_name, - apply: (lambda { |records, value, _options| records.joins(:purpose).where(plate_purposes: { name: value }) }) - filter :purpose_id, apply: ->(records, value, _options) { records.where(plate_purpose_id: value) } - filter :without_children, apply: ->(records, _value, _options) { records.without_children } - filter :created_at_gt, - apply: (lambda { |records, value, _options| records.where('labware.created_at > ?', value[0].to_date) }) - filter :updated_at_gt, - apply: (lambda { |records, value, _options| records.where('labware.updated_at > ?', value[0].to_date) }) - filter :include_used, apply: ->(records, value, _options) { records.include_labware_with_children(value) } - end + # Scopes + filter :barcode, apply: ->(records, value, _options) { records.with_barcode(value) } + filter :uuid, apply: ->(records, value, _options) { records.with_uuid(value) } + filter :purpose_name, + apply: + ( + lambda do |records, value, _options| + records.joins(:purpose).where(plate_purposes: { name: value }) + end + ) + filter :purpose_id, apply: ->(records, value, _options) { records.where(plate_purpose_id: value) } + filter :without_children, apply: ->(records, _value, _options) { records.without_children } + filter :created_at_gt, + apply: + (lambda { |records, value, _options| records.where('labware.created_at > ?', value[0].to_date) }) + filter :updated_at_gt, + apply: + (lambda { |records, value, _options| records.where('labware.updated_at > ?', value[0].to_date) }) + filter :include_used, apply: ->(records, value, _options) { records.include_labware_with_children(value) } + end - # Custom methods - # These shouldn't be used for business logic, and a more about - # I/O and isolating implementation details. - def labware_barcode - { - 'ean13_barcode' => _model.ean13_barcode, - 'machine_barcode' => _model.machine_barcode, - 'human_barcode' => _model.human_barcode - } + # Custom methods + # These shouldn't be used for business logic, and a more about + # I/O and isolating implementation details. + def labware_barcode + { + 'ean13_barcode' => _model.ean13_barcode, + 'machine_barcode' => _model.machine_barcode, + 'human_barcode' => _model.human_barcode + } + end + end + end end end diff --git a/app/resources/api/v2/shared_behaviour/receptacle.rb b/app/resources/api/v2/shared_behaviour/receptacle.rb index b66bc27bb1..0b77436614 100644 --- a/app/resources/api/v2/shared_behaviour/receptacle.rb +++ b/app/resources/api/v2/shared_behaviour/receptacle.rb @@ -6,44 +6,50 @@ # sense to ensure that all methods present on Receptacle are also on Well # (Liskov Substitution Principle) this is especially true for relationships, # as it means we support pre-loading those relationships on mixed endpoints -module Api::V2::SharedBehaviour::Receptacle - extend ActiveSupport::Concern - - included do - ::Tube.descendants.each { |subclass| model_hint model: subclass, resource: :tube } - - # Associations: - has_many :samples, readonly: true - has_many :studies, readonly: true - has_many :projects, readonly: true - - has_many :requests_as_source, readonly: true - has_many :requests_as_target, readonly: true - has_many :qc_results, readonly: true - has_many :aliquots, readonly: true - - has_many :downstream_assets, readonly: true, polymorphic: true - has_many :downstream_wells, readonly: true - has_many :downstream_plates, readonly: true - has_many :downstream_tubes, readonly: true - - has_many :upstream_assets, readonly: true, polymorphic: true - has_many :upstream_wells, readonly: true - has_many :upstream_plates, readonly: true - has_many :upstream_tubes, readonly: true - - has_many :transfer_requests_as_source, readonly: true - has_many :transfer_requests_as_target, readonly: true - - has_one :labware, readonly: true - - # Attributes - attribute :uuid, readonly: true - attribute :name, delegate: :display_name, readonly: true - attributes :pcr_cycles, :submit_for_sequencing, :sub_pool, :coverage, :diluent_volume - attribute :state, readonly: true - - # Filters - filter :uuid, apply: ->(records, value, _options) { records.with_uuid(value) } +module Api + module V2 + module SharedBehaviour + module Receptacle + extend ActiveSupport::Concern + + included do + ::Tube.descendants.each { |subclass| model_hint model: subclass, resource: :tube } + + # Associations: + has_many :samples, readonly: true + has_many :studies, readonly: true + has_many :projects, readonly: true + + has_many :requests_as_source, readonly: true + has_many :requests_as_target, readonly: true + has_many :qc_results, readonly: true + has_many :aliquots, readonly: true + + has_many :downstream_assets, readonly: true, polymorphic: true + has_many :downstream_wells, readonly: true + has_many :downstream_plates, readonly: true + has_many :downstream_tubes, readonly: true + + has_many :upstream_assets, readonly: true, polymorphic: true + has_many :upstream_wells, readonly: true + has_many :upstream_plates, readonly: true + has_many :upstream_tubes, readonly: true + + has_many :transfer_requests_as_source, readonly: true + has_many :transfer_requests_as_target, readonly: true + + has_one :labware, readonly: true + + # Attributes + attribute :uuid, readonly: true + attribute :name, delegate: :display_name, readonly: true + attributes :pcr_cycles, :submit_for_sequencing, :sub_pool, :coverage, :diluent_volume + attribute :state, readonly: true + + # Filters + filter :uuid, apply: ->(records, value, _options) { records.with_uuid(value) } + end + end + end end end diff --git a/app/resources/api/v2/state_change_resource.rb b/app/resources/api/v2/state_change_resource.rb index de4c9941ef..b2b6e86182 100644 --- a/app/resources/api/v2/state_change_resource.rb +++ b/app/resources/api/v2/state_change_resource.rb @@ -2,8 +2,20 @@ module Api module V2 + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note This resource is immutable: its endpoint will not accept `POST`, `PATCH`, or `DELETE` requests. + # @note Access this resource via the `/api/v2/state_changes/` endpoint. + # + # Provides a JSON:API representation of {StateChange}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class StateChangeResource < BaseResource - immutable # comment to make the resource mutable + immutable attribute :previous_state attribute :target_state diff --git a/app/resources/api/v2/study_resource.rb b/app/resources/api/v2/study_resource.rb index 8334537498..f36b2bd50c 100644 --- a/app/resources/api/v2/study_resource.rb +++ b/app/resources/api/v2/study_resource.rb @@ -2,8 +2,20 @@ module Api module V2 + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note This resource is immutable: its endpoint will not accept `POST`, `PATCH`, or `DELETE` requests. + # @note Access this resource via the `/api/v2/studies/` endpoint. + # + # Provides a JSON:API representation of {Study}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class StudyResource < BaseResource - immutable # comment to make the resource mutable + immutable attribute :name attribute :uuid diff --git a/app/resources/api/v2/submission_resource.rb b/app/resources/api/v2/submission_resource.rb index b5561f1bb4..f3a5335d65 100644 --- a/app/resources/api/v2/submission_resource.rb +++ b/app/resources/api/v2/submission_resource.rb @@ -2,12 +2,22 @@ module Api module V2 - # Provides a JSON API representation of submission - # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note This resource is immutable: its endpoint will not accept `POST`, `PATCH`, or `DELETE` requests. + # @note Access this resource via the `/api/v2/submissions/` endpoint. + # + # Provides a JSON:API representation of {Submission}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class SubmissionResource < BaseResource # Constants... - immutable # comment to make the resource mutable + immutable # model_name / model_hint if required diff --git a/app/resources/api/v2/submission_template_resource.rb b/app/resources/api/v2/submission_template_resource.rb index f72d3fbaa7..cee638c27d 100644 --- a/app/resources/api/v2/submission_template_resource.rb +++ b/app/resources/api/v2/submission_template_resource.rb @@ -2,8 +2,18 @@ module Api module V2 - # Provides a JSON API representation of a submission template. - # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note This resource is immutable: its endpoint will not accept `POST`, `PATCH`, or `DELETE` requests. + # @note Access this resource via the `/api/v2/submission_templates/` endpoint. + # + # Provides a JSON:API representation of {SubmissionTemplate}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class SubmissionTemplateResource < BaseResource immutable @@ -13,12 +23,12 @@ class SubmissionTemplateResource < BaseResource # Attributes ### - # @!attribute [r] - # @return [String] The name of the submission template. + # @!attribute [rw] name + # @return [String] the name of the submission template. attribute :name - # @!attribute [r] - # @return [String] The UUID of the submission template. + # @!attribute [r] uuid + # @return [String] the UUID of the submission template. attribute :uuid, readonly: true end end diff --git a/app/resources/api/v2/tag_group_adapter_type_resource.rb b/app/resources/api/v2/tag_group_adapter_type_resource.rb index 78cd6bf8e3..fc2cb5047e 100644 --- a/app/resources/api/v2/tag_group_adapter_type_resource.rb +++ b/app/resources/api/v2/tag_group_adapter_type_resource.rb @@ -2,17 +2,22 @@ module Api module V2 - # Provides a JSON API representation of a tag group AdapterType - # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note Access this resource via the `/api/v2/tag_group_adapter_types/` endpoint. + # + # Provides a JSON:API representation of {TagGroup::AdapterType}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class TagGroupAdapterTypeResource < BaseResource - model_name 'TagGroup::AdapterType', add_model_hint: false + model_name 'TagGroup::AdapterType' # Constants... - # immutable # uncomment to make the resource immutable - - # model_name / model_hint if required - # Associations: has_many :tag_groups, readonly: true, class_name: 'TagGroup' diff --git a/app/resources/api/v2/tag_group_resource.rb b/app/resources/api/v2/tag_group_resource.rb index 4552cd6ed9..7b2409b61f 100644 --- a/app/resources/api/v2/tag_group_resource.rb +++ b/app/resources/api/v2/tag_group_resource.rb @@ -2,13 +2,20 @@ module Api module V2 - # Provides a JSON API representation of TagGroup - # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note Access this resource via the `/api/v2/tag_groups/` endpoint. + # + # Provides a JSON:API representation of {TagGroup}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class TagGroupResource < BaseResource # Constants... - # immutable # uncomment to make the resource immutable - # model_name / model_hint if required default_includes :uuid_object, :tags diff --git a/app/resources/api/v2/tag_layout_template_resource.rb b/app/resources/api/v2/tag_layout_template_resource.rb index ab633c4429..4dd63a48a2 100644 --- a/app/resources/api/v2/tag_layout_template_resource.rb +++ b/app/resources/api/v2/tag_layout_template_resource.rb @@ -2,27 +2,65 @@ module Api module V2 - # Provides a JSON API representation of TagLayoutTemplate - # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note This resource is immutable: its endpoint will not accept `POST`, `PATCH`, or `DELETE` requests. + # @note Access this resource via the `/api/v2/tag_layout_templates/` endpoint. + # + # Provides a JSON:API representation of {TagLayoutTemplate}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class TagLayoutTemplateResource < BaseResource # Constants... # immutable # uncomment to make the resource immutable - # model_name / model_hint if required - - default_includes :uuid_object - - # Associations: + # @!attribute [r] tag_group + # A relationship for the primary tag group associated with the tag layout template. + # @return [Api::V2::TagGroupResource] has_one :tag_group has_one :tag2_group + # @!attribute [r] tag2_group + # A relationship for the secondary tag group associated with the tag layout template. + # This is used during dual indexing, but will not be found during single indexing. + # @return [Api::V2::TagGroupResource] + has_one :tag2_group, class_name: 'TagGroup' + + ### # Attributes + ### + + # @!attribute [r] uuid + # The UUID of the tag layout template. + # @return [String] attribute :uuid, readonly: true + + # @!attribute [r] name + # The display name of the tag layout template. + # @return [String] + attribute :name, readonly: true + + # @!attribute [r] direction + # The name of the algorithm defining the direction of the tag layout. + # @return [String] attribute :direction, readonly: true + + # @!attribute [r] walking_by + # The name of the algorithm defining the way of walking through the tag layout. + # @return [String] attribute :walking_by, readonly: true # Filters + ### + + # @!method enabled + # A filter to return only enabled tag layout templates. + # Set by default to `true`. filter :enabled, default: true # Custom methods diff --git a/app/resources/api/v2/tag_resource.rb b/app/resources/api/v2/tag_resource.rb index 3f1048f559..4c75af8311 100644 --- a/app/resources/api/v2/tag_resource.rb +++ b/app/resources/api/v2/tag_resource.rb @@ -2,12 +2,22 @@ module Api module V2 - # Provides a JSON API representation of aliquot - # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note This resource is immutable: its endpoint will not accept `POST`, `PATCH`, or `DELETE` requests. + # @note Access this resource via the `/api/v2/tags/` endpoint. + # + # Provides a JSON:API representation of {Tag}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class TagResource < BaseResource # Constants... - immutable # comment to make the resource mutable + immutable # model_name / model_hint if required diff --git a/app/resources/api/v2/template_resource.rb b/app/resources/api/v2/template_resource.rb index bdee319f56..a462ec61c9 100644 --- a/app/resources/api/v2/template_resource.rb +++ b/app/resources/api/v2/template_resource.rb @@ -2,6 +2,8 @@ module Api module V2 + # @abstract + # # This stub class is here to appease a problem with JSONAPI v0.9 # and polymorphic relationships. Also stubbing the TemplatesController. class TemplateResource < BaseResource diff --git a/app/resources/api/v2/transfer_request_resource.rb b/app/resources/api/v2/transfer_request_resource.rb index 9034f9f5a7..084f34a07c 100644 --- a/app/resources/api/v2/transfer_request_resource.rb +++ b/app/resources/api/v2/transfer_request_resource.rb @@ -2,12 +2,22 @@ module Api module V2 - # Provides a JSON API representation of TransferRequest - # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note This resource is immutable: its endpoint will not accept `POST`, `PATCH`, or `DELETE` requests. + # @note Access this resource via the `/api/v2/transfer_requests/` endpoint. + # + # Provides a JSON:API representation of {TransferRequest}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class TransferRequestResource < BaseResource # Constants... - immutable # comment to make the resource mutable + immutable # model_name / model_hint if required diff --git a/app/resources/api/v2/transfer_template_resource.rb b/app/resources/api/v2/transfer_template_resource.rb index 6a41f76373..4439e74191 100644 --- a/app/resources/api/v2/transfer_template_resource.rb +++ b/app/resources/api/v2/transfer_template_resource.rb @@ -2,8 +2,18 @@ module Api module V2 - # Provides a JSON API representation of a transfer template. - # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note This resource is immutable: its endpoint will not accept `POST`, `PATCH`, or `DELETE` requests. + # @note Access this resource via the `/api/v2/transfer_templates/` endpoint. + # + # Provides a JSON:API representation of {TransferTemplate}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class TransferTemplateResource < BaseResource immutable @@ -13,12 +23,12 @@ class TransferTemplateResource < BaseResource # Attributes ### - # @!attribute [r] - # @return [String] The name of the transfer template. + # @!attribute [r] name + # @return [String] the name of the transfer template. attribute :name - # @!attribute [r] - # @return [String] The UUID of the transfer template. + # @!attribute [r] uuid + # @return [String] the UUID of the transfer template. attribute :uuid, readonly: true end end diff --git a/app/resources/api/v2/tube_purpose_resource.rb b/app/resources/api/v2/tube_purpose_resource.rb index aa08d628d1..44f34e4345 100644 --- a/app/resources/api/v2/tube_purpose_resource.rb +++ b/app/resources/api/v2/tube_purpose_resource.rb @@ -2,8 +2,17 @@ module Api module V2 - # Provides a JSON API representation of a tube purpose. - # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note Access this resource via the `/api/v2/tube_purposes/` endpoint. + # + # Provides a JSON:API representation of {Tube::Purpose}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class TubePurposeResource < BaseResource model_name 'Tube::Purpose' @@ -11,21 +20,21 @@ class TubePurposeResource < BaseResource # Attributes ##### - # @!attribute [rw] - # @return [String] The name of the tube purpose. + # @!attribute [rw] name + # @return [String] the name of the tube purpose. attribute :name - # @!attribute [rw] - # @return [String] The purpose type. This is mapped to the type attribute on the model. + # @!attribute [rw] purpose_type + # @return [String] the purpose type. This is mapped to the type attribute on the model. attribute :purpose_type, delegate: :type - # @!attribute [rw] - # @return [String] The target type. + # @!attribute [rw] target_type + # @return [String] the target type. attribute :target_type - # @!attribute [r] - # @return [String] The UUID of the tube purpose. - attribute :uuid + # @!attribute [r] uuid + # @return [String] the UUID of the tube purpose. + attribute :uuid, readonly: true # Gets the list of fields which are creatable on a TubePurpose. # @@ -42,6 +51,8 @@ def self.creatable_fields(_context) def self.updatable_fields(_context) super - %i[uuid] # Do not allow creating with any readonly fields end + + filter :type, default: 'Tube::Purpose' end end end diff --git a/app/resources/api/v2/tube_rack_resource.rb b/app/resources/api/v2/tube_rack_resource.rb index e2b35aa8bc..72004ae850 100644 --- a/app/resources/api/v2/tube_rack_resource.rb +++ b/app/resources/api/v2/tube_rack_resource.rb @@ -2,8 +2,17 @@ module Api module V2 - # Provides a JSON API representation of TubeRack - # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note Access this resource via the `/api/v2/tube_racks/` endpoint. + # + # Provides a JSON:API representation of {TubeRack}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class TubeRackResource < BaseResource # Constants... @@ -13,8 +22,6 @@ class TubeRackResource < BaseResource # Instead this should be done as part of adding authentication to # the API in the security OKR. - # immutable # uncomment to make the resource immutable - # model_name / model_hint if required default_includes :uuid_object, :barcodes diff --git a/app/resources/api/v2/tube_rack_status_resource.rb b/app/resources/api/v2/tube_rack_status_resource.rb index 0c70d83346..eedfa63f02 100644 --- a/app/resources/api/v2/tube_rack_status_resource.rb +++ b/app/resources/api/v2/tube_rack_status_resource.rb @@ -2,11 +2,18 @@ module Api module V2 - # Provides a JSON API representation of TubeRackStatus - # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note Access this resource via the `/api/v2/tube_rack_statuses/` endpoint. + # + # Provides a JSON:API representation of {TubeRackStatus}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class TubeRackStatusResource < BaseResource - # immutable # uncomment to make the resource immutable - # model_name / model_hint if required default_includes :uuid_object diff --git a/app/resources/api/v2/tube_resource.rb b/app/resources/api/v2/tube_resource.rb index 88b78c1cdc..69bf38c62a 100644 --- a/app/resources/api/v2/tube_resource.rb +++ b/app/resources/api/v2/tube_resource.rb @@ -2,14 +2,24 @@ module Api module V2 - # Provides a JSON API representation of Tube - # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note This resource is immutable: its endpoint will not accept `POST`, `PATCH`, or `DELETE` requests. + # @note Access this resource via the `/api/v2/tubes/` endpoint. + # + # Provides a JSON:API representation of {Tube}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class TubeResource < BaseResource include Api::V2::SharedBehaviour::Labware # Constants... - immutable # comment to make the resource mutable + immutable default_includes :uuid_object, :barcodes, :transfer_requests_as_target diff --git a/app/resources/api/v2/user_resource.rb b/app/resources/api/v2/user_resource.rb index 228a83f6e5..c899c32d57 100644 --- a/app/resources/api/v2/user_resource.rb +++ b/app/resources/api/v2/user_resource.rb @@ -2,12 +2,22 @@ module Api module V2 - # Provides a JSON API representation of user - # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note This resource is immutable: its endpoint will not accept `POST`, `PATCH`, or `DELETE` requests. + # @note Access this resource via the `/api/v2/users/` endpoint. + # + # Provides a JSON:API representation of {User}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class UserResource < BaseResource # Constants... - immutable # comment to make the resource mutable + immutable # model_name / model_hint if required diff --git a/app/resources/api/v2/volume_update_resource.rb b/app/resources/api/v2/volume_update_resource.rb index 9c8ea04f0c..7d4b558f8b 100644 --- a/app/resources/api/v2/volume_update_resource.rb +++ b/app/resources/api/v2/volume_update_resource.rb @@ -2,21 +2,30 @@ module Api module V2 - # Provides a JSON API representation of VolumeUpdate - # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note Access this resource via the `/api/v2/volume_updates/` endpoint. + # + # Provides a JSON:API representation of {VolumeUpdate}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class VolumeUpdateResource < BaseResource model_name 'VolumeUpdate' # @!attribute created_by - # @return [String] the user who created the volume update. + # @return [String] the user who created the volume update. attribute :created_by # @!attribute asset_uuid - # @return [String] the uuid of the target labware associated with the volume update. + # @return [String] the uuid of the target labware associated with the volume update. attribute :target_uuid # @!attribute witnessed_by - # @return [Float] the volume change that occured on the target labware. + # @return [Float] the volume change that occured on the target labware. attribute :volume_change # Sets the target Labware on the model using the UUID provided in the API create/update request. diff --git a/app/resources/api/v2/well_resource.rb b/app/resources/api/v2/well_resource.rb index 32e5469405..d3f69d1e3b 100644 --- a/app/resources/api/v2/well_resource.rb +++ b/app/resources/api/v2/well_resource.rb @@ -2,15 +2,22 @@ module Api module V2 - # Provides a JSON API representation of a well - # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note Access this resource via the `/api/v2/wells/` endpoint. + # + # Provides a JSON:API representation of {Well}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. class WellResource < BaseResource include Api::V2::SharedBehaviour::Receptacle # Constants... - # immutable # uncomment to make the resource immutable - default_includes :uuid_object, :map, :transfer_requests_as_target, plate: :barcodes # Associations: diff --git a/app/resources/api/v2/work_order_resource.rb b/app/resources/api/v2/work_order_resource.rb index aca53e5660..fa7274aa2e 100644 --- a/app/resources/api/v2/work_order_resource.rb +++ b/app/resources/api/v2/work_order_resource.rb @@ -4,13 +4,20 @@ module Api module V2 + # @todo This documentation does not yet include a detailed description of what this resource (really) represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. # - # Class WorkOrderResource provides an abstraction of - # request for exposure to external applications. It - # is intended to allow us to update the internal - # representation, while maintaining an external - # interface + # @note Access this resource via the `/api/v2/work_orders/` endpoint. # + # Provides a JSON:API representation of {WorkOrder}. + # Work orders provide an abstraction of requests for exposure to external applications. + # They are intended to allow us to update the internal representation, while maintaining an external interface. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. + class WorkOrderResource < BaseResource IGNORED_METADATA_FIELDS = %w[id request_id created_at updated_at].freeze diff --git a/config/default_records/request_types/014_limber_scrna_core_cdna_prep_request_types.wip.yml b/config/default_records/request_types/014_limber_scrna_core_cdna_prep_request_types.wip.yml index 4d357144fa..31c2f9352c 100644 --- a/config/default_records/request_types/014_limber_scrna_core_cdna_prep_request_types.wip.yml +++ b/config/default_records/request_types/014_limber_scrna_core_cdna_prep_request_types.wip.yml @@ -20,14 +20,12 @@ limber_scrna_core_cdna_prep_gem_x_5p_pbmc_pools_input: name: scRNA Core cDNA Prep GEM-X 5p PBMC Pools Input asset_type: Well order: 1 - request_class_name: IlluminaHtp::Requests::StdLibraryRequest + request_class_name: CustomerRequest for_multiplexing: false billable: true product_line_name: Short Read acceptable_purposes: - LRC PBMC Pools Input - library_types: - - Chromium single cell GEM-X 5p v3 GE limber_scrna_core_aggregation: name: scRNA Core Aggregation asset_type: Well diff --git a/config/default_records/tag_sets/001_chromium_dual_index_tag_sets.wip.yml b/config/default_records/tag_sets/001_chromium_dual_index_tag_sets.wip.yml new file mode 100644 index 0000000000..504d02bd81 --- /dev/null +++ b/config/default_records/tag_sets/001_chromium_dual_index_tag_sets.wip.yml @@ -0,0 +1,13 @@ +--- +PN-1000215/PN-3000431 Dual Index Kit TT, Set A: + name: PN-1000215/PN-3000431 Dual Index Kit TT, Set A + tag_group_name: PN-1000215/PN-3000431 Dual Index Kit TT, Set A (i7) + tag2_group_name: PN-1000215/PN-3000431 Dual Index Kit TT, Set A (i5) +PN-1000250 Dual Index Kit TN, Set A: + name: PN-1000250 Dual Index Kit TN, Set A + tag_group_name: PN-1000250 Dual Index Kit TN, Set A (i7) + tag2_group_name: PN-1000250 Dual Index Kit TN, Set A (i5) +PN-1000251 Dual Index Kit TS, Set A: + name: PN-1000251 Dual Index Kit TS, Set A + tag_group_name: PN-1000251 Dual Index Kit TS, Set A (i7) + tag2_group_name: PN-1000251 Dual Index Kit TS, Set A (i5) diff --git a/config/routes.rb b/config/routes.rb index 036d3cb635..41d0b2485f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -50,8 +50,10 @@ jsonapi_resources :studies jsonapi_resources :submission_templates jsonapi_resources :submissions + jsonapi_resources :tag_group_adapter_types jsonapi_resources :tag_groups jsonapi_resources :tag_layout_templates + jsonapi_resources :tags jsonapi_resources :transfer_requests jsonapi_resources :transfer_templates jsonapi_resources :tube_purposes diff --git a/db/migrate/20240813130010_add_tag_sets.rb b/db/migrate/20240813130010_add_tag_sets.rb new file mode 100644 index 0000000000..ec14b20af5 --- /dev/null +++ b/db/migrate/20240813130010_add_tag_sets.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true +class AddTagSets < ActiveRecord::Migration[6.1] + def change + create_table :tag_sets do |t| + t.string :name, null: false, unique: true + t.references :tag_group, foreign_key: true, null: false, type: :integer + t.references :tag2_group, foreign_key: { to_table: 'tag_groups' }, type: :integer + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 48632176aa..207c08263d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2024_07_30_085322) do +ActiveRecord::Schema.define(version: 2024_08_13_130010) do create_table "aliquot_indices", id: :integer, charset: "utf8mb4", collation: "utf8mb4_unicode_ci", options: "ENGINE=InnoDB ROW_FORMAT=DYNAMIC", force: :cascade do |t| t.integer "aliquot_id", null: false @@ -1717,6 +1717,16 @@ t.index ["tag2_group_id"], name: "fk_rails_d221e7c041" end + create_table "tag_sets", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| + t.string "name", null: false + t.integer "tag_group_id", null: false + t.integer "tag2_group_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["tag2_group_id"], name: "index_tag_sets_on_tag2_group_id" + t.index ["tag_group_id"], name: "index_tag_sets_on_tag_group_id" + end + create_table "tags", id: :integer, charset: "utf8mb4", collation: "utf8mb4_unicode_ci", options: "ENGINE=InnoDB ROW_FORMAT=DYNAMIC", force: :cascade do |t| t.string "oligo" t.integer "map_id" @@ -1990,6 +2000,8 @@ add_foreign_key "tag_layout_template_submissions", "tag_layout_templates" add_foreign_key "tag_layout_templates", "tag_groups", column: "tag2_group_id" add_foreign_key "tag_layouts", "tag_groups", column: "tag2_group_id" + add_foreign_key "tag_sets", "tag_groups" + add_foreign_key "tag_sets", "tag_groups", column: "tag2_group_id" add_foreign_key "transfer_request_collection_transfer_requests", "transfer_request_collections" add_foreign_key "transfer_request_collection_transfer_requests", "transfer_requests" add_foreign_key "transfer_request_collections", "users" diff --git a/lib/record_loader/tag_set_loader.rb b/lib/record_loader/tag_set_loader.rb new file mode 100644 index 0000000000..010c8bf68f --- /dev/null +++ b/lib/record_loader/tag_set_loader.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +# This file was automatically generated via `rails g record_loader` + +# RecordLoader handles automatic population and updating of database records +# across different environments +# @see https://rubydoc.info/github/sanger/record_loader/ +module RecordLoader + # Creates the specified TagSet if they are not present + class TagSetLoader < ApplicationRecordLoader + config_folder 'tag_sets' + + def create_or_update!(name, options) + TagSet.create_with(options).find_or_create_by!(name: name) + end + end +end diff --git a/lib/tasks/record_loader/tag_set.rake b/lib/tasks/record_loader/tag_set.rake new file mode 100644 index 0000000000..9ce1207113 --- /dev/null +++ b/lib/tasks/record_loader/tag_set.rake @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +# This file was automatically generated via `rails g record_loader` +namespace :record_loader do + desc 'Automatically generate TagSet through TagSetLoader' + task tag_set: :environment do + RecordLoader::TagSetLoader.new.create! + end +end + +# Automatically run this record loader as part of record_loader:all +# Remove this line if the task should only run when invoked explicitly +task 'record_loader:all' => 'record_loader:tag_set' diff --git a/spec/data/record_loader/tag_sets/tag_sets_basic.yml b/spec/data/record_loader/tag_sets/tag_sets_basic.yml new file mode 100644 index 0000000000..58937f9403 --- /dev/null +++ b/spec/data/record_loader/tag_sets/tag_sets_basic.yml @@ -0,0 +1,10 @@ +# This file was automatically generated via `rails g record_loader` +# You should modify it to match your particular model. +--- +Tag Set 1: + name: Tag Set 1 + tag_group_name: Tag Group 1 +Tag Set 2: + name: Tag Set 2 + tag_group_name: Tag Group 2 + tag2_group_name: Tag Group 3 diff --git a/spec/factories/tag_set_factories.rb b/spec/factories/tag_set_factories.rb new file mode 100644 index 0000000000..abc467563f --- /dev/null +++ b/spec/factories/tag_set_factories.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :tag_set do + transient { adapter_type { build(:adapter_type) } } + + sequence(:name) { |n| "Tag Set #{n}" } + tag_group { create(:tag_group, adapter_type:) } + tag2_group { create(:tag_group, adapter_type:) } + end +end diff --git a/spec/lib/record_loader/tag_set_loader_spec.rb b/spec/lib/record_loader/tag_set_loader_spec.rb new file mode 100644 index 0000000000..bad4b490f2 --- /dev/null +++ b/spec/lib/record_loader/tag_set_loader_spec.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +require 'rails_helper' +require 'record_loader/tag_set_loader' + +# This file was initially generated via `rails g record_loader` +RSpec.describe RecordLoader::TagSetLoader, :loader, type: :model do + def a_new_record_loader + described_class.new(directory: test_directory, files: selected_files) + end + + subject(:record_loader) { a_new_record_loader } + + # Tests use a separate directory to avoid coupling your specs to the data + let(:test_directory) { Rails.root.join('spec/data/record_loader/tag_sets') } + + context 'with tag_sets_basic selected' do + let(:selected_files) { 'tag_sets_basic' } + # Required tag groups referenced by the tag sets + let!(:tag_group1) { create(:tag_group, name: 'Tag Group 1') } + let!(:tag_group2) { create(:tag_group, name: 'Tag Group 2') } + let!(:tag_group3) { create(:tag_group, name: 'Tag Group 3') } + + it 'creates two records' do + expect { record_loader.create! }.to change(TagSet, :count).by(2) + end + + # It is important that multiple runs of a RecordLoader do not create additional + # copies of existing records. + it 'is idempotent' do + record_loader.create! + expect { a_new_record_loader }.not_to change(TagSet, :count) + end + + it 'sets attributes on the created records' do + record_loader.create! + ts1 = TagSet.find_by(name: 'Tag Set 1') + ts2 = TagSet.find_by(name: 'Tag Set 2') + + expect(ts1).to have_attributes(name: 'Tag Set 1', tag_group_id: tag_group1.id, tag2_group_id: nil) + + expect(ts2).to have_attributes(name: 'Tag Set 2', tag_group_id: tag_group2.id, tag2_group_id: tag_group3.id) + end + end +end diff --git a/spec/models/api/study_io_spec.rb b/spec/models/api/study_io_spec.rb index 2159286944..db1188fd17 100644 --- a/spec/models/api/study_io_spec.rb +++ b/spec/models/api/study_io_spec.rb @@ -54,7 +54,7 @@ 's3_email_list' => 'aa1@sanger.ac.uk;aa2@sanger.ac.uk', 'data_deletion_period' => '3 months', 'contaminated_human_data_access_group' => 'contaminated human data access group test', - 'program' => 'General', + 'programme' => 'General', 'manager' => [ { login: manager.login, email: manager.email, name: manager.name }, { login: manager2.login, email: manager2.email, name: manager2.name } diff --git a/spec/models/tag_set_spec.rb b/spec/models/tag_set_spec.rb new file mode 100644 index 0000000000..e515b9308f --- /dev/null +++ b/spec/models/tag_set_spec.rb @@ -0,0 +1,115 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe TagSet do + describe 'validations' do + it 'is valid with valid attributes' do + tag_set = build(:tag_set) + expect(tag_set).to be_valid + end + + it 'is valid without a tag2_group' do + tag_set = build(:tag_set, tag2_group: nil) + expect(tag_set).to be_valid + end + + it 'is valid when the tag groups have the same adapter type' do + adapter_type = build(:adapter_type) + tag_group = create(:tag_group, adapter_type: adapter_type) + tag_group2 = create(:tag_group, adapter_type: adapter_type) + tag_set = build(:tag_set, tag_group: tag_group, tag2_group: tag_group2) + expect(tag_set).to be_valid + end + + it 'is not valid without a name' do + tag_set = build(:tag_set, name: nil) + expect(tag_set).not_to be_valid + expect(tag_set.errors[:name]).to include("can't be blank") + end + + it 'is not valid when the name is not unique' do + create(:tag_set, name: 'test name') + tag_set2 = build(:tag_set, name: 'test name') + expect(tag_set2).not_to be_valid + expect(tag_set2.errors[:name]).to include('has already been taken') + end + + it 'is not valid without a tag_group' do + tag_set = build(:tag_set, tag_group: nil, tag2_group: nil) + expect(tag_set).not_to be_valid + expect(tag_set.errors[:tag_group]).to include('must exist') + end + + it 'is not valid when the tag groups have different adapter types' do + tag_group1 = create(:tag_group, adapter_type: build(:adapter_type)) + tag_group2 = create(:tag_group, adapter_type: build(:adapter_type)) + tag_set = build(:tag_set, tag_group: tag_group1, tag2_group: tag_group2) + expect(tag_set).not_to be_valid + expect(tag_set.errors[:tag_group]).to include('Adapter types of tag groups must match') + end + end + + describe '#visible' do + it 'returns true if it only has one tag_group and it is set to visible' do + tag_group = create(:tag_group, visible: true) + tag_set = create(:tag_set, tag_group: tag_group, tag2_group: nil) + expect(tag_set.visible).to be(true) + end + + it 'returns false if it only has one tag_group and it is not set to visible' do + tag_group = create(:tag_group, visible: false) + tag_set = create(:tag_set, tag_group: tag_group, tag2_group: nil) + expect(tag_set.visible).to be(false) + end + + it 'returns true if both tag_groups are set to visible' do + tag_group = create_list(:tag_group, 2, visible: true) + tag_set = create(:tag_set, tag_group: tag_group[0], tag2_group: tag_group[1]) + expect(tag_set.visible).to be(true) + end + + it 'returns false if one of the tag_groups is not set to visible' do + tag_group = create(:tag_group, visible: true) + tag_group2 = create(:tag_group, visible: false) + tag_set = create(:tag_set, tag_group: tag_group, tag2_group: tag_group2) + expect(tag_set.visible).to be(false) + end + end + + describe '#adapter_type' do + it 'delegates to tag_group' do + tag_group = create(:tag_group) + tag_set = create(:tag_set, tag_group: tag_group, tag2_group: nil) + expect(tag_set.adapter_type).to eq(tag_group.adapter_type) + end + end + + describe '#tag_group_name=' do + it 'sets the tag_group' do + tag_group = create(:tag_group) + tag_set = build(:tag_set) + tag_set.tag_group_name = tag_group.name + expect(tag_set.tag_group).to eq(tag_group) + end + + it 'raises an error if the tag_group does not exist' do + tag_set = build(:tag_set) + expect { tag_set.tag_group_name = 'non-existent tag group' }.to raise_error(ActiveRecord::RecordNotFound) + end + end + + describe '#tag2_group_name=' do + it 'sets the tag_group' do + tag_group = create(:tag_group) + tag_set = build(:tag_set) + tag_set.tag2_group_name = tag_group.name + expect(tag_set.tag2_group).to eq(tag_group) + end + + it 'raises an error if the tag_group does not exist' do + tag_set = build(:tag_set) + expect { tag_set.tag2_group_name = 'non-existent tag group' }.to raise_error(ActiveRecord::RecordNotFound) + end + end +end diff --git a/spec/tasks/support/disable_hiseq_submission_templates_spec.rb b/spec/tasks/support/disable_hiseq_submission_templates_spec.rb index 2da1a64dc6..ada83a6dca 100644 --- a/spec/tasks/support/disable_hiseq_submission_templates_spec.rb +++ b/spec/tasks/support/disable_hiseq_submission_templates_spec.rb @@ -2,10 +2,16 @@ require 'rails_helper' -# only load Rake tasks if they haven't been loaded already -Rails.application.load_tasks if Rake::Task.tasks.empty? - describe 'support:disable_hiseq_submission_templates', type: :task do + let(:load_tasks) { Rails.application.load_tasks } + let(:task_reenable) { Rake::Task[self.class.top_level_description].reenable } + let(:task_invoke) { Rake::Task[self.class.top_level_description].invoke } + + before do + load_tasks # Load tasks directly in the test to avoid intermittent CI failures + task_reenable # Allows the task to be invoked again and ensures it is intially enabled + end + context 'when the disable_hiseq_submission_templates task is invoked' do it 'updates all hiseq submissions to have a superceded_by_id of -2' do # Create unused submission templates @@ -21,7 +27,7 @@ allow(Rails.logger).to receive(:info) - Rake::Task['support:disable_hiseq_submission_templates'].invoke + task_invoke expect(Rails.logger).to have_received(:info).with('Disabled 10 HiSeq submission templates.').at_least(:once) # Expect all hiseq submissions to have a superceded_by_id of -2