Esempio n. 1
0
def update():
    con = connect()
    request_data = request.json
    required_data = ["post", "message"]
    try:
        check_data(data=request_data, required=required_data)
        post = query.update_post(con, request_data["post"], request_data["message"])
    except Exception as e:
        con.close()
        return json.dumps({"code": 1, "response": (e.message)})
    con.close()
    return json.dumps({"code": 0, "response": post})
Esempio n. 2
0
def details():
    con = connect()
    request_data = get_json(request)
    required_data = ["user"]
    try:
        check_data(request_data, required_data)
        user = query.show_user(connect = con, email = request_data["user"])
    except Exception as e:
        con.close()
        return json.dumps({"code" : 1, "response": (e.message)})
    con.close()
    return json.dumps({"code": 0, "response": user})
Esempio n. 3
0
def unfollow():
    con = connect()
    request_data = get_json(request)
    required_data = ["follower", "followee"]   
    try:
        check_data(request_data, required_data)
        user = query.unfollow_user(con, request_data["follower"], request_data["followee"])
    except Exception as e:
        con.close()        
        return json.dumps({"code" : 1, "response": (e.message)})
    con.close()
    return json.dumps({"code": 0, "response": user })
Esempio n. 4
0
def list_users():
    con = connect()
    content = get_json(request)
    required_data = ["forum"]    
    optional = intersection(content, ["limit", "order", "since"])    
    try:
        check_data(content, required_data)
        users_l = query.users_list(con, content["forum"], optional)
    except Exception as e:
         con.close()
         return json.dumps({"code": 1, "response": (e.message)})
    con.close()
    return json.dumps({"code": 0, "response": users_l})
Esempio n. 5
0
def list_following():
    con = connect()
    request_data = get_json(request)
    required_data = ["user"]
    followers_param = intersection(request=request_data, values=["limit", "order", "since_id"])
    try:
        check_data(data=request_data, required=required_data)
        follower_l = query.followers_list(connect=con, email=request_data["user"], type="follow", params=followers_param)
    except Exception as e:
        con.close()
        return json.dumps({"code": 1, "response": (e.message)})
    con.close()
    return json.dumps({"code": 0, "response": follower_l})
Esempio n. 6
0
def user_posts():
    con = connect()
    content = get_json(request)
    required_data = ["user"]
    optional = intersection(content, ["limit", "order", "since"])    
    try:
        check_data(content, required_data)
        posts_l = posts.posts_list(con, "user", optional, content["user"], [])
    except Exception as e:
         con.close()
         return json.dumps({"code": 1, "response": (e.message)})
    con.close()
    return json.dumps({"code": 0, "response": posts_l})
Esempio n. 7
0
def list_threads():
    con = connect()
    content = get_json(request)
    required_data = ["forum"]
    related = related_exists(content)
    optional = intersection(content, ["limit", "order", "since"])
    try:
        check_data(content, required_data)
        threads_l = threads.threads_list(con, "forum", optional, content["forum"], related)
    except Exception as e:
        con.close()
        return json.dumps({"code": 1, "response": (e.message)})
    con.close()
    return json.dumps({"code": 0, "response": threads_l})
Esempio n. 8
0
def details():
    con = connect()
    content = get_json(request)
    required_data = ["post"]
    related = related_exists(content)
    if 'post' in related:
        con.close()
        return json.dumps({"code": 3, "response": "error"})
    try:
        check_data(content, required_data)
        post = query.show_post(con, content["post"], related)
    except Exception as e:
        con.close()
        return json.dumps({"code": 1, "response": (e.message)})
    con.close()
    return json.dumps({"code": 0, "response": post})
Esempio n. 9
0
def restore():
    con = connect()     
    content = request.json
    required_data = ["post"]
    try:
        check_data(content, required_data)
        post = query.restore_post(con , content["post"])       
    except Exception as e:
        con.close()
        if e.message == "Exist":
            return json.dumps({"code": 4, "response": (e.message)}) 
        if e.message == "KeyError":
            return json.dumps({"code": 3, "response": (e.message)}) 
        if e.message == "ValueError":
            return json.dumps({"code": 2, "response": (e.message)}) 
        return json.dumps({"code": 1, "response": (e.message)})
    con.close()    
    return json.dumps({"code": 0, "response": post})
Esempio n. 10
0
def create():    
    con = connect()
    content = request.json
    required_data = ["name", "short_name", "user"]    
    try:
        check_data(content, required_data)
        forum = query.save_forum(con, content["name"], content["short_name"], content["user"])
    except Exception as e:
        con.close()
        if e.message == "Exist":
            return json.dumps({"code": 4, "response": (e.message)}) 
        if e.message == "KeyError":
            return json.dumps({"code": 3, "response": (e.message)})
        if e.message == "ValueError":
            return json.dumps({"code": 2, "response": (e.message)})
        return json.dumps({"code": 1, "response": (e.message)})  
    con.close()
    return json.dumps({"code": 0, "response": forum})
Esempio n. 11
0
def update():
    con = connect()
    request_data = request.json
    required_data = ["user", "name", "about"]
    try:
        check_data(data=request_data, required=required_data)
        user = query.update_user(connect=con,email=request_data["user"], name=request_data["name"], about=request_data["about"])
    except Exception as e:
        con.close()
        if e.message == "Exist":
            return json.dumps({"code": 4, "response": (e.message)}) 
        if e.message == "KeyError":
            return json.dumps({"code": 3, "response": (e.message)}) 
        if e.message == "ValueError":
            return json.dumps({"code": 2, "response": (e.message)}) 
        return json.dumps({"code": 1, "response": (e.message)})
    con.close()
    return json.dumps({"code": 0, "response": user})
Esempio n. 12
0
def create():
    con = connect()     
    content = request.json
    required_data = ["date", "thread", "message", "user", "forum"]
    optional = intersection(content, ["parent", "isApproved", "isHighlighted", "isEdited", "isSpam", "isDeleted"])
    try:
        check_data(content, required_data)
        post = query.save_post(con , content["date"], content["thread"], content["message"], content["user"], content["forum"], optional)
    except Exception as e:
        con.close()
        if e.message == "Exist":
            return json.dumps({"code": 4, "response": (e.message)}) 
        if e.message == "KeyError":
            return json.dumps({"code": 3, "response": (e.message)}) 
        if e.message == "ValueError":
            return json.dumps({"code": 2, "response": (e.message)}) 
        return json.dumps({"code": 1, "response": (e.message)})
    con.close()    
    return json.dumps({"code": 0, "response": post})
Esempio n. 13
0
def create():
    con = connect()     
    content = request.json
    required_data = ["username", "about", "name", "email"]
    optional = intersection(request = content, values=["isAnonymous"])
    try:
        check_data(data=content, required=required_data)
        user = query.save_user(connect = con , username = content["username"], about = content["about"],name =  content["name"], email =content["email"], optional = optional)
    except Exception as e:        
        con.close()
        if e.message == "Exist":            
            return json.dumps({"code": 5, "response": (e.message)}) 
        if e.message == "KeyError":            
            return json.dumps({"code": 3, "response": (e.message)}) 
        if e.message == "ValueError":            
            return json.dumps({"code": 2, "response": (e.message)}) 
                    
        return json.dumps({"code": 1, "response": (e.message)})
    con.close()    
    return json.dumps({"code": 0, "response": user})