Order from API
This commit is contained in:
parent
c484741c16
commit
0aab29f0cb
2 changed files with 28 additions and 6 deletions
|
@ -22,12 +22,20 @@ class OrdersController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
if @order.save
|
respond_to do |format|
|
||||||
flash[:success] = @order.flash_success
|
format.html do
|
||||||
redirect_to root_path
|
if @order.save
|
||||||
else
|
flash[:success] = @order.flash_success
|
||||||
@products = Product.all.for_sale.order(:name)
|
redirect_to root_path
|
||||||
render 'new'
|
else
|
||||||
|
@products = Product.all.for_sale.order(:name)
|
||||||
|
render 'new'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
format.json do
|
||||||
|
@order.save
|
||||||
|
render json: @order
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
14
python_api_example/order.py
Normal file
14
python_api_example/order.py
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
base_url = 'http://localhost:3000'
|
||||||
|
user = 'j'
|
||||||
|
user_token = 'uiUTrjuD3ZSft6s8JD9S4g=='
|
||||||
|
|
||||||
|
headers = {'Authorization': f'Token token={user_token}'}
|
||||||
|
product = 1
|
||||||
|
|
||||||
|
data = {"order": {"order_items_attributes": [{"count": 1, "product_id": product}]}}
|
||||||
|
|
||||||
|
r = requests.post(f'{base_url}/users/{user}/orders.json', headers=headers, json=data)
|
||||||
|
print(r.text)
|
Loading…
Reference in a new issue