Class: Api::V5::TicketGroupsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/api/v5/ticket_groups_controller.rb

Overview

typed: ignore frozen_string_literal: true

Constant Summary

Constants inherited from BaseController

BaseController::CACHE_NAMESPACE, BaseController::INTERNAL_SERVER_ERROR_MESSAGE, BaseController::ResponseSchema

Instance Method Summary collapse

Methods inherited from BaseController

#identity_cache_memoization

Methods included from LogrageCustomLogger

#append_info_to_payload

Methods included from ResponseCacheConcern

#my_response_cache

Instance Method Details

#availabilityObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/api/v5/ticket_groups_controller.rb', line 42

def availability
  begin
    restaurant_id = params.require(:restaurant_id)
  rescue ActionController::ParameterMissing
    return render json: { error: 'Missing restaurant_id parameter' }, status: :bad_request
  end

  qw = InvQuotaWitness.new
  data = qw.get_data_by_restaurant_id(restaurant_id)

  render json: {
    data: data,
    success: true,
  }
end

#indexObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/api/v5/ticket_groups_controller.rb', line 7

def index
  restaurant = Restaurant.fetch params.require(:restaurant_id)
  time_next_reset_at = next_reset_at(restaurant.time_zone)
  cache_key = "Api::V5::TicketGroup:#{restaurant.active_ticket_groups.cache_key}:#{I18n.locale}:#{time_next_reset_at}"
  my_response_cache "#{self.class}:index:#{cache_key}", :json, public: true do
    ActiveModelSerializers::SerializableResource.new(restaurant.active_ticket_groups, {
                                                       serializer: ActiveModel::Serializer::CollectionSerializer,
                                                       adapter: :json_api,
                                                       each_serializer: Api::V5::TicketGroupSerializer,
                                                     }).as_json.
      merge(status: true,
            message: nil,
            next_reset_at: time_next_reset_at)
  end
  set_status_header(true)
rescue ActiveRecord::RecordNotFound
  raise RecordNotFoundButOk
end

#showObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/api/v5/ticket_groups_controller.rb', line 26

def show
  if @ticket_group.nil?
    return render json: { error: 'Ticket group not found' }, status: :not_found
  end

  my_response_cache @ticket_group.cache_key, :json, public: true do
    JSON.parse(
      render_to_string(
        json: @ticket_group,
        serializer: Api::V5::TicketGroupSerializer,
        adapter: :json_api,
      ),
    ).merge(success: true)
  end
end