Class: QueriesController
Constant Summary
ApplicationController::ALLOWABLE_CONFIGS
Instance Method Summary
collapse
Instance Method Details
#create ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'app/controllers/queries_controller.rb', line 25
def create
respond_to do |format|
format.json do
interaction = Interaction::QueryCreation.new(params[:query].merge(user: current_user))
@query = interaction.execute
if interaction.errors.any?
render json: { success: false, errors: interaction.errors }, status: :unprocessable_entity
else
render json: @query, status: :created
end
end
end
end
|
#destroy ⇒ Object
55
56
57
58
59
60
61
62
|
# File 'app/controllers/queries_controller.rb', line 55
def destroy
respond_to do |format|
format.json do
@query.destroy!
render json: @query
end
end
end
|
#index ⇒ Object
8
9
10
11
12
13
14
15
16
|
# File 'app/controllers/queries_controller.rb', line 8
def index
respond_to do |format|
format.html
format.json do
@paginated_queries = Query.paginated(@queries, )
render json: @paginated_queries, each_serializer: QueryIndexSerializer
end
end
end
|
#show ⇒ Object
18
19
20
21
22
23
|
# File 'app/controllers/queries_controller.rb', line 18
def show
respond_to do |format|
format.html { render :index }
format.json { render json: @query }
end
end
|
#update ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'app/controllers/queries_controller.rb', line 40
def update
respond_to do |format|
format.json do
interaction = Interaction::QueryUpdate.new(@query, params[:query].merge(user: current_user))
updated_query = interaction.execute
if interaction.errors.any?
render json: { success: false, errors: interaction.errors }, status: :unprocessable_entity
else
render json: updated_query, status: :ok
end
end
end
end
|