Class: Api::Vendor::V1::PackageTypesController

Inherits:
BaseController
  • Object
show all
Includes:
Concerns::Authentication
Defined in:
app/controllers/api/vendor/v1/package_types_controller.rb

Constant Summary

Constants inherited from BaseController

BaseController::CACHE_NAMESPACE

Instance Attribute Summary

Attributes inherited from BaseController

#vendor

Instance Method Summary collapse

Methods included from LogrageCustomLogger

#append_info_to_payload

Methods included from ResponseCacheConcern

#my_response_cache

Instance Method Details

#indexObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/api/vendor/v1/package_types_controller.rb', line 5

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

  my_response_cache cache_key, :json, public: true do
    package_types = PackageType.where(active: true)

    package_types = package_types.joins(:cities).where(cities: { id: city_id }).group(:id) if city_id.present?
    package_types = _filter_packages_by_type(package_types, package_type) if package_type.present?

    serialized_package_types = Api::Vendor::V1::PackageTypeSerializer.new(package_types)
    serialized_package_types.serializable_hash.merge(success: true, message: nil).as_json
  end
end