Class: Core::Endpoint::Base Abstract

Inherits:
Object
  • Object
show all
Extended by:
InstanceBehaviour, ModelBehaviour
Defined in:
app/api/core/endpoint/base.rb

Overview

This class is abstract.

Define new endpoints by specifying ModelBehaviour#model and InstanceBehaviour#instance actions

Core class for API V1 endpoints, which effectively acts as a controller layer. New endpoints should be placed in app/api/endpoints/ and should inherit from Core::Endpoint::Base. All endpoints are in the Endpoints namespace.

model defines actions on the collection, in the asset audit example a create action on api/1/asset_audits

instance defines actions on individual instances, usually accessed via their uuid. In this case each asset audit has an asset action which returns the associated asset. ie. api/1/000000-0000-0000-0000-000000000000/asset

There is no need to modify the routes when adding endpoints.

It is not necessary to define index or show endpoints, these are defined by default.

Examples:

Asset Audit

class ::Endpoints::AssetAudits < ::Core::Endpoint::Base
 model do
   action(:create) do |request, _response|
     request.create!
   end
 end

 instance do
   belongs_to(:asset, json: 'asset')
 end
end

See Also:

Direct Known Subclasses

Endpoints::AssetAudits, Endpoints::AssetGroups, Endpoints::Assets, Endpoints::BaitLibraryLayouts, Endpoints::BarcodePrinters, Endpoints::Batches, Endpoints::BulkTransfers, Endpoints::Comments, Endpoints::CustomMetadatumCollections, Endpoints::ExtractionAttributes, Endpoints::Lanes, Endpoints::LibraryEvents, Endpoints::LotTypes, Endpoints::Lots, Endpoints::OrderTemplates, Endpoints::Orders, Endpoints::Pipelines, Endpoints::PlateConversions, Endpoints::PlateCreations, Endpoints::PlatePurposes, Endpoints::PlateTemplates, Endpoints::Plates, Endpoints::PooledPlateCreations, Endpoints::Projects, Endpoints::QcDecisions, Endpoints::QcFiles, Endpoints::QcableCreators, Endpoints::Qcables, Endpoints::ReferenceGenomes, Endpoints::RequestTypes, Endpoints::Requests, Endpoints::Robots, Endpoints::SampleManifests, Endpoints::Samples, Endpoints::Searches, Endpoints::SpecificTubeCreations, Endpoints::Stamps, Endpoints::StateChanges, Endpoints::Studies, Endpoints::SubmissionPools, Endpoints::Submissions, Endpoints::Suppliers, Endpoints::Tag2LayoutTemplates, Endpoints::Tag2Layouts, Endpoints::TagGroups, Endpoints::TagLayoutTemplates, Endpoints::TagLayouts, Endpoints::TransferRequestCollections, Endpoints::TransferRequests, Endpoints::TransferTemplates, Endpoints::Transfers, Endpoints::Tube::Purposes, Endpoints::TubeCreations, Endpoints::TubeFromTubeCreations, Endpoints::Tubes, Endpoints::Users, Endpoints::Uuids, Endpoints::VolumeUpdates, Endpoints::Wells, Endpoints::WorkCompletions

Defined Under Namespace

Modules: InstanceBehaviour, ModelBehaviour

Class Method Summary collapse

Methods included from InstanceBehaviour

extended, instance

Methods included from ModelBehaviour

extended, model

Class Method Details

.rootObject



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'app/api/core/endpoint/base.rb', line 109

 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