Ejemplo n.º 1
0
def get_user_info(user_id):
    """
    Get user info function
        GET:
            no data
        Response json format:
            {'username': username, 'email': email}
        If the user is not exist, return error code 400
    """
    user = User.query.get(user_id)
    if user is None:
        return user_not_exist_by_id(user_id)
    return jsonify(username=user.username, email=user.email)
Ejemplo n.º 2
0
def add_friend(user_id):
    """
    Add friend function
        POST:
            no data
        Response 200 if success
        If the user is not exist, return error code 406
    """
    from_user = g.user
    if from_user is None:
        pass
    to_user = User.query.get(user_id)
    if to_user is None:
        return user_not_exist_by_id(user_id)

    # add friend
    from_user.add_friend(to_user)
    return Response("add friend %s" % to_user.username, status=200)
Ejemplo n.º 3
0
def launch_talk(talk_to_user_id):
    """
    Launch a new talk function,
    for current logined user want to talk to user for _user_id
        POST:
            no data
        Response 200 if success
        If the user is not exist return error code 400
        If the user is not both online, return 406
    """
    user = g.user
    if user is None:
        pass
    talk_to_user = User.query.get(talk_to_user_id)
    if talk_to_user is None:
        return user_not_exist_by_id(talk_to_user_id)
    if user.id not in online_users.get_online_users():
        return Response("User %s is not online now" % user.username, 406)
    if talk_to_user_id not in online_users.get_online_users():
        return Response("User %s is not online now" % talk_to_user.username, 406)
    talk_manager.new_talk(user.id, talk_to_user_id)
    return Response("launch talk to %s" % talk_to_user.username, 200)