Class: Api::V2::TubeRackResource

Inherits:
BaseResource
  • Object
show all
Defined in:
app/resources/api/v2/tube_rack_resource.rb

Overview

Note:

Access this resource via the /api/v2/tube_racks/ endpoint.

Provides a JSON:API representation of TubeRack.

This resource represents a tube rack, which can contain a collection of tubes, with locations specified for each tube in the rack. Tubes are linked via the RackedTubes association

For more information about JSON:API see the JSON:API Specifications or look at the JSONAPI::Resources package for Sequencescape's implementation of the JSON:API standard.

Examples:

GET request to fetch a Tube Rack by its ID:

GET /api/v2/tube_racks/{id}/

POST request to create a new Tube Rack with a name and barcode:

POST /api/v2/tube_racks/
{
  "data": {
    "type": "tube_racks",
    "attributes": {
        "size": 48,
        "name": "Rack A1",
        "tube_locations": {
            "A1": { "uuid": "558b931c-fb5f-11ef-86cc-000000000000" },
            "B1": { "uuid": "2abc4186-3718-11ec-9c4c-acde48001122" },
            "C1": { "uuid": "2ace27fc-3718-11ec-9c4c-acde48001122" }
        }
    }
  }
}

PATCH request to update the Tube Rack's size:

PATCH /api/v2/tube_racks/123
{
  "data": {
    "id": 123,
    "type": "tube_racks",
    "attributes": {
        "size": 96
    }
  }
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseResource

apply_includes, creatable_fields, default_includes, #fetchable_fields, inclusions, resolve_relationship_names_to_relations, updatable_fields

Instance Attribute Details

#commentsCommentResource (readonly)

Note:

Comments are readonly and provide additional context or notes regarding the tube rack.

Returns A collection of comments related to the tube rack.

Returns:



114
# File 'app/resources/api/v2/tube_rack_resource.rb', line 114

has_many :comments, readonly: true

#created_atString (readonly)

Returns The timestamp when the tube rack was created. Readonly.

Returns:

  • (String)

    The timestamp when the tube rack was created. Readonly.



60
# File 'app/resources/api/v2/tube_rack_resource.rb', line 60

attribute :created_at, readonly: true

#labware_barcodeHash

Note:

The labware barcode can be returned in different formats, such as EAN13 or machine-readable formats.

Returns A hash containing the different types of barcodes associated with the tube rack.

Returns:

  • (Hash)

    A hash containing the different types of barcodes associated with the tube rack.



66
# File 'app/resources/api/v2/tube_rack_resource.rb', line 66

attribute :labware_barcode, write_once: true

#nameString

Note:

This is a write-once attribute, meaning it cannot be modified once it has been set.

Returns The name of the tube rack.

Returns:

  • (String)

    The name of the tube rack.



71
# File 'app/resources/api/v2/tube_rack_resource.rb', line 71

attribute :name, write_once: true

#number_of_columnsInteger

Note:

A POST request errors when this attribute is provided. I believe these are automatically calculated based on the size of the tube rack.

Note:

This is a write-once attribute, meaning it cannot be modified once it has been set.

Returns The number of columns in the tube rack.

Returns:

  • (Integer)

    The number of columns in the tube rack.



78
# File 'app/resources/api/v2/tube_rack_resource.rb', line 78

attribute :number_of_columns, write_once: true

#number_of_rowsInteger

Note:

A POST request errors when this attribute is provided. I believe these are automatically calculated based on the size of the tube rack.

Note:

This is a write-once attribute, meaning it cannot be modified once it has been set.

Returns The number of rows in the tube rack.

Returns:

  • (Integer)

    The number of rows in the tube rack.



85
# File 'app/resources/api/v2/tube_rack_resource.rb', line 85

attribute :number_of_rows, write_once: true

#purposePurposeResource

Returns The purpose associated with the tube rack.

Returns:



118
# File 'app/resources/api/v2/tube_rack_resource.rb', line 118

has_one :purpose, foreign_key: :plate_purpose_id

#racked_tubesRackedTubeResource

Note:

This relationship represents the tubes placed in the rack at specified coordinates.

Returns The tubes that have been placed in the tube rack.

Returns:



123
# File 'app/resources/api/v2/tube_rack_resource.rb', line 123

has_many :racked_tubes

#sizeString

Note:

This attribute is required.

Returns The size of the tube rack (e.g., 48, 96).

Returns:

  • (String)

    The size of the tube rack (e.g., 48, 96).



90
# File 'app/resources/api/v2/tube_rack_resource.rb', line 90

attribute :size

#tube_locationsVoid

Note:

This is a write-only attribute used to map tubes to specific coordinates in the rack.

Returns:

  • (Void)

Raises:

  • (RuntimeError)

    If any of the provided UUIDs do not correspond to a valid tube.

See Also:



97
# File 'app/resources/api/v2/tube_rack_resource.rb', line 97

attribute :tube_locations, writeonly: true

#updated_atString (readonly)

Returns The timestamp when the tube rack was last updated. Readonly.

Returns:

  • (String)

    The timestamp when the tube rack was last updated. Readonly.



101
# File 'app/resources/api/v2/tube_rack_resource.rb', line 101

attribute :updated_at, readonly: true

#uuid(: uuid) ⇒ ActiveRecord::Relation (readonly)

Returns Filtered tube racks that match the provided UUID.

Examples:

GET /api/v2/tube_racks?filter=some-uuid-value

Returns:

  • (ActiveRecord::Relation)

    Filtered tube racks that match the provided UUID.



105
# File 'app/resources/api/v2/tube_rack_resource.rb', line 105

attribute :uuid, readonly: true

Instance Method Details

#barcode(: barcode) ⇒ ActiveRecord::Relation

Returns Filtered tube racks that match the provided barcode.

Examples:

GET /api/v2/tube_racks?filter=1234567890123

Returns:

  • (ActiveRecord::Relation)

    Filtered tube racks that match the provided barcode.



132
# File 'app/resources/api/v2/tube_rack_resource.rb', line 132

filter :barcode, apply: ->(records, value, _options) { records.with_barcode(value) }

#purpose_id(: purpose_id) ⇒ ActiveRecord::Relation

Returns Filtered tube racks that have the specified purpose ID.

Examples:

Returns:

  • (ActiveRecord::Relation)

    Filtered tube racks that have the specified purpose ID.



154
# File 'app/resources/api/v2/tube_rack_resource.rb', line 154

filter :purpose_id, apply: ->(records, value, _options) { records.where(plate_purpose_id: value) }

#purpose_name(: purpose_name) ⇒ ActiveRecord::Relation

Returns Filtered tube racks that have the specified purpose name.

Examples:

Returns:

  • (ActiveRecord::Relation)

    Filtered tube racks that have the specified purpose name.



142
143
144
145
146
147
148
149
# File 'app/resources/api/v2/tube_rack_resource.rb', line 142

filter :purpose_name,
             apply:
(
  lambda do |records, value, _options|
    purpose = Purpose.find_by(name: value)
    records.where(plate_purpose_id: purpose)
  end
)