Exemple #1
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)
    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)
Exemple #3
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)
    def post(self):
        parser = reqparse.RequestParser()

        parser.add_argument(name="username", type=str, location="json")
        parser.add_argument(name="password", type=str, location="json")
        parser.add_argument(name="address", type=str, location="json")
        parser.add_argument(name="spend", type=float, location="json")
        parser.add_argument(name="total_spend", type=float, location="json")

        body = parser.parse_args()

        username = body["username"]
        password = body["password"]
        address = body["address"]
        spend = body["spend"]
        total_spend = body["total_spend"]

        user = User(username=username,
                    password=password,
                    address=address,
                    spend=spend,
                    total_spend=total_spend)
        user.save()

        return mlab.item2json(user)
    def post(self):
        parser = reqparse.RequestParser()

        parser.add_argument(name="res_id", type=str, location="json")
        parser.add_argument(name="manager_id", type=str, location="json")
        parser.add_argument(name="res_name", type=str, location="json")
        parser.add_argument(name="res_type", type=str, location="json")
        parser.add_argument(name="address", type=str, location="json")
        parser.add_argument(name="phone", type=str, location="json")
        parser.add_argument(name="describe", type=str, location="json")

        body = parser.parse_args()

        res_id = body["res_id"]
        manager_id = body["manager_id"]
        res_name = body["res_name"]
        res_type = body["res_type"]
        address = body["address"]
        phone = body["phone"]
        describe = body["describe"]

        restaurant = Restaurant(res_id=res_id, manager_id=manager_id, res_name=res_name, res_type=res_type,
                                address=address, phone=phone, describe=describe)

        restaurant.save()

        added_menu = Restaurant.objects().with_id(restaurant.id)
        return mlab.item2json(added_menu)
Exemple #6
0
    def put(self, item_id):
        try:
            item = Item.objects(item_id=item_id).first()
        except Exception:
            return {"message": "Item id not exit"}, 400
        if item is None:
            return {"message": "Item id not exit"}, 400
        parser = reqparse.RequestParser()

        parser.add_argument(name="menu_id", type=str, location='json')
        parser.add_argument(name="cate_id", type=str, location='json')
        parser.add_argument(name="item_id", type=str, location='json')
        parser.add_argument(name="item_name", type=str, location='json')
        parser.add_argument(name="item_price", type=float, location='json')
        # parser.add_argument(name="item_discount", type=float, location='json')
        parser.add_argument(name="item_discount", type=float, location='json')
        parser.add_argument(name="item_desc", type=str, location='json')
        parser.add_argument(name="item_info", type=str, location='json')
        parser.add_argument(name="item_images_url", type=str, location='json', action='append')

        body = parser.parse_args()
        item_old_price = item.item_price
        menu_id = body["menu_id"]
        cate_id = body["cate_id"]
        # item_id = body["item_id"]
        item_name = body["item_name"]
        item_price = body["item_price"]
        # item_discount = body["item_discount"]
        item_desc = body["item_desc"]
        item_info = body["item_info"]
        item_images_url =[]
        # item_images_url = body["item_images_url"]
        listImage = ["http://www.lotteria.vn/resize.php?w=250&h=250&src=data/201423/bigstar_6281.png&zc=1",
                     "http://www.lotteria.vn/resize.php?w=250&h=250&src=data/201422/tom-b_8200.png&zc=1",
                     "http://www.lotteria.vn/resize.php?w=250&h=250&src=data/201635/1a_7975.png&zc=1",
                     "http://www.lotteria.vn/resize.php?w=250&h=250&src=data/201422/chicken-ball-rice_1604.png&zc=1",
                     "http://www.lotteria.vn/resize.php?w=250&h=250&src=data/201424/soup_7846.png&zc=1",
                     "http://www.lotteria.vn/resize.php?w=250&h=250&src=data/201635/4a_858.png&zc=1",
                     "http://www.lotteria.vn/resize.php?w=250&h=250&src=data/201422/pho-mai-que_5719.png&zc=1",
                     "http://www.lotteria.vn/resize.php?w=250&h=250&src=data/201422/gavien_6350.png&zc=1",
                     "http://www.lotteria.vn/resize.php?w=250&h=250&src=data/201710/hash-brown-n_9432.png&zc=1",
                     "http://www.lotteria.vn/resize.php?w=250&h=250&src=data/201422/hot-pie-_7269.png&zc=1",
                     "http://www.lotteria.vn/resize.php?w=250&h=250&src=data/201422/kem-ly-b_4978.png&zc=1",
                     "http://www.lotteria.vn/resize.php?w=250&h=250&src=data/201422/kem-cay_4637.png&zc=1",
                     "http://www.lotteria.vn/resize.php?w=250&h=250&src=data/201422/corn-salad---2_8590.png&zc=1",
                     "http://www.lotteria.vn/resize.php?w=250&h=250&src=data/201422/soy-bean-chicken-rice_2175.png&zc=1",
                     "http://www.lotteria.vn/resize.php?w=250&h=250&src=data/201640/lotteria---ga-sot---set_5668.png&zc=1"]
        item_images_url.append(listImage[random.randint(0, 14)])
        item_images_url.append(listImage[random.randint(0, 14)])
        item_images_url.append(listImage[random.randint(0, 14)])

        item.update(set__menu_id=menu_id, set__cate_id=cate_id, set__item_name=item_name, set__item_price=item_price,
                    set__item_old_price=item_old_price, set__item_info=item_info,
                    set__item_desc=item_desc, set__item_images_url=item_images_url)

        added_item = Item.objects().with_id(item.id)

        return mlab.item2json(added_item)
