def post(self): market_id = request.json['market_id'] reserve_list = request.json['menu'] order_time = request.json['time'] finder = Market_Model.objects(market_id=market_id).first() if finder is None: return abort(409) while True: uuid = random.randrange(11111, 99999) if Orderlist_Model.objects(order_uuid=uuid).first() is None: break for Rmenu in reserve_list: flag = True for menu in finder['menu']: if Rmenu['name'] == menu['menu_name']: flag = False if flag: abort(409) Sum = 0 for s in reserve_list: Sum += s['price'] user = User_Model.objects(id=get_jwt_identity()).first() if user['point'] < Sum: abort(409) user.update(point=user['point'] - Sum) user.save() owner = User_Model.objects(id=Market_Model.objects( market_id=market_id).first()['owner_id']).first() owner.update(point=owner['point'] + Sum) Orderlist_Model(order_uuid=uuid, market_id=market_id, customer_id=get_jwt_identity(), order=reserve_list, order_time=order_time).save() return "", 200
def get(self, market_id): res = [] order_list = Orderlist_Model.objects(market_id = market_id).all() market = Market_Model.objects(market_id = market_id).first() if not get_jwt_identity() == market['owner_id']: abort(409) for order in order_list: menu_list = [] for menu in order['order']: menu_list.append( { "menu_name":menu["name"], "menu_price":menu['price'] }) res.append( { "order_id": order['order_uuid'], "order_time":order['order_time'], "customer": order['customer_id'], "menu_list": menu_list }) return { "order_list": res }, 200
def delete(self): finder = User_Model.objects(id=get_jwt_identity()).first() markets = Market_Model.objects(owner_id=get_jwt_identity()).all() for market in markets: market.delete() finder.delete() return '', 200
def delete(self): delete_market_uuid = request.json['market_id'] finder = Market_Model.objects(market_id=delete_market_uuid).first() if not get_jwt_identity() == finder['owner_id']: abort(409) finder.delete() return "", 200
def get(self, market_uuid): uuid = market_uuid finder = Market_Model.objects(market_id=uuid).first() if finder is None: return abort(409) return { "market_id": int(uuid), "market_name": finder['name'], "image": finder['image'], "menu": finder['menu'], }, 200
def post(self): register_name = request.json['name'] register_loc = request.json['location'] register_num = request.json['tel_num'] register_image = request.json['image'] owner_id = get_jwt_identity() if User_Model.objects(id = get_jwt_identity()).first()['user_type'] == 0: abort(409) finder = Market_Model.objects(location=register_loc).first() if finder is not None: return abort(409) finder = Market_Model.objects(telephone_num = register_loc).first() if finder is not None: return abort(409) while True: uuid = random.randrange(11111, 99999) if Market_Model.objects(market_id=uuid).first() is None: break Market_Model( owner_id = owner_id, name = register_name, location = register_loc, telephone_num = register_num, market_id = uuid, image = register_image, menu = [] ).save() return '', 201
def get(self): markets = Market_Model.objects().all() market_list = [] a = 0 for market in markets: market_list.append({ "name": market['name'], "location": market['location'], "tel_num": market['telephone_num'], "market_id": market['market_id'] }) return {"market_list": market_list}, 201
def get(self): res = [] order_list = Orderlist_Model.objects( customer_id=get_jwt_identity()).all() for order in order_list: res.append({ "order_id": order['order_uuid'], "order_time": order['order_time'], "market_name": Market_Model.objects( market_id=order['market_id']).first()['name'], "main_menu": order['order'][0]['name'] }) return {"order_list": res}, 200
def delete(self, market_uuid): uuid = market_uuid finder = Market_Model.objects(market_id=uuid).first() if not finder['owner_id'] == get_jwt_identity(): abort(406) menu_name = request.json['menu_name'] menu_list = list() for i in finder['menu']: if not i['menu_name'] == menu_name: menu_list.append(i) finder.update(menu=menu_list) finder.save() return '', 201
def get(self, order_id): res = [] order_list = Orderlist_Model.objects(order_uuid=order_id).first() market_name = Market_Model.objects( market_id=order_list['market_id']).first() if not get_jwt_identity() == order_list['customer_id']: abort(409) for order in order_list['order']: res.append({ "menu_name": order["name"], "menu_price": order['price'], }) return { "market_name": market_name['name'], "order_time": order_list['order_time'], "menu_list": res }, 200
def get(self): res = [] finder = Market_Model.objects(owner_id=get_jwt_identity()).all() user = User_Model.objects(id=get_jwt_identity()).first() if finder is None: abort(409) if user['user_type'] == 0: abort(409) for market in finder: res.append({ "name": market['name'], "image": market['image'], "location": market['location'], "tel_num": market['telephone_num'], "market_id": market['market_id'] }) return {"markets": res}, 201
def post(self, market_uuid): uuid = market_uuid finder = Market_Model.objects(market_id=uuid).first() if not finder['owner_id'] == get_jwt_identity(): abort(406) menu_name = request.json['menu_name'] menu_price = request.json['menu_price'] menu_des = request.json['menu_des'] if menu_name == None or menu_price == None: abort(409) finder.menu.append({ 'menu_name': menu_name, 'menu_price': menu_price, 'menu_des': menu_des }) finder.save() return '', 201
def post(self): market_name = list(request.json['market'].split()) find = list() market_list = list() name_markets_list = list() real_markets_list = list() a = 0 flag = False flag_num = 1 for m in market_name: find.append(re.compile('.*' + m + '.*')) try: find[1] except: flag = True if flag: for i in find: name_markets = Market_Model.objects(Q(name=i) | Q(location=i)).all() for market in name_markets: market_list.append({ "name": market['name'], "location": market['location'], "tel_num": market['telephone_num'], "market_id": market['market_id'] }) return {"market_list": market_list}, 201 else: for i in find: if not flag: name_markets_list.append( Market_Model.objects(location=i).all()) flag_num += 1 if not name_markets_list[0]: del name_markets_list[0] name_markets_list.append( Market_Model.objects(name=i).all()) flag_num += 1 if flag: if flag_num == 2: for j in name_markets_list[0]: real_markets_list.append( Market_Model.objects( Q(market_id=j['market_id']) & Q(name=i)).all()) if flag_num == 3: for j in name_markets_list[0]: real_markets_list.append( Market_Model.objects( Q(market_id=j['market_id']) & Q(location=i)).all()) flag = True for return_market_list in real_markets_list: for market in return_market_list: market_list.append({ "name": market['name'], "location": market['location'], "tel_num": market['telephone_num'], "market_id": market['market_id'] }) return {"market_list": market_list}, 201