Class: ForestLiana::ResourcesController
Instance Method Summary
collapse
#authenticate_user_from_jwt, #forest_user, #serialize_model, #serialize_models
Instance Method Details
#create ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'app/controllers/forest_liana/resources_controller.rb', line 32
def create
creator = ResourceCreator.new(@resource, params)
creator.perform
if creator.errors
render serializer: nil, json: JSONAPI::Serializer.serialize_errors(
creator.errors), status: 400
elsif creator.record.valid?
render serializer: nil,
json: serialize_model(creator.record, include: record_includes)
else
render serializer: nil, json: JSONAPI::Serializer.serialize_errors(
creator.record.errors), status: 400
end
end
|
#destroy ⇒ Object
64
65
66
67
68
|
# File 'app/controllers/forest_liana/resources_controller.rb', line 64
def destroy
@resource.destroy_all(id: params[:id])
head :no_content
end
|
#index ⇒ Object
14
15
16
17
18
19
20
21
22
|
# File 'app/controllers/forest_liana/resources_controller.rb', line 14
def index
getter = ResourcesGetter.new(@resource, params)
getter.perform
render serializer: nil, json: serialize_models(getter.records,
include: includes(getter),
count: getter.count,
params: params)
end
|
#show ⇒ Object
24
25
26
27
28
29
30
|
# File 'app/controllers/forest_liana/resources_controller.rb', line 24
def show
getter = ResourceGetter.new(@resource, params)
getter.perform
render serializer: nil, json:
serialize_model(getter.record, include: includes(getter))
end
|
#update ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'app/controllers/forest_liana/resources_controller.rb', line 48
def update
updater = ResourceUpdater.new(@resource, params)
updater.perform
if updater.errors
render serializer: nil, json: JSONAPI::Serializer.serialize_errors(
updater.errors), status: 400
elsif updater.record.valid?
render serializer: nil,
json: serialize_model(updater.record, include: record_includes)
else
render serializer: nil, json: JSONAPI::Serializer.serialize_errors(
updater.record.errors), status: 400
end
end
|