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])
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))
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])
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])
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))
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))
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))
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))
def get_all_user(): user_list = User.query.all() return jsonify([row_dictify(user) for user in user_list])
def get_all_post(): post_list = Post.query.all() return jsonify([row_dictify(post) for post in post_list])
def get_all_like(): like_list = Like.query.all() return jsonify([row_dictify(like) for like in like_list])