Class: CompletionKit::Api::V1::RunsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/completion_kit/api/v1/runs_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



15
16
17
18
19
20
21
22
23
# File 'app/controllers/completion_kit/api/v1/runs_controller.rb', line 15

def create
  run = Run.new(run_params.except(:metric_ids))
  if run.save
    replace_run_metrics(run, params[:metric_ids])
    render json: run.reload, status: :created
  else
    render json: {errors: run.errors}, status: :unprocessable_entity
  end
end

#destroyObject



34
35
36
37
# File 'app/controllers/completion_kit/api/v1/runs_controller.rb', line 34

def destroy
  @run.destroy!
  head :no_content
end

#generateObject



39
40
41
42
# File 'app/controllers/completion_kit/api/v1/runs_controller.rb', line 39

def generate
  GenerateJob.perform_later(@run.id)
  render json: @run.reload, status: :accepted
end

#indexObject



7
8
9
# File 'app/controllers/completion_kit/api/v1/runs_controller.rb', line 7

def index
  render json: Run.order(created_at: :desc)
end

#judgeObject



44
45
46
47
# File 'app/controllers/completion_kit/api/v1/runs_controller.rb', line 44

def judge
  JudgeJob.perform_later(@run.id)
  render json: @run.reload, status: :accepted
end

#showObject



11
12
13
# File 'app/controllers/completion_kit/api/v1/runs_controller.rb', line 11

def show
  render json: @run
end

#updateObject



25
26
27
28
29
30
31
32
# File 'app/controllers/completion_kit/api/v1/runs_controller.rb', line 25

def update
  if @run.update(run_params.except(:metric_ids))
    replace_run_metrics(@run, params[:metric_ids]) if params.key?(:metric_ids)
    render json: @run.reload
  else
    render json: {errors: @run.errors}, status: :unprocessable_entity
  end
end