Class: SearchController

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

Overview

this is the search endpoint calls the Search class to handle reqest

Author:

Instance Attribute Summary

Attributes inherited from ApplicationController

#current_user

Instance Method Summary (collapse)

Instance Method Details

- (Object) index



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/controllers/search_controller.rb', line 4

def index
  if params.has_key?(:name) && params.has_key?(:id)
    render json: { errors: ['query can not contain both id and name param'] }, status: :bad_request
  elsif params.has_key?(:name)
    @response = Search.relations_by_name(params[:name].downcase)
    render :json => @response.to_json
  elsif params.has_key?(:id)
    @response = Search.relations_by_id(params[:id])
    render :json => @response.to_json
  else
    render json: { errors: ['must use name or id param'] }, status: :bad_request
  end
end