Class: HomeRestaurantSection

Inherits:
GroupLandingPage show all
Defined in:
app/models/home_restaurant_section.rb

Overview

typed: ignore

Schema Information

Table name: group_landing_pages

id                    :bigint           not null, primary key
budget_max_cents      :integer          default(0), not null
budget_max_currency   :string(191)      default("THB"), not null
budget_min_cents      :integer          default(0), not null
budget_min_currency   :string(191)      default("THB"), not null
default_sort          :string(191)
description           :text(65535)
footer_description    :text(65535)
group_single_type     :string(191)
group_type            :string(191)
icon                  :string(191)
section_image         :string(191)
section_template      :string(191)
section_type          :string(191)
slug                  :string(191)
sort_type             :string(191)
tag_line              :text(65535)
title                 :text(65535)
created_at            :datetime         not null
updated_at            :datetime         not null
group_id              :bigint
group_landing_page_id :bigint           not null
home_section_id       :bigint

Indexes

index_group_landing_pages_on_group_type_and_group_id  (group_type,group_id)
index_group_landing_pages_on_home_section_id          (home_section_id)
index_group_landing_pages_on_slug                     (slug) UNIQUE

Constant Summary collapse

SECTION_ROUTE =

example: route section_3: -> target :section_11 see config/locales/home.en.yml to see target section name

{
  # 1st, CompactRestaurant
  section_3: :section_11,

  # 2nd, CompactRestaurant
  section_1: :section_12,

  # 3rd, special section, don't change this!
  # restaurant card, not compact
  section_14: :section_14,

  # 4rd popular brand, Branch
  section_5: :section_5,

  # top categories location
  # 5th, Restaurant Tag
  section_4: :section_4,

  # top categories cuisine
  # 6th, Restaurant Tag
  section_7: :section_7,

  # 7th, CompactRestaurant
  section_8: :section_3,

  # 8th, CompactRestaurant
  section_6: :section_6,

  # 9th, CompactRestaurant
  section_9: :section_1,

  # 10th CompactRestaurant
  section_11: :section_8,

  # 11th CompactRestaurant (all restaurants)
  section_13: :section_13,

  # 12th NOT USED by app
  section_12: :section_13,

  # 10th
  section_10: :section_10,
}.freeze
COMPACT_RESTAURANT_SECTIONS =
%i[
  section_1
  section_3
  section_5
  section_6
  section_8
  section_11
  section_12
  section_13
].freeze
SECTION_TYPE =
%i[
  section_1
  section_3
  section_5
  section_4
  section_6
  section_7
  section_8
  section_10
  section_11
  section_12
  section_13
  section_banner
  hh_specials
].freeze

Constants inherited from GroupLandingPage

GroupLandingPage::GROUP_TYPES, GroupLandingPage::GROUP_TYPE_BRANCH, GroupLandingPage::GROUP_TYPE_RESTAURANT_TAG, GroupLandingPage::GROUP_TYPE_RESTAURANT_TAG_GROUP, GroupLandingPage::SORT_TYPES, GroupLandingPage::SORT_TYPE_HUMANIZES

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ModelExt::GroupLandingPages::FriendlyIdSetup

#slug_candidates

Methods included from ModelExt::GroupLandingPages::Validations

#validate_budget

Methods included from ModelExt::GroupLandingPages::InstanceMethods

#has_no_content?

Methods inherited from ApplicationRecord

sync_carrierwave_url

Class Method Details

.restaurant_section_typesObject



124
125
126
127
128
# File 'app/models/home_restaurant_section.rb', line 124

def self.restaurant_section_types
  SECTION_TYPE.index_by do |location|
    I18n.t("home_screen.#{location}")
  end
end

Instance Method Details

#compact_restaurantsObject



130
131
132
# File 'app/models/home_restaurant_section.rb', line 130

def compact_restaurants
  CompactRestaurant.where(active: true).where("rank_#{section_type} IS NOT NULL")
end

#update_compact_restaurants_rank(params) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'app/models/home_restaurant_section.rb', line 134

def update_compact_restaurants_rank(params)
  return true if params.blank?

  compact_restaurants.update_all("rank_#{section_type}": nil)

  Array.wrap(params).map(&:to_h).each do |h|
    next if h[:id].blank? || h[:rank].blank?

    cr = CompactRestaurant.find(h[:id])
    cr.send("rank_#{section_type}=".to_sym, h[:rank].to_i)
    cr.save
  end

  Tagging::UpdateSpecialSectionWorker.perform_async if section_type == 'section_12'
end