def get_project_post(id): limit = request.args.get('limit') offset = request.args.get('offset') if limit is not None and not function.isInt(limit): return jsonify({"error": "limit is not an integer"}), 400 if offset is not None and not function.isInt(offset): return jsonify({"error": "offset is not an integer"}), 400 dataCount = database.getProjectPostsCount(id) data = database.getProjectPosts(id, limit, offset) if data is None: return jsonify({"error": "No results found"}), 404 else: project = database.getProjectByID(id) if (project['projectVisibility'] == 'PRIVATE'): userRole = function.getProjectUserRole(get_jwt_identity(), id) if not function.isProjectMember(userRole): return jsonify( {"error": "Must be project member to view project posts"}), 403 for projectpost in data: user = database.getUserInfo(str(projectpost['postUser'])) projectpost['user'] = user dataCount['data'] = data return jsonify(dataCount), 200
def get_post(id): # Check if specified ID is an integer if not function.isInt(id): return jsonify({"error": "id is not an integer"}), 400 data = database.getPostByID(id) if data is None: return jsonify({"error": "No results found"}), 404 else: user = database.getUserInfo(str(data['postUser'])) data['user'] = user return jsonify(data), 200
def get_post_comments(id): # Check if specified ID is an integer if not function.isInt(id): return jsonify({"error": "id is not an integer"}), 400 data = database.getPostComments(id) if data is None: return jsonify({"error": "No results found"}), 404 else: for comment in data: user = database.getUserInfo(str(comment['commentUser'])) comment['user'] = user data = function.nest_comments(data) return jsonify(data), 200
def get_project_id(id): # Check if specified ID is an integer if not function.isInt(id): return jsonify({"error": "id is not an integer"}), 400 data = database.getProjectByID(id) if data is None: return jsonify({"error": "No results found"}), 404 else: if (data['projectVisibility'] == 'PRIVATE'): userRole = function.getProjectUserRole(get_jwt_identity(), id) if not function.isProjectMember(userRole): return jsonify( {"error": "Must be project member to view project"}), 403 user = database.getUserInfo(str(data['projectOwner'])) data['owner'] = user return jsonify(data), 200
def get_project_users(id): # Check if specified ID is an integer if not function.isInt(id): return jsonify({"error": "id is not an integer"}), 400 # Check if project actually exists project = database.getProjectByID(id) if project is None: return jsonify({"error": "Specified project does not exist"}) data = database.getProjectUsers(id) if data is None: return jsonify({"error": "No results found"}), 404 else: for projectuser in data: user = database.getUserInfo(str(projectuser['User_userID'])) projectuser['user'] = user return jsonify(data), 200
def get_project(): name = request.args.get('name') limit = request.args.get('limit') offset = request.args.get('offset') if limit is not None and not function.isInt(limit): return jsonify({"error": "limit is not an integer"}), 400 if offset is not None and not function.isInt(offset): return jsonify({"error": "offset is not an integer"}), 400 dataCount = database.getProjectsCount(name) data = database.getProjects(name, limit, offset) if data is None: return jsonify({"error": "No results found"}), 404 else: for project in data: user = database.getUserInfo(str(project['projectOwner'])) project['owner'] = user dataCount['data'] = data return jsonify(dataCount), 200