Esempio n. 1
0
def get_hot_questions():
    parser = reqparse.RequestParser()
    parser.add_argument('offset', type=int, location='json')
    parser.add_argument('size', type=int, location='json')
    args = parser.parse_args()
    # args = request.get_json(force=True)
    offset = args['offset']
    size = args['size']
    if not is_param_ok(offset, size):
        abort(400)
    api = QuestionResource()
    data = api.get_hot_questions(offset, size)
    return to_json(data, True)
Esempio n. 2
0
def get_userinfo(token, id):
    parser = reqparse.RequestParser()
    parser.add_argument('id', type=str)
    args = parser.parse_args()
    user_id = args['id']
    if not is_param_ok(user_id):
        abort(400)
    model = UserResource()
    data = model.get_user_info(user_id)
    if data:
        return to_json(data.toJson(), True)
    else:
        return to_json('User doesn\'t exist')
Esempio n. 3
0
def get_question_detail():
    parser = reqparse.RequestParser()
    parser.add_argument('id', type=int)
    args = parser.parse_args()
    id = args['id']
    if not is_param_ok(id):
        abort(400)
    api = QuestionResource()
    question = api.get_question_detail(id)
    if question:
        return to_json(question.toJson(), True)
    else:
        return to_json('get question detail failed')
Esempio n. 4
0
def get_similar_users():
    parser = reqparse.RequestParser()
    parser.add_argument('offset', type=int)
    parser.add_argument('size', type=int)
    parser.add_argument('keyword', type=str)
    args = parser.parse_args()
    offset = args['offset']
    size = args['size']
    keyword = args['keyword']
    if not is_param_ok(offset, size, keyword):
        abort(400)
    model = UserResource()
    data = model.get_similar_users(keyword, offset, size)
    return to_json(data, True)
Esempio n. 5
0
def get_heard_questions():
    parser = reqparse.RequestParser()
    parser.add_argument('user_id', type=int)
    parser.add_argument('offset', type=int)
    parser.add_argument('size', type=int)
    args = parser.parse_args()
    user_id = args['user_id']
    offset = args['offset']
    size = args['size']
    if not is_param_ok(user_id, offset, size):
        abort(400)
    api = HeardResource()
    data = api.get_user_heard_questions(user_id, offset, size)
    return to_json(data, True)
Esempio n. 6
0
def get_user_list():
    parser = reqparse.RequestParser()
    parser.add_argument('offset', type=int)
    parser.add_argument('size', type=int)
    args = parser.parse_args()
    offset = args['offset']
    size = args['size']
    if not is_param_ok(offset, size):
        abort(400)
    model = UserResource()
    data = model.get_user_list(offset, size)
    if data:
        return to_json(data, True)
    else:
        return to_json('Something wrong happened while querying')
Esempio n. 7
0
def create():
    parser = reqparse.RequestParser()
    parser.add_argument('paypal', type=str)
    parser.add_argument('user_id', type=int)
    args = parser.parse_args()
    paypal = args['paypal']
    user_id = args['user_id']
    if not is_param_ok(paypal, user_id):
        abort(400)
    api = WithdrawResource()
    withdraw = api.create_withdraw(paypal, user_id)
    if withdraw:
        return to_json(withdraw.toJson(), True)
    else:
        return to_json('withdraw failed')
Esempio n. 8
0
def check_user_heard():
    parser = reqparse.RequestParser()
    parser.add_argument('user_id', type=int)
    parser.add_argument('question_id', type=int)
    args = parser.parse_args()
    user_id = args['user_id']
    question_id = args['question_id']
    if not is_param_ok(user_id, question_id):
        abort(400)
    api = HeardResource()
    data = api.check_user_heard_question(user_id, question_id)
    if data:
        return to_json('heard', True)
    else:
        return to_json('unheard', True)
Esempio n. 9
0
def add():
    parser = reqparse.RequestParser()
    parser.add_argument('question_id', type=int)
    parser.add_argument('user_id', type=int)
    args = parser.parse_args()
    question_id = args['question_id']
    user_id = args['user_id']
    if not is_param_ok(question_id, user_id):
        abort(400)
    api = HeardResource()
    heard = api.set_heard_user(question_id, user_id)
    if heard:
        return to_json(heard.toJson(), True)
    else:
        return to_json('add heard user failed')
