Class: Api::V2::QcResultsController

Inherits:
JSONAPI::ResourceController
  • Object
show all
Defined in:
app/controllers/api/v2/qc_results_controller.rb

Overview

QcResultsController create needs some specific code as it is not standard JSON API behaviour

Instance Method Summary collapse

Instance Method Details

#createObject


8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/api/v2/qc_results_controller.rb', line 8

def create
  @qc_result_factory = QcResultFactory.new(qc_results_params)
  if @qc_result_factory.valid?
    @qc_result_factory.save
    @qc_result_resources = @qc_result_factory.qc_results.map { |qc_result| QcResultResource.new(qc_result, nil) }
    render json: JSONAPI::ResourceSerializer.new(QcResultResource).serialize_to_hash(@qc_result_resources),
           status: :created
  else
    render json: @qc_result_factory.errors, status: :unprocessable_entity
  end
end

#qc_results_paramsObject


20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/api/v2/qc_results_controller.rb', line 20

def qc_results_params
  params
    .require(:data)
    .require(:attributes)
    .map do |p|
      ActionController::Parameters
        .new(p.to_unsafe_h)
        .permit(:barcode, :uuid, :well_location, :key, :value, :units, :cv, :assay_type, :assay_version)
    end
end