Class: Api::V3::ApplicationController
- Inherits:
-
Api::V2::ApplicationController
- Object
- Api::V2::ApplicationController
- Api::V3::ApplicationController
show all
- Includes:
- Pagy::Backend
- Defined in:
- app/controllers/api/v3/application_controller.rb
Instance Method Summary
collapse
Instance Method Details
#create ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
|
# File 'app/controllers/api/v3/application_controller.rb', line 30
def create
authorize! :create, @model
status, result, status_number = check_for_custom_action
return render json: result, status: (status_number.presence || 200) if status == true
record = @model.new(jsonapi_attributes)
record.save!
serializer = Api::V3::SerializerFactory.serializer_for(@model)
render json: serializer.new(record, **serializer_opts).serializable_hash, status: :created
end
|
#destroy ⇒ Object
55
56
57
58
59
60
61
62
63
|
# File 'app/controllers/api/v3/application_controller.rb', line 55
def destroy
authorize! :destroy, @record
status, result, status_number = check_for_custom_action
return render json: result, status: (status_number.presence || 200) if status == true
@record.destroy!
head :no_content
end
|
#index ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'app/controllers/api/v3/application_controller.rb', line 4
def index
authorize! :index, @model
status, result, status_number = check_for_custom_action
return render json: result, status: (status_number.presence || 200) if status == true
scope = apply_filters(@model.all)
scope = apply_sorting(scope)
pagy, records = pagy(scope, page: page_number, limit: page_size)
serializer = Api::V3::SerializerFactory.serializer_for(@model)
render json: serializer.new(records, **serializer_opts).serializable_hash.merge(meta: { total: pagy.count }),
status: :ok
end
|
#show ⇒ Object
20
21
22
23
24
25
26
27
28
|
# File 'app/controllers/api/v3/application_controller.rb', line 20
def show
authorize! :show, @record
status, result, status_number = check_for_custom_action
return render json: result, status: (status_number.presence || 200) if status == true
serializer = Api::V3::SerializerFactory.serializer_for(@model)
render json: serializer.new(@record, **serializer_opts).serializable_hash, status: :ok
end
|
#update ⇒ Object
Also known as:
patch
42
43
44
45
46
47
48
49
50
51
|
# File 'app/controllers/api/v3/application_controller.rb', line 42
def update
authorize! :update, @record
status, result, status_number = check_for_custom_action
return render json: result, status: (status_number.presence || 200) if status == true
@record.update!(jsonapi_attributes)
serializer = Api::V3::SerializerFactory.serializer_for(@model)
render json: serializer.new(@record, **serializer_opts).serializable_hash, status: :ok
end
|