Esempio n. 1
0
def put_user():
    name = request.form.get("name")
    if not name:
        return status_response(403, "Missing 'name'")

    user = User(name=name)
    db.session.add(user)

    try:
        db.session.commit()
    except sqlalchemy.exc.SQLAlchemyError as e:
        print(e)
        return status_response(500, "Cannot Write")

    return jsonify(row_dictify(user))
Esempio n. 2
0
def get_user_posts(user_id):
    user = User.query.filter_by(id=user_id).first()

    if not user:
        return status_response(404, "Not Found")

    return jsonify([row_dictify(post) for post in user.posts])
Esempio n. 3
0
def get_user_likes(user_id):
    user = User.query.filter_by(id=user_id).first()

    if not user:
        return status_response(404, "Not Found")

    return jsonify([row_dictify(like) for like in user.likes])
Esempio n. 4
0
def get_user(user_id):
    user = User.query.filter_by(id=user_id).first()

    if not user:
        return status_response(404, "Not Found")

    return jsonify(row_dictify(user))
Esempio n. 5
0
def get_post_likes(post_id):
    post = Post.query.filter_by(id=post_id).first()

    if not post:
        return status_response(404, "Not Found")

    return jsonify([row_dictify(like) for like in post.likes])
Esempio n. 6
0
def get_post(post_id):
    post = Post.query.filter_by(id=post_id).first()

    if not post:
        return status_response(404, "Not Found")

    return jsonify(row_dictify(post))
Esempio n. 7
0
def get_like(like_id):
    like = Like.query.filter_by(id=like_id).first()

    if not like:
        return status_response(404, "Not Found")

    return jsonify(row_dictify(like))
Esempio n. 8
0
def put_post():
    text = request.form.get("text")
    if not text:
        return status_response(403, "Missing 'text'")

    user_id = request.form.get("user_id")
    if not user_id:
        return status_response(403, "Missing 'user_id'")

    post = Post(text=text, user_id=user_id)
    db.session.add(post)

    try:
        db.session.commit()
    except sqlalchemy.exc.SQLAlchemyError as e:
        print(e)
        return status_response(500, "Cannot Write")

    return jsonify(row_dictify(post))
Esempio n. 9
0
def page_not_found(e):
    return status_response(404, "Not Found")