Example #1
0
def get_menu_by_id(restaurant_id: int = Query(...)) -> Dict:
    mongo_client = MongoClient(collection='menus')
    result = list(mongo_client.db.find({'restaurant_id': restaurant_id}))
    print(result)
    mongo_client.close()
    json_response = json.loads(json_util.dumps(result))
    return json_response
Example #2
0
def get_rating_tags_info(restaurant_id: int = Query(...)) -> List:
    mongo_client = MongoClient(collection='ratings')
    result = list(
        mongo_client.db.find({
            'restaurant_id': restaurant_id
        }).sort('_id', pymongo.DESCENDING))
    detail = [i['tags'] for i in result]
    mongo_client.close()
    # 一定要处理objectid,默认json无法序列化的
    json_response = json.loads(json_util.dumps(detail))
    return json_response
Example #3
0
def cart_checkout(come_from: str = Body(...),
                  entities: List = Body(...),
                  geohash: str = Body(...),
                  restaurant_id: int = Body(...)) -> Dict:
    """

    :param come_from:
    :param entities:
    :param geohash:
    :param restaurant_id:
    :return:
    """

    # todo 后续优化封装成一个专门的函数处理
    # 1 获取payments  有新任务断更了
    mongo_client = MongoClient(collection='payments')
    payment = list(mongo_client.db.find({}).sort('_id', pymongo.DESCENDING))
    payments = json.loads(json_util.dumps(payment))
    mongo_client.close()
    # 2、获取cart_id
    mongo_client2 = MongoClient(collection='ids')
    result_ids = mongo_client2.db.find_one()
    # 先获取cart_id
    cart_id = result_ids['cart_id'] + 1
    # 然后更新cart_id
    result_ids['cart_id'] = cart_id
    mongo_client2.db.update({}, result_ids)
    mongo_client2.close()
    # 2、获取cart_id

    return {'hello,world'}
Example #4
0
def shopping_restaurants(
    latitude: float = Query(None),
    longitude: float = Query(None),
    offset: int = 0,
    limt: int = 20,
    extras: str = Query(None),
    keyword: str = Query(None),
    restaurant_category_ids: str = Query(None),
    order_by: str = Query(None),
    delivery_mode: str = Query(None)
) -> List:
    mongo_client = MongoClient(collection='shops')
    result = list(mongo_client.db.find())
    mongo_client.close()
    # 一定要处理objectid,默认json无法序列化的
    json_response = json.loads(json_util.dumps(result))
    return json_response
Example #5
0
def index_entry() -> List:
    """

    :param type:
    :param city_id:
    :param keyword:
    :return:
    """
    # 根据id排序后返回
    # entry.entry_info.sort(key=lambda k: k.get('id'))
    # return entry.entry_info
    mongo_client = MongoClient(collection='entries')
    result = list(mongo_client.db.find())
    mongo_client.close()
    # 一定要处理objectid,默认json无法序列化的
    json_response = json.loads(json_util.dumps(result))
    return json_response
Example #6
0
def get_restaurant_by_id(id: int = Query(...)) -> Dict:
    mongo_client = MongoClient(collection='shops')
    result = mongo_client.db.find_one({'id': id})
    mongo_client.close()
    json_response = json.loads(json_util.dumps(result))
    return json_response