Class: Api::Aoa::V1::ReservationsFilter
- Inherits:
-
Object
- Object
- Api::Aoa::V1::ReservationsFilter
- Defined in:
- app/filters/api/aoa/v1/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::Aoa::V1::RestaurantPreviewSerializer.
-
#build_collections ⇒ Object
get desired reservations from database.
- #by_aoa_user_id(aoa_user_id) ⇒ Object
- #dining_time(time_x, operator, time_y = nil) ⇒ Object
- #exclude_no_package ⇒ Object
- #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
- #per_page(number) ⇒ Object
Constructor Details
#initialize(collections = nil) ⇒ ReservationsFilter
Returns a new instance of ReservationsFilter.
11 12 13 14 |
# File 'app/filters/api/aoa/v1/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/aoa/v1/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/aoa/v1/reservations_filter.rb', line 8 def @error_message end |
Instance Method Details
#active_only(val) ⇒ Object
36 37 38 39 |
# File 'app/filters/api/aoa/v1/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::Aoa::V1::RestaurantPreviewSerializer
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'app/filters/api/aoa/v1/reservations_filter.rb', line 100 def as_json(context, _version, = {}) [:each_serializer] = Api::Aoa::V1::ReservationSerializer ActiveModelSerializers::SerializableResource.new(collections, { serialization_context: context, serializer: ActiveModel::Serializer::CollectionSerializer, adapter: :json_api, }.merge()).as_json # options[:each_serializer] = Api::Aoa::V1::ReservationSerializer # options[:user_id] = config[:user].id if config[:user] # ActiveModelSerializers::SerializableResource.new(build_collections, # { serialization_context: context, # serializer: ActiveModel::Serializer::CollectionSerializer, # adapter: :json_api }.merge(options)).as_json end |
#build_collections ⇒ Object
get desired reservations from database
124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'app/filters/api/aoa/v1/reservations_filter.rb', line 124 def build_collections _init_default _need_review _active_only _not_pending _pending _exclude_no_package _filter_by_dining_time _order_by _paginate collections end |
#by_aoa_user_id(aoa_user_id) ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'app/filters/api/aoa/v1/reservations_filter.rb', line 82 def by_aoa_user_id(aoa_user_id) return self if aoa_user_id.blank? self.collections = collections.joins(:aoa_reservation) .where(aoa_reservations: { aoa_user_id: aoa_user_id, }) self end |
#dining_time(time_x, operator, time_y = nil) ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'app/filters/api/aoa/v1/reservations_filter.rb', line 63 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 ⇒ Object
118 119 120 121 |
# File 'app/filters/api/aoa/v1/reservations_filter.rb', line 118 def exclude_no_package config[:exclude_no_package] = true self end |
#init_default(user) ⇒ Object
17 18 19 20 21 22 |
# File 'app/filters/api/aoa/v1/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/aoa/v1/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/aoa/v1/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/aoa/v1/reservations_filter.rb', line 29 def order_by(order) return self if order.blank? config[:order_by] = order self end |
#page_number(number) ⇒ Object
72 73 74 75 |
# File 'app/filters/api/aoa/v1/reservations_filter.rb', line 72 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/aoa/v1/reservations_filter.rb', line 46 def pending(val) config[:pending] = val self end |
#per_page(number) ⇒ Object
77 78 79 80 |
# File 'app/filters/api/aoa/v1/reservations_filter.rb', line 77 def per_page(number) config[:per_page] = number.to_i if number.to_i.positive? self end |