Exemple #7
0
    def get(self):
        search_terms = request.args["search_terms"].lower().strip()

        audio = Audio.objects(search_terms=search_terms).first()

        if audio is not None:
            return {'success': 1, 'data': mlab.item2json(audio)}
        else:
            return {'success': 0, 'message': 'Not found'}
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument(name="manager_id", type=str, location="json")
        parser.add_argument(name="menu_id", type=str, location="json")
        parser.add_argument(name="menu_name", type=str, location="json")
        parser.add_argument(name="date_create", type=str, location="json")
        parser.add_argument(name="describe", type=str, location="json")
        parser.add_argument(name="menu_pic", type=str, location="json")
        parser.add_argument(name="categories", type=list, location="json")
        parser.add_argument(name="items", type=list, location="json")

        # parse body
        body = parser.parse_args()
        # getdata from body
        manager_id = body["manager_id"]
        menu_id = body["menu_id"]
        menu_name = body["menu_name"]
        date_create = body["date_create"]
        describe = body["describe"]
        menu_pic = body["menu_pic"]
        categories = body["categories"]
        items = body["items"]

        curent_menus = Menu.objects()
        # check require field
        if manager_id is None:
            mess = {"message": "Restaurant id is required"}
            return RespHandle.get_resp(mess=mess, code=400)
        if menu_id is None:
            mess = {"message": "Menu id is required"}
            return RespHandle.get_resp(mess=mess, code=400)

        # check exit id
        for m in curent_menus:

            c_menu_id = m["menu_id"]

            if menu_id == c_menu_id:
                mess = {"message": "Menu id is exited"}
                return RespHandle.get_resp(mess=mess, code=400)

        menu = Menu(manager_id=manager_id,
                    menu_id=menu_id,
                    menu_name=menu_name,
                    date_create=date_create,
                    describe=describe,
                    menu_pic=menu_pic,
                    categories=categories,
                    items=items)

        menu.save()

        added_menu = Menu.objects().with_id(menu.id)
        resp = jsonify(mlab.item2json(added_menu))
        resp.status_code = 200
        return added_menu.get_json()
Exemple #9
0
 def get_json(self):
     str = mlab.item2json(self)
     oid = str["_id"]["$oid"]
     return {
         "id_comment": oid,
         "customer": self.customer.get_json(),
         "message": self.message,
         "rage": self.rage.get_json(),
         "date": self.date
     }
Exemple #10
0
 def get(self):
     args = request.args
     users = User.objects(
         (Q(username=args["username"]) & Q(password=args["password"])))
     print(len(users))
     if len(users) == 0:
         return {"status ": "error", "message": "User doesn't exist"}, 401
     else:
         print(users.first())
         return mlab.item2json(users)
Exemple #11
0
    def post(self):
        args = parser.parse_args()

        username = args["username"]
        password = args["password"]

        account = Account(username=username, password=password)
        account.save()

        return mlab.item2json(Account.objects().with_id(account.id))
