Class: Workarea::Api::Storefront::SearchesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/workarea/api/storefront/searches_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#cache_page, #skip_session

Methods included from UserActivity

#assert_current_user_activity_id, #current_user_activity_id, #user_activity

Methods included from Authentication

#authentication?, #current_user

Instance Method Details

#indexObject



7
8
9
10
11
12
13
14
15
16
17
# File 'app/controllers/workarea/api/storefront/searches_controller.rb', line 7

def index
  search_query = QueryString.new(params[:q]).sanitized

  render(nothing: true) && (return) if search_query.blank?
  autocomplete_params = params.permit(:q)
  search = Search::SearchSuggestions.new(autocomplete_params)

  @results = search.results.map do |result|
    SearchSuggestionViewModel.new(result).to_h
  end
end

#showObject



19
20
21
22
23
24
25
# File 'app/controllers/workarea/api/storefront/searches_controller.rb', line 19

def show
  response = Search::StorefrontSearch.new(params.to_unsafe_h).response
  @search = Workarea::Storefront::SearchViewModel.new(
    response,
    view_model_options
  )
end