def getChatPosts(self, chat_id): dao = PostsDAO() posts = dao.getChatPosts(chat_id) postsList = [] for row in posts: postsList.append(self.build_post_dict(row)) return jsonify(Posts=postsList)
def getAllPosts(self): dao = PostsDAO() posts = dao.getAllPosts() postsList = [] for row in posts: postsList.append(self.build_post_dict(row)) return jsonify(Posts=postsList)
def getDailyPosts(self): dao = PostsDAO() post_list = dao.getDailyPosts() result_list = [] for row in post_list: result_list.append(self.build_daily_post_dict(row)) print(result_list) return jsonify(Post=result_list)
def getPostsInChatX(self, chat_id, post_id): dao = PostsDAO() row = dao.getPostsInChatX(chat_id, post_id) if not row: return jsonify(Error="Post Not Found"), 404 else: post = self.build_post_dict(row) return jsonify(Post=post)
def getPostById(self, post_id): dao = PostsDAO() row = dao.getPostById(post_id) if not row: return jsonify(Error="Post not found"), 404 else: post = self.build_post_dict(row) return jsonify(Post=post)
def insertReact(self, json): react_type = json['react_type'] user_that_react = json['user_that_react'] p_reacted = -1 reply_reacted = -1 user = UsersDAO().getUserById(user_that_react) if json.get('p_reacted'): p_reacted = json['p_reacted'] post = PostsDAO().getPostById(p_reacted) if not post: return jsonify(Error="Post not found."), 404 elif json.get('reply_reacted'): reply_reacted = json['reply_reacted'] reply = ReplyDAO().getReplyById(reply_reacted) if not reply: return jsonify(Error="Reply not found."), 404 if not user: return jsonify(Error="User not found."), 404 elif react_type and user_that_react and json.get('p_reacted'): ReactsDAO().insertReactP(react_type, user_that_react, p_reacted) result = self.build_react_attributes_P(react_type, user_that_react, p_reacted) return jsonify(React=result), 201 elif react_type and user_that_react and json.get('reply_reacted'): ReactsDAO().insertReactR(react_type, user_that_react, reply_reacted) result = self.build_react_attributes_R(react_type, user_that_react, reply_reacted) return jsonify(React=result), 201 else: return jsonify(Error="Unexpected attributes in post request"), 400
def insertHashtagToPost(self, json): print(json) p_with_hashtag = json['p_with_hashtag'] hashtag_id = json['hashtag_id'] post = PostsDAO().getPostById(p_with_hashtag) hashtag = HashtagsDAO().getHashtagById(hashtag_id) if not post: return jsonify(Error="Post not found."), 404 elif not hashtag: return jsonify(Error="Hashtag not found."), 404 elif p_with_hashtag and hashtag_id: HashtagsDAO().insertHashtagToPost(p_with_hashtag, hashtag_id) result = self.build_hashtag_Post(p_with_hashtag, hashtag_id) return jsonify(Has_Hashatg=result) else: return jsonify(Error="Unexpected attributes in post request"), 400
def insertReply(self, json): # reply_date = json['reply_date'] reply_text = json['reply_text'] p_replied = json['p_replied'] user_that_replied = json['user_that_replied'] post = PostsDAO().getPostById(p_replied) user = UsersDAO().getUserById(user_that_replied) if not post: return jsonify(Error="Post not found."), 404 elif not user: return jsonify(Error="User not found."), 404 elif reply_text and p_replied and user_that_replied: ReplyDAO().insertReply(reply_text, p_replied, user_that_replied) result = self.build_reply_attributes(reply_text, p_replied, user_that_replied) return jsonify(Reply=result), 201 else: return jsonify(Error="Unexpected attributes in post request"), 400
def insertPost(self, json): post_caption = json['post_caption'] #post_date = json['post_date'] p_created_by = json['p_created_by'] c_post_belongs = json['c_post_belongs'] chat = ChatsDAO().getChatById(c_post_belongs) user = UsersDAO().getUserById(p_created_by) if not chat: return jsonify(Error="Chat not found."), 404 elif not user: return jsonify(Error="User not found."), 404 elif post_caption and p_created_by and c_post_belongs: post_id = PostsDAO().insertPost(post_caption, p_created_by, c_post_belongs) result = self.build_post_attributes(post_caption, p_created_by, c_post_belongs, post_id) return jsonify(Post=result), 201 else: return jsonify(Error="Unexpected attributes in post request"), 400