Class: Api::V2::TubePurposeResource

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

Overview

TODO:

The below POST request does not error if purpose_type is anything other than Tube::Purpose, but the object isn't created. See Y25-236.

Note:

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

Provides a JSON:API representation of Tube::Purpose.

A Tube::Purpose is a base class for the all tube purposes, which describes the role the associated Tube is playing within the lab, and modifies its behaviour.

This resource allows for the management and retrieval of tube purposes.

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 for all TubePurpose resources

GET /api/v2/tube_purposes/

GET request for a TubePurpose with ID 123

GET /api/v2/tube_purposes/123/

POST request to create a new TubePurpose

POST /api/v2/tube_purposes/
{
  "data": {
    "type": "tube_purposes",
    "attributes": {
      "name": "9DNA Extraction",
      "purpose_type": "Tube::Purpose",
      "target_type": "StockLibraryTube"
    }
  }
}

PATCH request to update a TubePurpose with ID 123

PATCH /api/v2/tube_purposes/123/
{
  "data": {
    "id": 123,
    "type": "tube_purposes",
    "attributes": {
      "name": "DNA Extraction 123",
      "purpose_type": "Tube::Purpose",
      "target_type": "StockLibraryTube"
    }
  }
}

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

#nameString

Note:

This attribute is required.

Returns The name of the tube purpose, describing the intended use of the tube.

Returns:

  • (String)

    The name of the tube purpose, describing the intended use of the tube.



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/resources/api/v2/tube_purpose_resource.rb', line 64

 do
  # NOTE: The following attribute is not required for Microarray Genotyping.
  # I think this might be broken and suggests that there should be separate classes for project: one for
  # next-gen sequencing that includes this attribute in it's metadata, and one for microarray genotyping
  # that doesn't.
  include ProjectManager::Associations
  include BudgetDivision::Associations

  custom_attribute(:project_cost_code, required: true)
  custom_attribute(:funding_comments)
  custom_attribute(:collaborators)
  custom_attribute(:external_funding_source)
  custom_attribute(:sequencing_budget_cost_centre)
  custom_attribute(:project_funding_model, in: PROJECT_FUNDING_MODELS)
  custom_attribute(:gt_committee_tracking_id)

  before_validation do |record|
    record.project_cost_code = nil if record.project_cost_code.blank?
    record.project_funding_model = nil if record.project_funding_model.blank?
  end
end

#purpose_typeString

This is mapped to the type attribute on the model.

Returns:

  • (String)

    The purpose type (e.g., "Tube::Purpose").



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/resources/api/v2/tube_purpose_resource.rb', line 69

 do
  # NOTE: The following attribute is not required for Microarray Genotyping.
  # I think this might be broken and suggests that there should be separate classes for project: one for
  # next-gen sequencing that includes this attribute in it's metadata, and one for microarray genotyping
  # that doesn't.
  include ProjectManager::Associations
  include BudgetDivision::Associations

  custom_attribute(:project_cost_code, required: true)
  custom_attribute(:funding_comments)
  custom_attribute(:collaborators)
  custom_attribute(:external_funding_source)
  custom_attribute(:sequencing_budget_cost_centre)
  custom_attribute(:project_funding_model, in: PROJECT_FUNDING_MODELS)
  custom_attribute(:gt_committee_tracking_id)

  before_validation do |record|
    record.project_cost_code = nil if record.project_cost_code.blank?
    record.project_funding_model = nil if record.project_funding_model.blank?
  end
end

#target_typeString

Note:

This attribute is required.

Returns The target type, indicating what type of tube the purpose is associated with (e.g., 'StockLibraryTube').

Returns:

  • (String)

    The target type, indicating what type of tube the purpose is associated with (e.g., 'StockLibraryTube').



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'app/resources/api/v2/tube_purpose_resource.rb', line 75

 do
  # NOTE: The following attribute is not required for Microarray Genotyping.
  # I think this might be broken and suggests that there should be separate classes for project: one for
  # next-gen sequencing that includes this attribute in it's metadata, and one for microarray genotyping
  # that doesn't.
  include ProjectManager::Associations
  include BudgetDivision::Associations

  custom_attribute(:project_cost_code, required: true)
  custom_attribute(:funding_comments)
  custom_attribute(:collaborators)
  custom_attribute(:external_funding_source)
  custom_attribute(:sequencing_budget_cost_centre)
  custom_attribute(:project_funding_model, in: PROJECT_FUNDING_MODELS)
  custom_attribute(:gt_committee_tracking_id)

  before_validation do |record|
    record.project_cost_code = nil if record.project_cost_code.blank?
    record.project_funding_model = nil if record.project_funding_model.blank?
  end
end

#uuidString (readonly)

Note:

This identifier is automatically assigned upon creation and cannot be modified.

Returns The UUID of the tube purpose.

Returns:

  • (String)

    The UUID of the tube purpose.



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'app/resources/api/v2/tube_purpose_resource.rb', line 80

 do
  # NOTE: The following attribute is not required for Microarray Genotyping.
  # I think this might be broken and suggests that there should be separate classes for project: one for
  # next-gen sequencing that includes this attribute in it's metadata, and one for microarray genotyping
  # that doesn't.
  include ProjectManager::Associations
  include BudgetDivision::Associations

  custom_attribute(:project_cost_code, required: true)
  custom_attribute(:funding_comments)
  custom_attribute(:collaborators)
  custom_attribute(:external_funding_source)
  custom_attribute(:sequencing_budget_cost_centre)
  custom_attribute(:project_funding_model, in: PROJECT_FUNDING_MODELS)
  custom_attribute(:gt_committee_tracking_id)

  before_validation do |record|
    record.project_cost_code = nil if record.project_cost_code.blank?
    record.project_funding_model = nil if record.project_funding_model.blank?
  end
end

Instance Method Details

#filter_typeObject

Filter tube purposes by type.

Examples:

GET request with type filter

GET /api/v2/tube_purposes?filter[type]=Extraction


90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'app/resources/api/v2/tube_purpose_resource.rb', line 90

 do
  # NOTE: The following attribute is not required for Microarray Genotyping.
  # I think this might be broken and suggests that there should be separate classes for project: one for
  # next-gen sequencing that includes this attribute in it's metadata, and one for microarray genotyping
  # that doesn't.
  include ProjectManager::Associations
  include BudgetDivision::Associations

  custom_attribute(:project_cost_code, required: true)
  custom_attribute(:funding_comments)
  custom_attribute(:collaborators)
  custom_attribute(:external_funding_source)
  custom_attribute(:sequencing_budget_cost_centre)
  custom_attribute(:project_funding_model, in: PROJECT_FUNDING_MODELS)
  custom_attribute(:gt_committee_tracking_id)

  before_validation do |record|
    record.project_cost_code = nil if record.project_cost_code.blank?
    record.project_funding_model = nil if record.project_funding_model.blank?
  end
end