Module: Rawbotz::RawbotzApp::Routing::RemoteShop

Includes:
RawgentoModels
Defined in:
lib/rawbotz/routes/remote_shop.rb

Class Method Summary collapse

Class Method Details

.registered(app) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rawbotz/routes/remote_shop.rb', line 6

def self.registered(app)
  # app.get '/remote_cart',   &show_remote_cart
  show_remote_cart = lambda do
    @cart_content = Rawbotz.mech.get_cart_content
    @cart_products = @cart_content.map do |name, qty|
      [RemoteProduct.find_by(name: name), qty]
    end
    haml "remote_cart/index".to_sym
  end

  # app.get '/remote_orders',    &show_remote_orders
  show_remote_orders = lambda do
    @last_orders = Rawbotz.mech.last_orders
    haml "remote_orders/index".to_sym
  end

  # app.get '/remote_order/:id', &show_remote_order
  show_remote_order = lambda do
    @remote_order_id = params[:id]
    @remote_order_items = Rawbotz.mech.products_from_order params[:id]
    @remote_products_qty = @remote_order_items.map do |remote_product|
      [RemoteProduct.find_by(name: remote_product[0]) || OpenStruct.new(name: remote_product[0]), remote_product[2], remote_product[3]]
    end
    # TODO catch problem if one is missing ...
    haml "remote_order/view".to_sym
  end

  app.get '/remote_cart',      &show_remote_cart
  app.get '/remote_orders',    &show_remote_orders
  app.get '/remote_order/:id', &show_remote_order
end