Example #1
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])
Example #2
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))
Example #3
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])
Example #4
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])
Example #5
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))
Example #6
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))
Example #7
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))
Example #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))
Example #9
0
def get_all_user():
    user_list = User.query.all()

    return jsonify([row_dictify(user) for user in user_list])
Example #10
0
def get_all_post():
    post_list = Post.query.all()

    return jsonify([row_dictify(post) for post in post_list])
Example #11
0
def get_all_like():
    like_list = Like.query.all()

    return jsonify([row_dictify(like) for like in like_list])