Class: QueriesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/queries_controller.rb

Constant Summary

Constants inherited from ApplicationController

ApplicationController::ALLOWABLE_CONFIGS

Instance Method Summary collapse

Instance Method Details

#createObject



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

#destroyObject



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

#indexObject



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, query_pagination_params)
      render json: @paginated_queries, each_serializer: QueryIndexSerializer
    end
  end
end

#showObject



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

#updateObject



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