Sha256: 4328969d0552bbacabaeee591a1ffd9d469e72966473e870f12481ebf52db747

Contents?: true

Size: 1.63 KB

Versions: 7

Compression:

Stored size: 1.63 KB

Contents

class Mobile::OrdersController < ApplicationController
  rescue_from ActiveRecord::RecordNotFound do |e|
    case e.message
    when /Organization/
      error = {
        :error => "Could not load orders",
        :reason => "Organization could not be found",
        :code => 2
      }
      render :json => error, :status => 404
    when /Show/
      error = {
        :error => "Could not load orders",
        :reason => "Show could not be found",
        :code => 4
      }
      render :json => error, :status => 404
    when /Order/
      error = {
        :error => "Could not load order",
        :reason => "Order could not be found",
        :code => 5
      }
      render :json => error, :status => 404
    else
      raise e
    end
  end

  def index
    organization = current_user.organizations.find(params[:organization_id])
    show = organization.shows.find(params[:show_id])
    orders = show.items.map(&:order).uniq
    render :json => orders, :each_serializer => OrderSerializer
  end

  def show
    organization = current_user.organizations.find(params[:organization_id])
    order = organization.orders.find(params[:id])
    render :json => order, :serializer => OrderSerializer
  end

  def validate
    organization = current_user.organizations.find(params[:organization_id])
    order = organization.orders.find(params[:id])

    Order.transaction do
      order.tickets.each do |item|
        ticket = item.product
        begin
          ticket.validate_ticket!(current_user)
        rescue Transitions::InvalidTransition
          # ignore
        end
      end
    end

    render :json => order, :serializer => OrderSerializer
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
artfully_ose-1.2.0.pre.23 app/controllers/mobile/orders_controller.rb
artfully_ose-1.2.0.pre.21 app/controllers/mobile/orders_controller.rb
artfully_ose-1.2.0.pre.20 app/controllers/mobile/orders_controller.rb
artfully_ose-1.2.0.pre.19 app/controllers/mobile/orders_controller.rb
artfully_ose-1.2.0.pre.18 app/controllers/mobile/orders_controller.rb
artfully_ose-1.2.0.pre.17 app/controllers/mobile/orders_controller.rb
artfully_ose-1.2.0.pre.16 app/controllers/mobile/orders_controller.rb