Class: Katello::Api::V2::HostDebsController

Inherits:
ApiController
  • Object
show all
Includes:
Concerns::Api::V2::RepositoryContentController, Concerns::FilteredAutoCompleteSearch
Defined in:
app/controllers/katello/api/v2/host_debs_controller.rb

Constant Summary

Constants included from Concerns::FilteredAutoCompleteSearch

Concerns::FilteredAutoCompleteSearch::PAGE_SIZE

Instance Method Summary collapse

Methods included from Concerns::FilteredAutoCompleteSearch

#auto_complete_search

Methods inherited from ApiController

#empty_search_query?, #full_result_response, #scoped_search, #skip_session

Methods included from Rendering

#respond_for_async, #respond_for_bulk_async, #respond_for_create, #respond_for_destroy, #respond_for_index, #respond_for_show, #respond_for_status, #respond_for_update, #respond_with_template, #respond_with_template_collection, #respond_with_template_resource, #try_specific_collection_template, #try_specific_resource_template

Methods included from Katello::Api::Version2

#api_version

Instance Method Details

#indexObject



33
34
35
36
37
# File 'app/controllers/katello/api/v2/host_debs_controller.rb', line 33

def index
  collection = scoped_search(index_relation, :name, :asc, :resource_class => ::Katello::InstalledDeb)
  collection[:results] = HostDebPresenter.with_latest(collection[:results], @host) if ::Foreman::Cast.to_bool(params[:include_latest_upgradable])
  respond_for_index(:collection => collection)
end

#index_relationObject



39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/katello/api/v2/host_debs_controller.rb', line 39

def index_relation
  packages = @host.installed_debs
  upgradable_packages = ::Katello::Deb.installable_for_hosts([@host]).select(:name)
  if params[:status].present?
    packages = case params[:status]
               when 'up-to-date' then packages.where.not(name: upgradable_packages)
               when 'upgradable' then packages.where(name: upgradable_packages)
               end
  end
  packages
end

#installed_debsObject



15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/katello/api/v2/host_debs_controller.rb', line 15

def installed_debs
  _sort_by, _sort_order, options = sort_options
  sort_by = 'name'
  sort_order = 'asc'

  options[:select] = "DISTINCT ON (#{::Katello::InstalledDeb.table_name}.name) #{::Katello::InstalledDeb.table_name}.id, #{::Katello::InstalledDeb.table_name}.name"
  final_relation = ::Katello::InstalledDeb.all

  result = scoped_search(final_relation, sort_by, sort_order, options)
  respond_for_index(:collection => result, :template => "installed_debs")
end

#resource_classObject



51
52
53
# File 'app/controllers/katello/api/v2/host_debs_controller.rb', line 51

def resource_class
  Katello::InstalledDeb
end