Class: Api::V5::ReservationsFilter
- Inherits:
-
Object
- Object
- Api::V5::ReservationsFilter
- Defined in:
- app/filters/api/v5/reservations_filter.rb
Overview
Responsible to filter reservations data based on user ID
Instance Attribute Summary collapse
-
#collections ⇒ Object
Returns the value of attribute collections.
-
#error_message ⇒ Object
Returns the value of attribute error_message.
Instance Method Summary collapse
- #active_only(val) ⇒ Object
-
#as_json(context, _version, options = {}) ⇒ Object
if preview_mode == true, then use Api::V5::RestaurantPreviewSerializer.
-
#build_collections ⇒ Object
get desired reservations from database.
- #dining_time(time_x, operator, time_y = nil) ⇒ Object
- #exclude_no_package(val) ⇒ Object
-
#group_booking(val) ⇒ Api::V5::ReservationsFilter
Returns self for method chaining.
- #init_default(user) ⇒ Object
-
#initialize(collections = nil) ⇒ ReservationsFilter
constructor
A new instance of ReservationsFilter.
- #need_review(val) ⇒ Object
- #not_pending(val) ⇒ Object
- #order_by(order) ⇒ Object
- #page_number(number) ⇒ Object
- #pending(val) ⇒ Object
-
#pending_confirmation(val) ⇒ Api::V5::ReservationsFilter
Returns self for method chaining.
- #per_page(number) ⇒ Object
Constructor Details
#initialize(collections = nil) ⇒ ReservationsFilter
Returns a new instance of ReservationsFilter.
11 12 13 14 |
# File 'app/filters/api/v5/reservations_filter.rb', line 11 def initialize(collections = nil) self.collections = collections unless collections.nil? @config = {} end |
Instance Attribute Details
#collections ⇒ Object
Returns the value of attribute collections.
8 9 10 |
# File 'app/filters/api/v5/reservations_filter.rb', line 8 def collections @collections end |
#error_message ⇒ Object
Returns the value of attribute error_message.
8 9 10 |
# File 'app/filters/api/v5/reservations_filter.rb', line 8 def @error_message end |
Instance Method Details
#active_only(val) ⇒ Object
36 37 38 39 |
# File 'app/filters/api/v5/reservations_filter.rb', line 36 def active_only(val) config[:active_only] = val self end |
#as_json(context, _version, options = {}) ⇒ Object
if preview_mode == true, then use Api::V5::RestaurantPreviewSerializer
105 106 107 108 109 110 111 112 |
# File 'app/filters/api/v5/reservations_filter.rb', line 105 def as_json(context, _version, = {}) [:each_serializer] = Api::V5::ReservationSerializer [:user_id] = config[:user].id if config[:user] ActiveModelSerializers::SerializableResource.new(build_collections, { serialization_context: context, serializer: ActiveModel::Serializer::CollectionSerializer, adapter: :json_api }.merge()).as_json end |
#build_collections ⇒ Object
get desired reservations from database
120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'app/filters/api/v5/reservations_filter.rb', line 120 def build_collections _init_default _need_review _active_only _not_pending _pending _pending_confirmation _group_booking _exclude_no_package _filter_by_dining_time _order_by _paginate collections end |
#dining_time(time_x, operator, time_y = nil) ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'app/filters/api/v5/reservations_filter.rb', line 77 def dining_time(time_x, operator, time_y = nil) config[:dining_time] = { time_x: time_x, operator: operator, time_y: time_y, } self end |
#exclude_no_package(val) ⇒ Object
114 115 116 117 |
# File 'app/filters/api/v5/reservations_filter.rb', line 114 def exclude_no_package(val) config[:exclude_no_package] = val self end |
#group_booking(val) ⇒ Api::V5::ReservationsFilter
Returns self for method chaining
65 66 67 68 |
# File 'app/filters/api/v5/reservations_filter.rb', line 65 def group_booking(val) config[:group_booking] = val self end |
#init_default(user) ⇒ Object
17 18 19 20 21 22 |
# File 'app/filters/api/v5/reservations_filter.rb', line 17 def init_default(user) return self unless user.is_a?(::User) config[:user] = user self end |
#need_review(val) ⇒ Object
51 52 53 54 |
# File 'app/filters/api/v5/reservations_filter.rb', line 51 def need_review(val) config[:need_review] = val self end |
#not_pending(val) ⇒ Object
41 42 43 44 |
# File 'app/filters/api/v5/reservations_filter.rb', line 41 def not_pending(val) config[:not_pending] = val self end |
#order_by(order) ⇒ Object
29 30 31 32 33 34 |
# File 'app/filters/api/v5/reservations_filter.rb', line 29 def order_by(order) return self if order.blank? config[:order_by] = order self end |
#page_number(number) ⇒ Object
86 87 88 89 |
# File 'app/filters/api/v5/reservations_filter.rb', line 86 def page_number(number) config[:page_number] = number.to_i if number.to_i.positive? self end |
#pending(val) ⇒ Object
46 47 48 49 |
# File 'app/filters/api/v5/reservations_filter.rb', line 46 def pending(val) config[:pending] = val self end |
#pending_confirmation(val) ⇒ Api::V5::ReservationsFilter
Returns self for method chaining
58 59 60 61 |
# File 'app/filters/api/v5/reservations_filter.rb', line 58 def pending_confirmation(val) config[:pending_confirmation] = val self end |
#per_page(number) ⇒ Object
91 92 93 94 |
# File 'app/filters/api/v5/reservations_filter.rb', line 91 def per_page(number) config[:per_page] = number.to_i if number.to_i.positive? self end |