Exemple #12
0
    def get_json(self):

        str=mlab.item2json(self)
        oid=str["_id"]["$oid"]
        return {
            "id_comment":oid,
            "user":self.user.get_json(),
            "message":self.message,
            "food":self.food.get_json(),
            "date":self.date
        }
Exemple #13
0
 def put(self, id1, id2):
     parser = reqparse.RequestParser()
     parser.add_argument(name="message", type=str, location="json")
     body = parser.parse_args()
     message = body["message"]
     comment = Comment.objects().with_id(id2)
     date = datetime.datetime.utcnow() + datetime.timedelta(hours=7)
     comment.update(message=message, date=str(date))
     comment.save()
     comment_add = Comment.objects().with_id(id2)
     return mlab.item2json(comment_add), 200
Exemple #14
0
 def post(self):
     parser = reqparse.RequestParser()
     parser.add_argument(name="name", type=str, location="json")
     parser.add_argument(name="password", type=str, location="json")
     body = parser.parse_args()
     name = body["name"]
     password = body["password"]
     user = User(name=name, password=password)
     user.save()
     add_user = User.objects().with_id(user.id)
     return mlab.item2json(add_user)
Exemple #15
0
 def get_json(self):
     str = mlab.item2json(self)
     oid = str["_id"]["$oid"]
     return {
         "id_data": oid,
         "menu_id": self.menu_id,
         "cate_id": self.cate_id,
         "cate_name": self.cate_name,
         "cate_type": self.cate_type,
         "cate_order": self.cate_order,
         "items": [item.get_json() for item in self.items]
     }
Exemple #16
0
    def put(self):
        parser = reqparse.RequestParser()
        parser.add_argument(name="name", type=str, location="json")
        body = parser.parse_args()
        name = body.name
        checkin = CheckinClass.objects()

        for checkin_res in checkin:
            if (checkin_res.name != name):
                checkin.remove(checkin_res)

        return mlab.item2json(checkin)
Exemple #17
0
 def get_json(self):
     str = mlab.item2json(self)
     oid = str["_id"]["$oid"]
     return {
         "id_data": oid,
         "menu_id": self.menu_id,
         "cate_id": self.cate_id,
         "cate_name": self.cate_name,
         "cate_type": self.cate_type,
         "cate_order": self.cate_order,
         "items": [item.get_json() for item in self.items]
     }
 def post(self):
     parser = reqparse.RequestParser()
     parser.add_argument(name="name", type=str, location="json")
     parser.add_argument(name="date", type=str, location="json")
     parser.add_argument(name="students", type=list, location="json")
     body = parser.parse_args()
     name = body.name
     date = body.date
     students = body["students"]
     checkin = CheckinClass(name=name, date=date, students=students)
     checkin.save()
     add_checkin = CheckinClass.objects().with_id(checkin.id)
     return mlab.item2json(add_checkin)
Exemple #19
0
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument(name="name", type=str, location="json")
        parser.add_argument(name="password", type=str, location="json")
        body = parser.parse_args()
        name = body["name"]
        password = body["password"]

        for user_data in User.objects:
            if user_data.name == name:
                if user_data.password == password:
                    return mlab.item2json(user_data)
        return {"message": " Username or password doesn't not match"}, 401
Exemple #20
0
 def get_json(self):
     str = mlab.item2json(self)
     oid = str["_id"]["$oid"]
     return {
         "id_data": oid,
         "manager_id": self.manager_id,
         "menu_id": self.menu_id,
         "menu_name": self.menu_name,
         "date_create": self.date_create,
         "describe": self.describe,
         "menu_pic": self.menu_pic,
         "categories": [cate.get_json() for cate in self.categories],
         "items": [item.get_json() for item in self.items]
     }
