def post_comment_delete(comment_id): comment = get_comment_by_comment_id(comment_id) if user_verifying() == comment.user_id or is_admin(user_verifying()): db_delete(comment) db_commit() return jsonify(comment) else: return jsonify("You're not allowed to do this action.")
def user_delete_by_username(username): user = get_user_by_username(username) if user_verifying() == user.user_id or is_admin(user_verifying()): db_delete(user) db_commit() return jsonify(user) else: return jsonify("You're not allowed to do this action.")
def post_delete(post_id): post = PostModel.query.filter(user_verifying() == PostModel.user_id and post_id == PostModel.post_id).first() if user_verifying() == post.user_id or is_admin(user_verifying()): db_delete(post) db_commit() return jsonify(post) else: return jsonify("You're not allowed to do this action.")
def posts_comment_update(post_id): post = get_one_comment(post_id) comment = get_spesific_comment(user_verifying(), post) if user_verifying() == comment.user_id or is_admin(user_verifying()): comment_text = request.json["comment_text"] comment.comment_text = comment_text db_commit() return jsonify(comment) else: return jsonify("You're not allowed to do this action.")
def post_update(user_id, post_id): post = PostModel.query.filter(user_id == PostModel.user_id and post_id == PostModel.post_id).first() post_text = request.json["post_text"] if user_verifying() == post.user_id or is_admin(user_verifying()): post.post_text = post_text db_commit() return jsonify(post) else: return jsonify("You're not allowed to do this.")
def points_to_post(post_id): post = get_posts_by_post_id(post_id) point = request.json["point"] if user_verifying() == post.user_id: return jsonify("You can't set points to your post.") else: if int(point) >= 0 or int(point) <= 10: user_id = user_verifying() point_post = PostPointModel(user_id, post_id, int(point)) db_add(point_post) db_commit() return jsonify(point_post) else: return jsonify("You have to set points between 0 and 10.")
def user_update(username): user = get_user_by_username(username) if user.user_id == user_verifying() or is_admin(user_verifying()): username = request.json['username'] password = request.json['password'] email = request.json['email'] user.email = email user.username = username user.password_hash = password db_commit() return jsonify(user) else: return jsonify("You're not allowed to do this action.")
def add_post(): user_id = user_verifying() post_text = request.json["post_text"] new_post = PostModel(post_text, user_id) db_add(new_post) db_commit() return jsonify(new_post)
def points_to_comment(comment_id): comment = get_comment_by_comment_id(comment_id) if user_verifying() == comment.user_id: return jsonify("You can't set points to your comment.") else: points = request.json["points"] if 0 <= int(points) <= 10: user_id = user_verifying() post_id = comment.post_id comment_id = comment.comment_id point_comment = CommentPointModel(user_id, post_id, comment_id, int(points)) db_add(point_comment) db_commit() return jsonify(point_comment) else: return jsonify("You have to set points between 0 and 10.")
def add_comment_to_post(post_id): user_id = user_verifying() post = get_posts_by_post_id(post_id) comment_text = request.json["comment_text"] parent_id = None new_comment = CommentModel(user_id, post.post_id, comment_text, parent_id) db_add(new_comment) db_commit() return jsonify(new_comment)
def set_admin(): if is_admin(user_verifying()): user_id = request.json["user_id"] role_id = request.json["role_id"] user = get_user_by_user_id(user_id) user.role_id = role_id db_commit() else: return jsonify("You're not allowed to do this")
def add_comment_to_comment(comment_id): user_id = user_verifying() post = get_posts_by_user_id(user_id) post_id = post.post_id parent_id = comment_id comment_text = request.json["comment_text"] comment = CommentModel(user_id, post_id, comment_text, parent_id) db_add(comment) db_commit() return jsonify("Request done.")
def point_to_user(username): user = get_user_by_username(username) if user_verifying() == user.user_id: return jsonify("You can't set points to yourself.") else: points = request.json["point"] if 0 <= int(points) <= 10: user_id = user.user_id point_user = UserPointModel(user_id, int(points)) db_add(point_user) db_commit() return jsonify(point_user) else: return jsonify("You have to set points between 0 and 10.")
def logged_users_post(): my_post = get_posts_by_user_id(user_verifying()) result = posts_schema.dump(my_post) return jsonify(result.data)
def get_logged_user(): spesific_user = get_user_by_user_id(user_verifying()) result = user_schema.dump(spesific_user) return jsonify(result.data)