Class: Doodle::KeywordsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#auth_params, #authenticate, #authenticate_user

Instance Method Details

#actionObject



28
29
30
31
32
33
34
35
# File 'app/controllers/doodle/keywords_controller.rb', line 28

def action
 @keyword = Doodle::Keyword::Action::FinderService.new(name: params.require(:name)).call.first
 if @keyword
   render json: Doodle::KeywordsHelper.stub_action(@keyword)
 else
   render json: {error: 'Missing Action Keyword'}, status: 404
 end
end

#all_actionsObject



24
25
26
# File 'app/controllers/doodle/keywords_controller.rb', line 24

def all_actions
  render json: Doodle::Keyword::Action.all
end

#createObject



7
8
9
10
11
12
13
14
# File 'app/controllers/doodle/keywords_controller.rb', line 7

def create
  keyword = Keyword.new(keyword_params)
  if keyword.save
    render json: keyword.reload.to_json
  else
    render json: {error: 'When save keyword'}.to_json
  end
end

#finder_serviceObject



41
42
43
# File 'app/controllers/doodle/keywords_controller.rb', line 41

def finder_service
  @finder_service || Doodle::Keyword::Text::FinderService.new(keyword_params)
end

#indexObject



16
17
18
19
20
21
22
# File 'app/controllers/doodle/keywords_controller.rb', line 16

def index
  if params[:keyword].present?
    render json: finder_service.to_json
  else
    render json: Keyword::Text.all.to_json
  end
end

#keyword_paramsObject



37
38
39
# File 'app/controllers/doodle/keywords_controller.rb', line 37

def keyword_params
  params.require(:keyword).permit(:name, :value, :type)
end