31 lines
740 B
Ruby
31 lines
740 B
Ruby
|
|
|
|
helpers do
|
|
def anonymous_id
|
|
auid = cookies[:anonymous_user_id]
|
|
if auid.nil?
|
|
auid = AnonymousUser.uid
|
|
response.set_cookie('anonymous_user_id', :path=> '/', :httponly => true, :value=>auid, :expires=>Time.now+100.year)
|
|
end
|
|
auid
|
|
end
|
|
end
|
|
|
|
get '/cart' do
|
|
# -1 is a placeholder for user id when we implement users
|
|
# auid will still be used in case user is not logged in
|
|
Cart.find_or_create(anonymous_id, -1).to_json
|
|
end
|
|
|
|
get '/cart/item' do
|
|
Cart.find_or_create(anonymous_id, -1).item_in_carts.to_json
|
|
end
|
|
|
|
post '/cart/item/add' do
|
|
#cart_id = Cart.find_or_create(anonymous_id, -1).id
|
|
#item_id = params[:id].to_i
|
|
#ItemInCart.add(cart_id, item_id)
|
|
#json_params.to_json
|
|
"not ready yet".to_json
|
|
end
|