Class: Api::V5::TicketsController

Inherits:
BaseController
  • Object
show all
Includes:
Concerns::Authorization, Concerns::PaginationParam
Defined in:
app/controllers/api/v5/tickets_controller.rb

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

#indexObject



28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/api/v5/tickets_controller.rb', line 28

def index
  section_type = params.require(:section_type)
  page = params.fetch(:page, {})
  section_type = params[:section_type].presence || "redeemed"
  filter = Api::V5::TicketsFilter.new(current_user)
  filter.section_type(section_type)
  filter.build_collections

  filter.page_number(page.fetch(:number, 1)).per_page(page.fetch(:size, 10))
  render json: filter.as_json(serialization_context).merge(success: true, message: nil)
end

#qrcodeObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/controllers/api/v5/tickets_controller.rb', line 40

def qrcode
  ticket = Ticket.find_by(id: Ticket.decrypt_id(params[:ticket_id]))
  if ticket.present?
    today = DateTime.now
    valid_date = today >= ticket.valid_start_date && today <= ticket.valid_end_date
    title = ticket.ticket_group.name
    price = ticket.amount.amount
    valid_start = ticket.valid_start_date
    valid_end = ticket.valid_end_date
    code = ticket.ticket_code
    qrcode = ticket.qrcode_data_url
    if valid_date
      @data = {
        ticket_id: ticket.id,
        title: title,
        price: price,
        valid_start: valid_start,
        valid_end: valid_end,
        code: code,
        qrcode: qrcode,
        is_valid: true
      }
      render json: @data
    else
      @data = {
        ticket_id: ticket.id,
        title: title,
        price: price,
        valid_start: valid_start,
        valid_end: valid_end,
        code: code,
        qrcode: qrcode,
        is_valid: false
      }
      render json: @data
    end
  else
    redirect_to 'https://www.hungryhub.com'
  end
end

#showObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/api/v5/tickets_controller.rb', line 12

def show
  voucher = Ticket.find_by(id: Ticket.decrypt_id(params[:id]))

  return render json: { success: false, data: nil, message: 'Invalid data' } if voucher.blank?

  my_response_cache voucher.cache_key, :json do
    JSON.parse(
      render_to_string(
        json: voucher,
        serializer: Api::V5::TicketSerializer,
        adapter: :json_api
      )
    ).merge(success: true)
  end
end