Exemple #1
0
def user_update_profile(email, about, name):
    db_funcs.db_exist(entity="Users", entity_attr="email", attr_value=email)
    db_funcs.db_insert_or_delete_or_update(
        'UPDATE Users'
        ' SET about = %s, name = %s'
        ' WHERE email = %s',
        (about, name, email, )
    )
    return user_details(email)
Exemple #2
0
def thread_update(thread_id, slug, message):
    db_funcs.db_exist(entity="Threads", entity_attr="id", attr_value=thread_id)
    db_funcs.db_insert_or_delete_or_update(
        'UPDATE Threads'
        ' SET slug = %s, message = %s'
        ' WHERE id = %s',
        (slug, message, thread_id, )
    )
    return thread_details(thread_id=thread_id, related=[])
Exemple #3
0
def post_update(post_id, message):
    db_funcs.db_exist(entity="Posts", entity_attr="id", attr_value=post_id)
    db_funcs.db_insert_or_delete_or_update(
        'UPDATE Posts'
        ' SET message = %s'
        ' WHERE id = %s',
        (message, post_id, )
    )
    return post_details(post_id=post_id, related=[])
Exemple #4
0
def post_remove_or_restore(post_id, status):
    db_funcs.db_exist(entity="Posts", entity_attr="id", attr_value=post_id)
    db_funcs.db_insert_or_delete_or_update(
        "UPDATE Posts "
        "SET isDeleted = %s "
        "WHERE id = %s",
        (status, post_id, )
    )
    post_response = {"post": post_id}
    return post_response
Exemple #5
0
def forum_create(name, short_name, user):
    db_funcs.db_exist(entity="Users", entity_attr="email", attr_value=user)
    forum = forum_get(short_name)
    if not len(forum):
        db_funcs.db_insert_or_delete_or_update(
            'INSERT INTO Forums (name, short_name, user) '
            'VALUES (%s, %s, %s)',
            (name, short_name, user, )
        )
        forum = forum_get(short_name)
    return forum_describe(forum[0])
Exemple #6
0
def thread_remove_or_restore(thread_id, is_deleted):
    db_funcs.db_exist(entity="Threads", entity_attr="id", attr_value=thread_id)
    db_funcs.db_insert_or_delete_or_update(
        "UPDATE Threads"
        " SET isDeleted = %s"
        " WHERE id = %s",
        (is_deleted, thread_id, )
    )
    thread_response = {
        "thread": thread_id
    }
    return thread_response
def user_follow(follower_email, followee_email):
    if follower_email == followee_email:
        raise Exception("followers: follower_email=followee_email=" + follower_email)
    db_funcs.db_exist(entity="Users", entity_attr="email", attr_value=follower_email)
    db_funcs.db_exist(entity="Users", entity_attr="email", attr_value=followee_email)
    follows = follower_select(follower_email, followee_email)
    if not len(follows):
        db_funcs.db_insert_or_delete_or_update(
            'INSERT INTO Followers (follower, followee)'
            ' VALUES (%s, %s)',
            (follower_email, followee_email, )
        )
    return db_users_func.user_details(follower_email)
def user_unfollow(follower_email, followee_email):
    if follower_email == followee_email:
        raise Exception("followers: follower_email=followee_email=" + follower_email)
    db_funcs.db_exist(entity="Users", entity_attr="email", attr_value=follower_email)
    db_funcs.db_exist(entity="Users", entity_attr="email", attr_value=followee_email)
    follows = follower_select(follower_email, followee_email)
    if len(follows):
        db_funcs.db_insert_or_delete_or_update(
            'DELETE'
            ' FROM Followers'
            ' WHERE id= %s',
            (follows[0][0], )
        )
    else:
        raise Exception("followers: following not found")
    return db_users_func.user_details(follower_email)
