Ejemplo n.º 1
0
 def post(self):
     #Post trên server sẽ lấy đủ đơn hàng, post trên local sẽ thiếu đơn hàng
     body = parser.parse_args()
     items = body["items"]
     user_id = body.user_id
     total_spend = 0
     order_item = []
     dumps = json.dumps(items)
     ldumps = re.findall(r"[\w']+", dumps)
     print(len(items))
     for i in range(0, len(items) + 1):
         try:
             good_id = ldumps[4 * i + 1][1:-1]
             count = int(ldumps[4 * i + 3])
             good = Good.objects().with_id(good_id)
             price = good.price
             total_spend += price * count
             singleOrder = SingleOrder(good=good, count=count)
             order_item.append(singleOrder)
         except:
             print("Index error")
     print("order_item:", mlab.list2json(order_item))
     customer = Customer.objects().with_id(user_id)
     order = Order(items=order_item,
                   customer=customer,
                   totalspend=total_spend)
     order.save()
     add_order = Order.objects().with_id(order.id)
     return mlab.item2json(add_order)
Ejemplo n.º 2
0
    def put(self, order_id):
        parser = reqparse.RequestParser()

        parser.add_argument(name="username", type=str, location="json")
        parser.add_argument(name="userid", type=str, location="json")
        parser.add_argument(name="food_name", type=str, location="json")
        parser.add_argument(name="orderdate", type=str, location="json")
        parser.add_argument(name="rate", type=float, location="json")
        parser.add_argument(name="food_number", type=int, location="json")

        body = parser.parse_args()

        username = body.username
        userid = body.userid
        food_name = body.food_name
        orderdate = body.orderdate
        rate = body.rate
        food_number = body.food_number

        order = Order.objects().with_id(order_id)
        order.update(username=username,
                     userid=userid,
                     food_name=food_name,
                     orderdate=orderdate,
                     rate=rate,
                     food_number=food_number)

        return mlab.item2json(order)
Ejemplo n.º 3
0
    def post(self):

        #parser.add_argument(name="id", type= int, location="json")
        #parser.add_argument(name="count", type=int, location="json")

        body = parser.parse_args()
        items = body["items"]
        user_id = body.user_id
        total_spend = 0
        order_item = []
        print("body:", body)
        print("items:", items)
        print("user_id:", user_id)
        for item in items:
            print("item type:", type(item))
            print("item:", item)
            good_id = item["id"]
            count = item["count"]
            good = Good.objects().with_id(good_id)
            price = good.price
            print("good_id:", good_id, ";count: ", count, "price: ", price)
            total_spend += price * count
            singleOrder = SingleOrder(good=good, count=count)
            order_item.append(singleOrder)
        customer = Customer.objects().with_id(user_id)
        #print(mlab.item2json(order_item[0]))
        #print("order_item0:",mlab.item2json(order_item[0]),"order_item1:",order_item[1])

        order = Order(items=order_item,
                      customer=customer,
                      totalspend=total_spend)
        order.save()
        add_order = Order.objects().with_id(order.id)
        return mlab.item2json(add_order)
Ejemplo n.º 4
0
 def get(self):
     orders = Order.objects()
     return mlab.list2json(orders)
Ejemplo n.º 5
0
 def get(self, order_id):
     order = Order.objects().with_id(order_id)
     return mlab.item2json(order)