def getMessages(self): dao = MessagesDAO() result = dao.getMessages() message = [] for i in result: message.append(self.arrange(i)) return jsonify(Messages=message)
def getReactions(self, mid): dao = MessagesDAO() result = dao.getReactions(mid) if result: res = self.arrangereactions(result) return jsonify(Reactions=res) return jsonify(ERROR='0 Reactions')
def getNumberOfDislikes(self, mid): dao = MessagesDAO() result = dao.getNumberOfDislikes(mid) if result: res = self.arrangedislike(result) return jsonify(Message_Disikes=res) return jsonify(ERROR='0 Likes')
def getMessageReplies(self, gid, mid): dao = MessagesDAO() result = dao.getMessageReplies(gid, mid) res = [] if result: for r in result: res.append(self.arrangebeta(r)) return jsonify(Replies=res) return jsonify(ERROR='No replies for that message')
def getMessageDislikes(self, gid, mid): dao = MessagesDAO() result = dao.getMessageDislikes(gid, mid) res = [] if result: for r in result: res.append(self.arrangebeta(r)) return jsonify(Message=res) return jsonify(ERROR='No one has disliked this message')
def getUserMessagesById(self, usrid): dao = MessagesDAO() result = dao.getUserMessagebyId(usrid) message = [] if result: for m in result: message.append(self.arrangeJoin(m)) return jsonify(Messages=message) return jsonify(ERROR='No messages from that User')
def insertDislikes(self, form): if len(form) != 2: return jsonify(ERROR='Malformed request form') else: mid = form['mid'] user = form['user'] if mid and user: dao = MessagesDAO() mess = dao.insertDislike(mid, user) if mess: result = self.arrangeEcho(mess) return jsonify(Dislikes=result) else: return jsonify(ERROR='Could not post like')
def insertReply(self, form): if len(form) != 4: return jsonify(ERROR='Malformed request form') else: mid = form['mid'] user = form['user'] groupname = form['groupname'] content = form['content'] res = { 'content': content, 'mid': mid } if mid and user and groupname and content: dao = MessagesDAO() mess = dao.insertReply(mid, user, groupname, content) if mess: result = self.arrangeEcho(mess) hashtag = HashtagDAO().parseHash(res) return jsonify(Reply=result) else: return jsonify(ERROR='Could not post like')
def insertMessage(self, form, userid, groupname): if len(form) != 1: return jsonify(ERROR='Malformed request form') else: group = groupname usrid = userid content = form['content'] if group and usrid and content: dao = MessagesDAO() mess = dao.insertMessage(group, usrid, content) if mess: result = self.arrange(mess) hashtag = HashtagDAO().parseHashtag(result) return jsonify(Message={ 'Message': result, 'Hashtags': hashtag }) else: return jsonify(ERROR='Could not post message') else: return jsonify(ERROR='Wrong form posted')
def getHashtags(self): dao = MessagesDAO() result = dao.getHashtags() return jsonify(Hashtags=result)