Class: Api::V5::PackageTypesController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/api/v5/package_types_controller.rb

Overview

package types

Constant Summary

Constants inherited from BaseController

BaseController::CACHE_NAMESPACE, BaseController::INTERNAL_SERVER_ERROR_MESSAGE, BaseController::ResponseSchema

Instance Method Summary collapse

Methods inherited from BaseController

#identity_cache_memoization

Methods included from LogrageCustomLogger

#append_info_to_payload

Methods included from ResponseCacheConcern

#my_response_cache

Instance Method Details

#indexObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/api/v5/package_types_controller.rb', line 8

def index
  city_id = params[:city_id]
  cache_key = "#{CACHE_NAMESPACE}:#{self.class}:index:#{PackageType.maximum(:updated_at)}:#{city_id}:#{MyLocaleManager.normalize_locale}"

  my_response_cache cache_key, :json, public: true do
    package_types = PackageType.where(active: true)
    if city_id.present?
      package_types = package_types.joins(:cities).where(cities: { id: city_id }).group(:id)
      package_types = package_types.to_a << add_on_type
    end
    ActiveModelSerializers::SerializableResource.new(
      package_types,
      {
        each_serializer: Api::V5::PackageTypeSerializer,
        adapter: :json_api,
      },
    ).serializable_hash.merge(success: true, message: nil).as_json
  end
end