def delete_comment(post_id, comment_id): user = SESSION.get(request.headers.get('Authorization')) if user is None: abort(400, {'message': 'TOKEN_NOT_FOUND'}) from model import Comment comment_exist = Comment.find(comment_id) if comment_exist is None: abort(400, {'message': 'COMMENT_NOT_FOUND'}) comment_exist.delete() return "DELETED"
def delete_like(post_id, like_id): user = SESSION.get(request.headers.get('Authorization')) if user is None: abort(400, {'message': 'TOKEN_NOT_FOUND'}) from model import Like like_exist = Like.find(like_id) if like_exist is None: abort(400, {'message': 'NOT_YET_LIKED'}) like_exist.delete() return jsonify("Deleted")
def delete_post(post_id): user = SESSION.get(request.headers.get('Authorization')) if user is None: abort(400, {'message': 'TOKEN_NOT_FOUND'}) from model import Post post_exist = Post.find(post_id) if post_exist is None: abort(400, {'message': 'POST_NOT_FOUND'}) post_exist.delete() return "DELETED"
def create_post(): user = SESSION.get(request.headers.get('Authorization')) if user is None: abort(400, {'message': 'TOKEN_NOT_FOUND'}) input_data = request.get_json() from model import Post post = Post() post.user_id = user.id post.content = input_data['content'] post.save() return jsonify(post.to_dict())
def update_post(post_id): user = SESSION.get(request.headers.get('Authorization')) if user is None: abort(400, {'message': 'TOKEN_NOT_FOUND'}) input_data = request.get_json() from model import Post post_exist = Post.find(post_id) if post_exist is None: abort(400, {'message': 'POST_NOT_FOUND'}) post_exist.content = input_data['content'] post_exist.save() return jsonify(post_exist.to_dict())
def get_post(post_id): user = SESSION.get(request.headers.get('Authorization')) if user is None: abort(400, {'message': 'TOKEN_NOT_FOUND'}) from model import Post post_exist = Post.find(post_id) if post_exist is None: abort(400, {'message': 'POST_NOT_FOUND'}) posts_response = { 'content': post_exist.content } return jsonify(posts_response)
def list_posts(): user = SESSION.get(request.headers.get('Authorization')) if user is None: abort(400, {'message': 'TOKEN_NOT_FOUND'}) from model import User posts_response = [] for post in User.find(user.id).posts: posts_response.append({ 'id': post.id, 'content': post.content }) return jsonify(posts_response)
def create_like(post_id): user = SESSION.get(request.headers.get('Authorization')) if user is None: abort(400, {'message': 'TOKEN_NOT_FOUND'}) # input_data = request.get_json() from model import Like, Post post_exist = Post.find(post_id) if post_exist is None: abort(400, {'message','POST_NOT_FOUND'}) like = Like() like.post_id = post_id like.user_id = user.id like.save() return "Liked."
def create_comment(post_id): user = SESSION.get(request.headers.get('Authorization')) if user is None: abort(400, {'message': 'TOKEN_NOT_FOUND'}) input_data = request.get_json() from model import Comment, Post post_exist = Post.find(post_id) if post_exist is None: abort(400, {'message','POST_NOT_FOUND'}) comment = Comment() comment.post_id = post_id comment.user_id = user.id comment.body = input_data['body'] comment.save() return jsonify("Created.")
def list_profiles(): profile = SESSION.get(request.headers.get('Authorization')) if profile is None: abort(400, {'message': 'TOKEN_NOT_FOUND'}) from model import Profile profile_response = [] for profile in Profile.query.all(): profile_response.append({ 'name': profile.name, 'dob': profile.dob, 'img': profile.img, 'star': profile.star, 'age': profile.age }) return jsonify(profile_response)
def get_likes(post_id): user = SESSION.get(request.headers.get('Authorization')) if user is None: abort(400, {'message': 'TOKEN_NOT_FOUND'}) from model import Like, Post p = Post.find(post_id) s = p.likes if p is None: abort(400, {'message': 'NO_LIKES_FOUND'}) likes_response = [] for i in s: print(i.user_id) likes_response.append({ 'user' : i.user_id }) return jsonify(likes_response)
def get_comments(post_id): user = SESSION.get(request.headers.get('Authorization')) if user is None: abort(400, {'message': 'TOKEN_NOT_FOUND'}) from model import Comment, Post p = Post.find(post_id) s = p.comments if p is None: abort(400, {'message': 'COMMENT_NOT_FOUND'}) comments_response = [] for i in s: print(i.body) comments_response.append({ 'comment' : i.body }) return jsonify(comments_response)
def view_profile(): profile = SESSION.get(request.heades.get('Authorization')) if profile is None: abort(400, {'message': 'TOKEN_NOT_FOUND'}) from model import Profile profile_response = [] for profile in Profile.query.all(): profile_response.append({ 'id': profile.id, 'imageUrls': profile.imageUrls, 'name': profile.name, 'email': profile.email, 'password': profile.password, 'gender': profile.gender, 'dob': profile.dob, 'birth_time': profile.birth_time, 'birth_place': profile.birth_place, 'religion': profile.religion, 'caste': profile.caste, 'subcaste': profile.subcaste, 'gothram': profile.gothram, 'star': profile.star, 'qualification': profile.qualification, 'job': profile.job, 'workplace': profile.workplace, 'income': profile.income, 'height': profile.height, 'weight': profile.weight, 'mother_tongue': profile.mother_tongue, 'known_language': profile.known_language, 'nativity': profile.nativity, 'marital_status': profile.marital_status, 'talents': profile.talents, 'hobbies': profile.hobbies, 'vehicle_driving': profile.vehicle_driving, 'disabilities': profile.disabilities, 'box11': profile.box11, 'box12': profile.box12, 'box13': profile.box13, 'box14': profile.box14, 'box15': profile.box15, 'box16': profile.box16, 'box17': profile.box17, 'box18': profile.box18, 'box19': profile.box19, 'box110': profile.box110, 'box111': profile.box111, 'box112': profile.box112, 'box21': profile.box21, 'box22': profile.box22, 'box23': profile.box23, 'box24': profile.box24, 'box25': profile.box25, 'box26': profile.box26, 'box27': profile.box27, 'box28': profile.box28, 'box29': profile.box29, 'box210': profile.box210, 'box211': profile.box211, 'box212': profile.box212, 'father_name': profile.father_name, 'father_occupation': profile.father_occupation, 'mother_name': profile.mother_name, 'mother_occupation': profile.mother_occupation, 'contact1': profile.contact1, 'contact2': profile.contact2, 'sibiling_count': profile.sibiling_count, 'family_status': profile.family_status, 'properties': profile.properties, 'anydetails': profile.anydetails, 'expected_qualification': profile.expected_qualification, 'expected_place': profile.expected_place, 'expected_income': profile.expected_income, 'expected_caste': profile.expected_caste, 'expected_subcaste': profile.expected_subcaste, 'age_difference': profile.age_difference, 'expected_height': profile.expected_height, 'expected_weight': profile.expected_weight, 'expectations': profile.expectations }) return jsonify(profile_response)