Class: Partners::ReservationSummary
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Partners::ReservationSummary
- Defined in:
- app/models/partners/reservation_summary.rb
Overview
Streamlined summary table for Partner API reservations performance optimization. Stores exact values from serializer logic for fast querying and filtering.
Key principles:
-
No validation callbacks or complex business logic
-
No pre-computed formatted fields (use runtime formatting)
-
Stores exact values that match serializer output
-
Optimized for filtering and querying only
-
Tracks sync freshness via last_synced_at for monitoring and debugging
Instance Attribute Summary collapse
-
#active ⇒ Boolean
Whether reservation is active (not cancelled/deleted).
-
#adjusted ⇒ Boolean
Whether reservation was modified after creation.
-
#adult ⇒ Integer
Number of adult guests.
-
#created_at ⇒ DateTime
Record creation timestamp.
-
#customer_email ⇒ String
Customer email for search functionality.
-
#customer_name ⇒ String
Customer name for search functionality.
-
#customer_phone ⇒ String
Customer phone for search functionality.
-
#date ⇒ Date
Reservation date for filtering and grouping.
-
#end_time ⇒ Time
Reservation end time.
-
#for_locking_system ⇒ Boolean
Whether reservation is for table locking system.
-
#is_temporary ⇒ Boolean
Whether reservation is temporary (pending confirmation).
-
#kids ⇒ Integer
Number of child guests.
-
#last_synced_at ⇒ DateTime?
Timestamp of last sync for monitoring data freshness.
-
#party_size ⇒ Integer
Total number of guests (adult + kids).
-
#payment_status ⇒ String
Payment status for filtering.
-
#reservation_id ⇒ Integer
Original reservation ID (primary reference).
-
#reservation_status ⇒ String
Current reservation status.
-
#restaurant_id ⇒ Integer
Restaurant ID for filtering and associations.
-
#service_type ⇒ String
Service type ('dine_in', 'delivery', etc.).
-
#start_time ⇒ Time
Reservation start time.
-
#updated_at ⇒ DateTime
Record last update timestamp.
-
#user_id ⇒ Integer?
User ID (optional for guest bookings).
Class Method Summary collapse
-
.adjusted? ⇒ Boolean
Check if reservation was adjusted (modified).
-
.by_date(date) ⇒ ActiveRecord::Relation<Partners::ReservationSummary>
Filter summaries by specific date.
-
.by_package_type(type) ⇒ ActiveRecord::Relation<Partners::ReservationSummary>
Filter summaries by package type through associated packages.
-
.by_party_size(party_size) ⇒ ActiveRecord::Relation<Partners::ReservationSummary>
Filter summaries by party size.
-
.by_restaurant(restaurant_id) ⇒ ActiveRecord::Relation<Partners::ReservationSummary>
Filter summaries by restaurant.
-
.by_service_type(service_type) ⇒ ActiveRecord::Relation<Partners::ReservationSummary>
Filter summaries by service type.
-
.delivery? ⇒ Boolean
Check if reservation is for delivery service.
-
.dine_in? ⇒ Boolean
Check if reservation is for dine-in service.
-
.future? ⇒ Boolean
Helper method to check if reservation is in the future.
-
.past? ⇒ Boolean
Time-dependent method that cannot be stored in database This replaces the need to store is_past_reservation field.
-
.reservation_time ⇒ Time
Calculate reservation time using exact same logic as Reservation model.
-
.today? ⇒ Boolean
Helper method to check if reservation is today.
Methods inherited from ApplicationRecord
Instance Attribute Details
#active ⇒ Boolean
Returns Whether reservation is active (not cancelled/deleted).
|
|
# File 'app/models/partners/reservation_summary.rb', line 23
|
#adjusted ⇒ Boolean
Returns Whether reservation was modified after creation.
|
|
# File 'app/models/partners/reservation_summary.rb', line 23
|
#adult ⇒ Integer
Returns Number of adult guests.
|
|
# File 'app/models/partners/reservation_summary.rb', line 23
|
#created_at ⇒ DateTime
Returns Record creation timestamp.
|
|
# File 'app/models/partners/reservation_summary.rb', line 23
|
#customer_email ⇒ String
Returns Customer email for search functionality.
|
|
# File 'app/models/partners/reservation_summary.rb', line 23
|
#customer_name ⇒ String
Returns Customer name for search functionality.
|
|
# File 'app/models/partners/reservation_summary.rb', line 23
|
#customer_phone ⇒ String
Returns Customer phone for search functionality.
|
|
# File 'app/models/partners/reservation_summary.rb', line 23
|
#date ⇒ Date
Returns Reservation date for filtering and grouping.
|
|
# File 'app/models/partners/reservation_summary.rb', line 23
|
#end_time ⇒ Time
Returns Reservation end time.
|
|
# File 'app/models/partners/reservation_summary.rb', line 23
|
#for_locking_system ⇒ Boolean
Returns Whether reservation is for table locking system.
|
|
# File 'app/models/partners/reservation_summary.rb', line 23
|
#is_temporary ⇒ Boolean
Returns Whether reservation is temporary (pending confirmation).
|
|
# File 'app/models/partners/reservation_summary.rb', line 23
|
#kids ⇒ Integer
Returns Number of child guests.
|
|
# File 'app/models/partners/reservation_summary.rb', line 23
|
#last_synced_at ⇒ DateTime?
Returns Timestamp of last sync for monitoring data freshness.
|
|
# File 'app/models/partners/reservation_summary.rb', line 23
|
#party_size ⇒ Integer
Returns Total number of guests (adult + kids).
|
|
# File 'app/models/partners/reservation_summary.rb', line 23
|
#payment_status ⇒ String
Returns Payment status for filtering.
|
|
# File 'app/models/partners/reservation_summary.rb', line 23
|
#reservation_id ⇒ Integer
Returns Original reservation ID (primary reference).
|
|
# File 'app/models/partners/reservation_summary.rb', line 23
|
#reservation_status ⇒ String
Returns Current reservation status.
|
|
# File 'app/models/partners/reservation_summary.rb', line 23
|
#restaurant_id ⇒ Integer
Returns Restaurant ID for filtering and associations.
|
|
# File 'app/models/partners/reservation_summary.rb', line 23
|
#service_type ⇒ String
Returns Service type ('dine_in', 'delivery', etc.).
|
|
# File 'app/models/partners/reservation_summary.rb', line 23
|
#start_time ⇒ Time
Returns Reservation start time.
|
|
# File 'app/models/partners/reservation_summary.rb', line 23
|
#updated_at ⇒ DateTime
Returns Record last update timestamp.
|
|
# File 'app/models/partners/reservation_summary.rb', line 23
|
#user_id ⇒ Integer?
Returns User ID (optional for guest bookings).
|
|
# File 'app/models/partners/reservation_summary.rb', line 23
|
Class Method Details
.adjusted? ⇒ Boolean
Check if reservation was adjusted (modified)
175 176 177 |
# File 'app/models/partners/reservation_summary.rb', line 175 def adjusted? adjusted == true end |
.by_date(date) ⇒ ActiveRecord::Relation<Partners::ReservationSummary>
Filter summaries by specific date
118 |
# File 'app/models/partners/reservation_summary.rb', line 118 scope :by_date, ->(date) { where(date: date) } |
.by_package_type(type) ⇒ ActiveRecord::Relation<Partners::ReservationSummary>
Filter summaries by package type through associated packages
147 148 149 |
# File 'app/models/partners/reservation_summary.rb', line 147 scope :by_package_type, ->(type) { joins(:summary_packages).where(partners_reservation_summary_packages: { package_type: type }) } |
.by_party_size(party_size) ⇒ ActiveRecord::Relation<Partners::ReservationSummary>
Filter summaries by party size
134 |
# File 'app/models/partners/reservation_summary.rb', line 134 scope :by_party_size, ->(party_size) { where(party_size: party_size) } |
.by_restaurant(restaurant_id) ⇒ ActiveRecord::Relation<Partners::ReservationSummary>
Filter summaries by restaurant
111 |
# File 'app/models/partners/reservation_summary.rb', line 111 scope :by_restaurant, ->(restaurant_id) { where(restaurant_id: restaurant_id) } |
.by_service_type(service_type) ⇒ ActiveRecord::Relation<Partners::ReservationSummary>
Filter summaries by service type
127 |
# File 'app/models/partners/reservation_summary.rb', line 127 scope :by_service_type, ->(service_type) { where(service_type: service_type) } |
.delivery? ⇒ Boolean
Check if reservation is for delivery service
182 183 184 |
# File 'app/models/partners/reservation_summary.rb', line 182 def delivery? service_type == 'delivery' end |
.dine_in? ⇒ Boolean
Check if reservation is for dine-in service
189 190 191 |
# File 'app/models/partners/reservation_summary.rb', line 189 def dine_in? service_type == 'dine_in' end |
.future? ⇒ Boolean
Helper method to check if reservation is in the future
235 236 237 |
# File 'app/models/partners/reservation_summary.rb', line 235 def future? !past? end |
.past? ⇒ Boolean
Time-dependent method that cannot be stored in database This replaces the need to store is_past_reservation field
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'app/models/partners/reservation_summary.rb', line 197 def past? return false unless date && start_time begin restaurant_timezone = restaurant&.time_zone || 'Asia/Bangkok' reservation_datetime = Time.zone.parse("#{date} #{start_time}") reservation_datetime_in_tz = reservation_datetime.in_time_zone(restaurant_timezone) current_time_in_tz = Time.current.in_time_zone(restaurant_timezone) reservation_datetime_in_tz < current_time_in_tz rescue StandardError => e BUSINESS_LOGGER.warn('Error calculating is_past for reservation summary', { reservation_id: reservation_id, error_message: e., }) false end end |
.reservation_time ⇒ Time
Calculate reservation time using exact same logic as Reservation model
This method replicates the reservation_time logic from the original Reservation model to avoid N+1 queries while maintaining exact compatibility. Memoized for performance since date/time fields rarely change for existing reservations.
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'app/models/partners/reservation_summary.rb', line 248 def reservation_time return @reservation_time if defined?(@reservation_time) time_zone = restaurant&.time_zone || 'Asia/Bangkok' @reservation_time = Time.use_zone time_zone do if start_time.blank? Time.zone.at(0) else # Use start_time_format equivalent (start_time is already stored as string) start_time_formatted = start_time&.strftime('%H:%M') Time.zone.parse(start_time_formatted, date) end end rescue StandardError => e BUSINESS_LOGGER.warn('Error calculating reservation_time for reservation summary', { reservation_id: reservation_id, error_message: e., }) @reservation_time = Time.zone.at(0) end |
.today? ⇒ Boolean
Helper method to check if reservation is today
220 221 222 223 224 225 226 227 228 229 230 |
# File 'app/models/partners/reservation_summary.rb', line 220 def today? return false unless date begin restaurant_timezone = restaurant&.time_zone || 'Asia/Bangkok' current_date_in_tz = Time.current.in_time_zone(restaurant_timezone).to_date date == current_date_in_tz rescue StandardError false end end |