Class: Tramway::Api::V1::RecordsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/tramway/api/v1/records_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#render_error_with_text, #render_errors_for, #snake_case

Instance Method Details

#create ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/tramway/api/v1/records_controller.rb', line 18

def create
  record_form = form_class.new model_class.new
  if record_form.submit snake_case params[:data][:attributes]
    render json: record_form.model,
           serializer: serializer_class,
           include: '*',
           status: :created
  else
    render_errors_for record_form
  end
end

#destroy ⇒ Object



50
51
52
53
54
55
56
57
# File 'app/controllers/tramway/api/v1/records_controller.rb', line 50

def destroy
  record = model_class.active.find_by uuid: params[:id]
  record.remove
  render json: record,
         serializer: serializer_class,
         include: '*',
         status: :no_content
end

#index ⇒ Object



9
10
11
12
13
14
15
16
# File 'app/controllers/tramway/api/v1/records_controller.rb', line 9

def index
  records = model_class.active.order(id: :desc).send params[:scope] || :all
  records = records.full_text_search params[:search] if params[:search]
  render json: records,
         each_serializer: serializer_class,
         include: '*',
         status: :ok
end

#show ⇒ Object



42
43
44
45
46
47
48
# File 'app/controllers/tramway/api/v1/records_controller.rb', line 42

def show
  record = model_class.active.find_by uuid: params[:id]
  render json: record,
         serializer: serializer_class,
         include: '*',
         status: :ok
end

#update ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/tramway/api/v1/records_controller.rb', line 30

def update
  record_form = form_class.new model_class.active.find_by uuid: params[:id]
  if record_form.submit snake_case params[:data][:attributes]
    render json: record_form.model,
           serializer: serializer_class,
           include: '*',
           status: :ok
  else
    render_errors_for record_form
  end
end