Ejemplo n.º 1
0
def create_post(author_id, title, description, body):
    session = Session()
    try:
        post = Post(author_id, title, description, body,
                    strftime("%Y-%m-%dT%H:%M:%S", gmtime()))
        session.add(post)
        session.commit()
        return successful(post.id)
    except:
        session.rollback()
        return internal_server_error
    finally:
        session.close()
Ejemplo n.º 2
0
def update_post(title, description, body, post_id):
    session = Session()
    try:
        session.query(Post).filter(Post.id == post_id).update({
            'title': title,
            'description': description,
            'body': body
        })

        session.commit()
        return successful('Post {} updated'.format(post_id))
    except:
        session.rollback()
        return internal_server_error
    finally:
        session.close()
Ejemplo n.º 3
0
def new_user(email, name, password_encrypted, token):
    session = Session()
    try:
        user = User(email, name, password_encrypted, token)
        session.add(user)
        session.commit()
        return successful({
            'id': user.id,
            'email': user.email,
            'password_encrypted': user.password_encrypted,
            'token': user.token,
        })
    except:
        session.rollback()
        return internal_server_error
    finally:
        session.close()
Ejemplo n.º 4
0
def delete_post(post_id):
    session = Session()
    try:
        session.query(Post).filter(Post.id == post_id).delete()
        session.commit()

        image_path = image_format(post_id)

        if os.path.isfile(image_path):
            os.remove(image_path)

        return successful('Post {} deleted'.format(post_id))
    except:
        session.rollback()
        return internal_server_error
    finally:
        session.close()