Exemple #21
0
 def get_json(self):
     str = mlab.item2json(self)
     oid = str["_id"]["$oid"]
     return {
         "id_data": oid,
         "manager_id": self.manager_id,
         "menu_id": self.menu_id,
         "menu_name": self.menu_name,
         "date_create": self.date_create,
         "describe": self.describe,
         "menu_pic": self.menu_pic,
         "categories": [cate.get_json() for cate in self.categories],
         "items": [item.get_json() for item in self.items]
     }
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument(name="manager_id", type=str, location="json")
        parser.add_argument(name="menu_id", type=str, location="json")
        parser.add_argument(name="menu_name", type=str, location="json")
        parser.add_argument(name="date_create", type=str, location="json")
        parser.add_argument(name="describe", type=str, location="json")
        parser.add_argument(name="menu_pic", type=str, location="json")
        parser.add_argument(name="categories", type=list, location="json")
        parser.add_argument(name="items", type=list, location="json")

        # parse body
        body = parser.parse_args()
        # getdata from body
        manager_id = body["manager_id"]
        menu_id = body["menu_id"]
        menu_name = body["menu_name"]
        date_create = body["date_create"]
        describe = body["describe"]
        menu_pic = body["menu_pic"]
        categories = body["categories"]
        items = body["items"]

        curent_menus = Menu.objects()
        # check require field
        if manager_id is None:
            mess = {"message": "Restaurant id is required"}
            return RespHandle.get_resp(mess=mess, code=400)
        if menu_id is None:
            mess = {"message": "Menu id is required"}
            return RespHandle.get_resp(mess=mess, code=400)

        # check exit id
        for m in curent_menus:

            c_menu_id = m["menu_id"]

            if menu_id == c_menu_id:
                mess = {"message": "Menu id is exited"}
                return RespHandle.get_resp(mess=mess, code=400)

        menu = Menu(manager_id=manager_id, menu_id=menu_id, menu_name=menu_name, date_create=date_create, describe=describe,
                    menu_pic=menu_pic, categories=categories, items=items)

        menu.save()

        added_menu = Menu.objects().with_id(menu.id)
        resp = jsonify(mlab.item2json(added_menu))
        resp.status_code = 200
        return added_menu.get_json()
Exemple #23
0
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument(name="name", type=str, location="json")
        parser.add_argument(name="price", type=float, location="json")

        body = parser.parse_args()
        name = body.name
        price = body.price

        good = Good(goodname=name, price=price)
        good.save()
        print("saved")
        add_good = Good.objects().with_id(good.id)
        return mlab.item2json(add_good), 200
Exemple #24
0
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument(name="name", type=str, location="json")
        parser.add_argument(name="password", type=str, location="json")
        body = parser.parse_args()
        name = body["name"]
        for user_res in User.objects():
            if user_res.name == name:
                return {"message": "Username existed!"}, 401

        password = body["password"]
        user = User(name=name, password=password)
        user.save()
        add_user = User.objects().with_id(user.id)
        return mlab.item2json(add_user)
Exemple #25
0
    def get_json(self):

        str = mlab.item2json(self)
        oid = str["_id"]["$oid"]
        return {
            "id_data": oid,
            "id_user": self.id_user,
            "name": self.name,
            "address": self.address,
            "total_spend": self.total_spend,
            "phone_number": self.phone_number,
            "urlPic": self.urlPic,
            "urlFb": self.urlFb,
            "token": self.token
        }
Exemple #26
0
 def get_json(self):
     str = mlab.item2json(self)
     oid = str["_id"]["$oid"]
     return {
         "id": oid,
         "items": [item.get_json() for item in self.items],
         "spend": self.spend,
         "date": self.date,
         "address_order": self.address_order,
         "phone_number": self.phone_number,
         "customer": self.customer.get_json(),
         "is_Success": self.is_Success,
         "ship_money": self.ship_money,
         "code": self.code,
         "code_price": self.code_price
     }
Exemple #27
0
    def post(self):
        args = parser.parse_args()

        name = args["name"]
        phone = args["phone"]
        content = args["content"]
        speed = args["speed"]
        accuracy = args["accuracy"]

        feed_back = Feedback(name=name,
                                phone=phone,
                                content=content,
                                speed=speed,
                                accuracy=accuracy)
        feed_back.save()

        return mlab.item2json(Feedback.objects().with_id(feed_back.id))
Exemple #28
0
 def put(self, food_id):
     parser = reqparse.RequestParser()
     parser.add_argument(name="rate", type=float, location="json")
     body = parser.parse_args()
     # name = body.name
     # url = body.url
     # coint_old = body.coint_old
     # coint_new = body.coint_new
     # cout_rate = body.cout_rate
     rate_res = body.rate
     food = Food.objects().with_id(food_id)
     cout_rate = food.cout_rate
     rate = food.rate
     rate_new = (cout_rate * rate + rate_res) / (cout_rate + 1)
     food.update(cout_rate=cout_rate + 1, rate=rate_new)
     add_food = Food.objects().with_id(food_id)
     return mlab.item2json(add_food)
