Class: Api::V2::QcFileResource

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

Overview

Note:

This resource cannot be modified after creation: its endpoint will not accept PATCH requests.

Note:

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

Provides a JSON:API representation of QcFile which contains the QC data previously added to a piece of Labware. The file contents are stored in the database using the DbFile model.

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:

POST request

POST /api/v2/qc_files/
{
  "data": {
    "type": "qc_files",
    "attributes": {
      "filename": "qc_file.csv",
      "contents": "A1,A2,A3\n1,2,3\n4,5,6\n"
    },
    "relationships": {
      "asset": {
        "data": {
          "type": "labware",
          "id": "123"
        }
      }
    }
  }
}

GET request for all QcFile resources

GET /api/v2/qc_files/

GET request for a QcFile with ID 123

GET /api/v2/qc_files/123/

GET request for all QcFile resources associated with a Plate with ID 123

GET /api/v2/plates/123/qc_files/

Instance Attribute Summary collapse

Class Method 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

#content_typeString (readonly)

Returns The content type, or MIME type, of the QC file.

Returns:

  • (String)

    The content type, or MIME type, of the QC file.



50
# File 'app/resources/api/v2/qc_file_resource.rb', line 50

attribute :content_type, readonly: true

#contentsString

Returns The String contents of the QC file. This is usually the CSV data for the QC file. This can only be written once on creation.

Returns:

  • (String)

    The String contents of the QC file. This is usually the CSV data for the QC file. This can only be written once on creation.



56
# File 'app/resources/api/v2/qc_file_resource.rb', line 56

attribute :contents, write_once: true

#created_atDateTime (readonly)

Returns The date and time the QC file was created.

Returns:

  • (DateTime)

    The date and time the QC file was created.



70
# File 'app/resources/api/v2/qc_file_resource.rb', line 70

attribute :created_at, readonly: true

#filenameString

Returns The filename of the QC file. This can only be written once on creation.

Returns:

  • (String)

    The filename of the QC file. This can only be written once on creation.



75
# File 'app/resources/api/v2/qc_file_resource.rb', line 75

attribute :filename, write_once: true

#labwareLabwareResource

Returns The Labware which this QcFile belongs to.

Returns:



96
# File 'app/resources/api/v2/qc_file_resource.rb', line 96

has_one :labware, relation_name: :asset, foreign_key: :asset_id, write_once: true

#sizeInteger (readonly)

Returns The size of the QC file in bytes.

Returns:

  • (Integer)

    The size of the QC file in bytes.



84
# File 'app/resources/api/v2/qc_file_resource.rb', line 84

attribute :size, readonly: true

#uuidString (readonly)

Returns The UUID of the bulk transfers operation.

Returns:

  • (String)

    The UUID of the bulk transfers operation.



88
# File 'app/resources/api/v2/qc_file_resource.rb', line 88

attribute :uuid, readonly: true

Class Method Details

.create_with_tempfile(context, tempfile, filename) ⇒ QcFileResource

Returns The new QcFile resource.

Parameters:

  • context (Hash)

    The context for the request.

  • tempfile (Tempfile)

    A temporary file containing the uploaded data.

  • filename (String)

    The filename for the uploaded data.

Returns:



120
121
122
123
# File 'app/resources/api/v2/qc_file_resource.rb', line 120

def self.create_with_tempfile(context, tempfile, filename)
  opts = { uploaded_data: { tempfile:, filename: } }
  new(QcFile.new(opts), context)
end

Instance Method Details

#create_with_tempfileObject

Create a new QcFile resource with the uploaded data from a temporary file. This is called by the controller when a create request for a QcFile is made. It ensures the contents of the file have been written to a new TempFile instance.



120
121
122
123
# File 'app/resources/api/v2/qc_file_resource.rb', line 120

def self.create_with_tempfile(context, tempfile, filename)
  opts = { uploaded_data: { tempfile:, filename: } }
  new(QcFile.new(opts), context)
end

#filter_uuidObject

Filter the QcFile resources by UUID.

Examples:

GET request with UUID filter

GET /api/v2/qc_files?filter[uuid]=12345678-1234-1234-1234-123456789012


106
# File 'app/resources/api/v2/qc_file_resource.rb', line 106

filter :uuid, apply: ->(records, value, _options) { records.with_uuid(value) }