Exemple #9
0
def user_create(email, username, about, name, optional):
    is_anonymous = 0
    if "isAnonymous" in optional:
        is_anonymous = optional["isAnonymous"]
    try:
        user = user_select(email)
        if not len(user):
            db_funcs.db_insert_or_delete_or_update(
                'INSERT INTO Users (email, about, name, username, isAnonymous)'
                ' VALUES (%s, %s, %s, %s, %s)',
                (email, about, name, username, is_anonymous, )
            )
            user = user_select(email)
    except Exception as e:
        raise Exception(e.message)
    return user_describe(user[0])
def thread_subscribe(sub_email, thread_id):
    db_funcs.db_exist(entity="Users", entity_attr="email", attr_value=sub_email)
    db_funcs.db_exist(entity="Threads", entity_attr="id", attr_value=thread_id)
    subscription = subscription_select(sub_email, thread_id)
    if not len(subscription):
        db_funcs.db_insert_or_delete_or_update(
            'INSERT INTO Subscriptions (thread, user)'
            ' VALUES (%s, %s)',
            (thread_id, sub_email, )
        )
        subscription = subscription_select(sub_email, thread_id)
    subscription_response = {
        "thread": subscription[0][0],
        "user": subscription[0][1]
    }
    return subscription_response
Exemple #11
0
def thread_vote(thread_id, vote):
    db_funcs.db_exist(entity="Threads", entity_attr="id", attr_value=thread_id)
    if vote == -1:
        db_funcs.db_insert_or_delete_or_update(
            "UPDATE Threads"
            " SET dislikes = dislikes + 1, points = points - 1"
            " WHERE id = %s",
            (thread_id, )
        )
    else:
    # if vote == 1:
        db_funcs.db_insert_or_delete_or_update(
            "UPDATE Threads"
            " SET likes = likes + 1, points = points + 1"
            " WHERE id = %s",
            (thread_id, )
        )
    return thread_details(thread_id=thread_id, related=[])
Exemple #12
0
def post_vote(post_id, vote):
    db_funcs.db_exist(entity="Posts", entity_attr="id", attr_value=post_id)
    if vote == -1:
        db_funcs.db_insert_or_delete_or_update(
            "UPDATE Posts"
            " SET dislikes=dislikes+1, points=points-1"
            " WHERE id = %s",
            (post_id, )
        )
    else:
    # if vote == 1:
        db_funcs.db_insert_or_delete_or_update(
            "UPDATE Posts"
            " SET likes=likes+1, points=points+1"
            " WHERE id = %s",
            (post_id, )
        )
    return post_details(post_id=post_id, related=[])
def thread_unsubscribe(sub_email, thread_id):
    #db_funcs.db_exist(entity="Users", entity_attr="email", attr_value=sub_email)
    #db_funcs.db_exist(entity="Threads", entity_attr="id", attr_value=thread_id)
    subscription = subscription_select(sub_email, thread_id)
    if not len(subscription):
        raise Exception("thread: user " + sub_email + " don't subscribe thread #" + str(thread_id))
    db_funcs.db_insert_or_delete_or_update(
        'DELETE'
        ' FROM Subscriptions'
        ' WHERE user = %s'
        ' AND thread = %s',
        (sub_email, thread_id, )
    )
    subscription_response = {
        "thread": subscription[0][0],
        "user": subscription[0][1]
    }
    return subscription_response
Exemple #14
0
def thread_create(forum, title, is_closed, user, date, message, slug, optional):
    db_funcs.db_exist(entity="Users", entity_attr="email", attr_value=user)
    db_funcs.db_exist(entity="Forums", entity_attr="short_name", attr_value=forum)
    is_deleted = 0
    if "isDeleted" in optional:
        is_deleted = optional["isDeleted"]
    thread = thread_select(slug)
    if not len(thread):
        db_funcs.db_insert_or_delete_or_update(
            'INSERT INTO Threads (forum, title, isClosed, user, date, message, slug, isDeleted)'
            ' VALUES (%s, %s, %s, %s, %s, %s, %s, %s)',
            (forum, title, is_closed, user, date, message, slug, is_deleted, )
        )
        thread = thread_select(slug)
    thread_response = thread_describe(thread[0])
    del thread_response["dislikes"]
    del thread_response["likes"]
    del thread_response["points"]
    del thread_response["posts"]
    return thread_response