Esempio n. 10
0
def get_similar_questions():
    parser = reqparse.RequestParser()
    parser.add_argument('offset', type=int)
    parser.add_argument('size', type=int)
    parser.add_argument('keyword', type=str)
    args = parser.parse_args()
    # args = request.get_json(force=True)
    offset = args['offset']
    size = args['size']
    keyword = args['keyword']
    if not is_param_ok(offset, size, keyword):
        abort(400)
    api = QuestionResource()
    data = api.get_similar_questions(keyword, offset, size)
    return to_json(data, True)
Esempio n. 11
0
def get_related_questions():
    parser = reqparse.RequestParser()
    parser.add_argument('type', type=str)
    parser.add_argument('user_id', type=int)
    parser.add_argument('offset', type=int)
    parser.add_argument('size', type=int)
    args = parser.parse_args()
    request_type = args['type']
    user_id = args['user_id']
    offset = args['offset']
    size = args['size']
    if not is_param_ok(request_type, user_id, offset, size):
        abort(400)
    api = QuestionResource()
    data = api.get_related_questions(request_type, user_id, offset, size)
    return to_json(data, True)
Esempio n. 12
0
def answer_question():
    parser = reqparse.RequestParser()
    parser.add_argument('id', type=int)
    parser.add_argument('url', type=str)
    parser.add_argument('length', type=int)
    args = parser.parse_args()
    id = args['id']
    url = args['url']
    length = args['length']
    if not is_param_ok(id, url, length):
        abort(400)
    api = QuestionResource()
    question = api.answer_question(id, length, url)
    if question:
        return to_json(question.toJson(), True)
    else:
        return 'answer question failed'
Esempio n. 13
0
def create_question():
    parser = reqparse.RequestParser()
    parser.add_argument('content', type=str)
    parser.add_argument('price', type=float)
    parser.add_argument('public', type=int)
    parser.add_argument('ask_uuid', type=int)
    parser.add_argument('answer_uuid', type=int)
    args = parser.parse_args()
    content = args['content']
    price = args['price']
    public = args['public']
    asker = args['ask_uuid']
    answer = args['answer_uuid']
    if not is_param_ok(content, price, public, asker, answer):
        abort(400)
    api = QuestionResource()
    question = api.create_question(content=content, price=price, public=public, ask_uuid=asker, answer_uuid=answer)
    if question:
        return to_json(question.toJson(), True)
    else:
        return to_json('create the question failed')
Esempio n. 14
0
def update_userinfo():
    parser = reqparse.RequestParser()
    parser.add_argument('id', type=str)
    parser.add_argument('title', type=str)
    parser.add_argument('introduction', type=str)
    parser.add_argument('price', type=float)
    args = parser.parse_args()
    user_id = args['id']
    title = args['title']
    introduction = args['introduction']
    price = args['price']

    model = UserResource()
    if not is_param_ok(user_id, title, introduction, price):
        abort(400)
    data = model.update_user_info(user_id,
                                  title=title,
                                  introduction=introduction,
                                  price=price)
    if data:
        return to_json(data.toJson(), True)
    else:
        return to_json('User doesn\'t exist')
Esempio n. 15
0
def user_login():
    parser = reqparse.RequestParser()
    parser.add_argument('username', type=str)
    parser.add_argument('third_id', type=str)
    parser.add_argument('icon', type=str)
    parser.add_argument('device_token', type=str)
    args = parser.parse_args()
    username = args['username']
    third_party_uuid = args['third_id']
    icon = args['icon']
    device_token = args['device_token']

    if not is_param_ok(username, third_party_uuid, icon):
        abort(400)
    model = UserResource()
    new_user_data = model.login(third_party_uuid, username, icon, device_token)

    if new_user_data:
        data = new_user_data.toJson()
        token = gen_token(new_user_data.id)
        data.update(token=token)
        return to_json(data, True)
    else:
        return to_json('login failed')