Exemple #29
0
 def post(self, id):
     parser = reqparse.RequestParser()
     parser.add_argument(name="user_id", type=str, location="json")
     parser.add_argument(name="message", type=str, location="json")
     body = parser.parse_args()
     id_user = body["user_id"]
     message = body["message"]
     rage = Rage.objects().with_id(id)
     customer = Customer.objects().with_id(id_user)
     date = datetime.datetime.utcnow() + datetime.timedelta(hours=7)
     comment = Comment(customer=customer,
                       message=message,
                       date=str(date),
                       rage=rage)
     comment.save()
     comment_add = Comment.objects().with_id(comment.id)
     return mlab.item2json(comment_add), 200
Exemple #30
0
 def put(self, id):
     order = Order.objects().with_id(id)
     if order.is_Success != True:
         order.update(set__is_Success=True)
         order_add = Order.objects().with_id(id)
         customer = order["customer"]
         spend = float(order["spend"])
         if customer["total_spend"] is not None:
             spend_user = float(customer["total_spend"])
             total = spend + spend_user
         else:
             total = spend
         customer.update(total_spend=total)
         return mlab.item2json(customer), 200
     else:
         return {
             "message": "đơn hàng đã success rồi còn push lại làm gì?"
         }, 200
Exemple #31
0
    def post(self, id_user):
        args = movieParser.parse_args()
        print(id_user)
        id_user = id_user
        id_movie = args["id_movie"]
        name = args["name"]
        image_link = args["image_link"]
        status = args["status"]

        new_movie = Movie()
        new_movie.id_user = id_user
        new_movie.id_movie = id_movie
        new_movie.name = name
        new_movie.image_link = image_link
        new_movie.status = status

        new_movie.save()
        return mlab.item2json(new_movie)
Exemple #32
0
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument(name="name", type=str, location="json")
        parser.add_argument(name="date_start", type=str, location="json")
        parser.add_argument(name="date_end", type=str, location="json")
        parser.add_argument(name="time_study", type=str, location="json")
        parser.add_argument(name="class_room", type=str, location="json")
        body = parser.parse_args()

        name = body.name
        date_start = body.date_start
        date_end = body.date_end
        time_study = body.time_study
        class_room = body.class_room
        schdule = Schdule(name=name, date_start=date_start, date_end=date_end, time_study=time_study,
                         class_room=class_room)
        schdule.save()
        add_schdule=Schdule.objects().with_id(schdule.id)
        return mlab.item2json(add_schdule)
 def post(self):
     parser = reqparse.RequestParser()
     parser.add_argument(name="name", type=str, location="json")
     parser.add_argument(name="date", type=str, location="json")
     parser.add_argument(name="students", type=list, location="json")
     body = parser.parse_args()
     name = body.name
     date = body.date
     for checkin_res in CheckinClass.objects():
         if checkin_res.name == name:
             if checkin_res.date == date:
                 return {
                     "message": "data existed, you only can add 1request/h"
                 }, 400
     students = body["students"]
     checkin = CheckinClass(name=name, date=date, students=students)
     checkin.save()
     add_checkin = CheckinClass.objects().with_id(checkin.id)
     return mlab.item2json(add_checkin)
    def put(self, cate_id):
        try:
            category = Categoty.objects(cate_id=cate_id).first()
        except Exception:
            return {'message': "this id is wrong"}, 404

        parser = reqparse.RequestParser()
        # parser.add_argument(name="menu_id", type=str, location='json')
        # parser.add_argument(name="cate_id", type=str, location='json')
        parser.add_argument(name="cate_name", type=str, location='json')
        parser.add_argument(name="cate_type", type=str, location='json')
        parser.add_argument(name="cate_order", type=int, location='json')

        body = parser.parse_args()

        # menu_id = body["menu_id"]
        # cate_id = body["cate_id"]
        cate_name = body["cate_name"]
        cate_type = body["cate_type"]
        cate_order = body["cate_order"]

        category.update(
                        set__cate_name=cate_name, set__cate_type=cate_type, set__cate_order=cate_order)
        return mlab.item2json(Categoty.objects().with_id(category.id))
Exemple #35
0
 def get_json(self):
     return mlab.item2json(self)