def removeMember(self, cid, uid): result = ChatDAO() if not result.getChatByID(cid): return jsonify(Error="Chat not found."), 404 else: result.removeMember(cid, uid) return jsonify(DeleteStatus="OK"), 200
def getAllChats(self): dao = ChatDAO() result = dao.getAllChats() mapped_result = [] for r in result: mapped_result.append(self.mapToDict(r)) return jsonify(Chats=mapped_result)
def getAllReplies(self): dao = ReplyDAO() dao1 = MessageDAO() dao2 = MessageDAO() userDAO = UserDAO() chatDAO = ChatDAO() result = dao.getAllReplies() mapped_result = [] for r in result: reply_info = [] result1 = dao1.getMessageById(r[0]) # array de mensaje-reply result2 = dao2.getMessageById(r[1]) # array de mensaje original reply_info.append(result1[1]) #replyer_text reply_info.append(result2[1]) #original_text # buscar user con user id # result1[3] - replyer_id replyer = userDAO.getUserById(result1[3]) reply_info.append(replyer[1] + ' ' +replyer[2]) # buscar chat con chat id # result1[4] - chat_id chat_name = chatDAO.getChatById(result1[4]) reply_info.append(chat_name[1]) reply_info.append(result1[2]) #reply_date reply_info.append(result2[2]) #original_message_date mapped_result.append(self.mapToDict(reply_info)) return jsonify(Replies=mapped_result)
def getChatByUserIDandChatID(self, cid, uid): dao = ChatDAO() chat_list = dao.getChatByUserIDandChatID(uid, cid) if not chat_list: return jsonify(Error="Chat Not Found"), 404 else: chat = self.build_chat_attributes(chat_list) return jsonify(Chat=chat_list)
def chatOwnerId(self, cid): dao = ChatDAO() row = dao.getChatByID(cid) if not row: return jsonify(Error="Chat Not Found"), 404 else: user = self.build_owner_dict(row) return jsonify(User=user)
def getChatByID(self, id): dao = ChatDAO() result = dao.getChatById(id) if result == None: return jsonify(Error="CHAT NOT FOUND") else: mapped = self.mapToDict(result) return jsonify(Chat=mapped)
def findChat(self, name): dao = ChatDAO() result = dao.searchByChatName(name) if result == None: return jsonify(Error="CHAT NOT FOUND") else: mapped = self.mapToDict(result) return jsonify(Chat=mapped)
def getAllChats(self): result = ChatDAO().getAllChats() chats = [] if result: for i in result: chats.append(self.buildChatAlpha(i)) return jsonify(Chats=chats) else: return jsonify(ERROR='No chats found')
def getChatOwner(self, cgid ): dao = ChatDAO() result = dao.getChatOwner(cgid) mapped_result = [] if not result: return jsonify(Error="Not Found"), 404 for r in result: mapped_result.append(self.mapOwnersToDict(r)) return jsonify(Chat=mapped_result)
def getChatsNotJoined(self,uid): dao = ChatDAO() result = dao.getChatsNotJoined(uid) mapped_result = [] if not result: return jsonify(Error="Not Found"), 404 for r in result: mapped_result.append(self.mapToDict(r)) return jsonify(Chat=mapped_result)
def getAllMessagesByChat(self, cgid): dao = ChatDAO() result = dao.getAllMessagesByChat(cgid) mapped_result = [] if len(result) == 0: return jsonify(Error="Not Found"), 404 for r in result: mapped_result.append(self.mapChatMessageToDict(r)) return jsonify(Messages=mapped_result)
def getAllChatGroups(self): dao = ChatDAO() result = dao.getAllChatGroups() mapped_result = [] if not result: return jsonify(Error="Not Found"), 404 for r in result: mapped_result.append(self.mapToDict(r)) return jsonify(Chat=mapped_result)
def getChatGroupsByUserId(self,uid): dao = ChatDAO() result = dao.getChatGroupsByUserId(uid) mapped_result = [] if not result: return jsonify(Error="Not Found"), 404 for r in result: mapped_result.append(self.mapToDictUserChatGroups(r)) return jsonify(ChatGroups=mapped_result)
def getChatMembers(self, cgid): dao = ChatDAO() result = dao.getChatUsers(cgid) mapped_result = [] if not result: return jsonify(Error="Not Found"), 404 for r in result: mapped_result.append(self.mapMembersToDict(r)) return jsonify(Members=mapped_result)
def getChatMsgsByUserId(self,cgid, uid): dao = ChatDAO() result = dao.getChatMsgsByUserId(cgid,uid) mapped_result = [] if not result: return jsonify(Error="Not Found"), 404 for r in result: mapped_result.append(self.mapUserMsgsToDict(r)) return jsonify(Messages=mapped_result)
def insertChatJson(self, json): cname = json['cname'] uid = json['uid'] if cname and uid: dao = ChatDAO() cid = dao.insert(cname, uid) dao.insertMember(cid, uid) result = self.build_chat_attributes(cid, cname, uid) return jsonify(Chat=result), 201 else: return jsonify(Error="Unexpected attributes in post request"), 400
def removeChat(self, cID, ownerID): result = ChatDAO() user = UsersDAO() if not result.getChatByID(cID): return jsonify(Error="Chat not found."), 404 else: print(ownerID, user.chatOwner(cID)[0]) if ownerID == user.chatOwner(cID)[0]: print(ownerID, user.chatOwner(cID)) result.delete(cID) return jsonify(DeleteStatus="OK"), 200 else: return jsonify(Error="Not chat admin"), 404
def newChat(self, form): if len(form) != 1: return jsonify(Error="Malformed post request"), 400 else: print(form) chatname = form['chatname'] if chatname: dao = ChatDAO() cgid = dao.newChat(chatname) result = self.buildChat(cgid, chatname) return jsonify(Chat=result), 201 else: return jsonify(Error="Unexpected attributes in post request"), 400
def getAllMemberships(self): dao = MemberDAO() dao1 = UserDAO() dao2 = ChatDAO() result = dao.getAllMemberships() mapped_result = [] for r in result: result2 = dao1.getUserById(r[0]) result3 = dao2.getChatById(r[1]) r[0] = result2[1] + " " + result2[2] r[1] = result3[1] mapped_result.append(self.mapToDict(r)) return jsonify(Members=mapped_result)
def joinChat(self, form, uid): if len(form) != 1: return jsonify(Error="Malformed post request"), 400 else: print(form) print(uid) cgid = form['cgid'] if uid and cgid: dao = ChatDAO() dao.joinChat(uid, cgid) result = self.mapChatMember(uid, cgid) return jsonify(ChatMember=result), 201 else: return jsonify(Error="Unexpected attributes in post request"), 400
def insertChat(self, form): print("form: ", form) if len(form) != 2: return jsonify(Error="Malformed post request"), 400 else: cname = form['cname'] uid = form['uid'] if cname and uid: dao = ChatDAO() cid = dao.insert(cname, uid) result = self.build_post_attributes(cid, cname, uid) return jsonify(Chat=result), 201 else: return jsonify( Error="Unexpected attributes in post request"), 400
def getMembershipByUID(self, user_id): dao = MemberDAO() dao1 = UserDAO() dao2 = ChatDAO() result = dao.getMembershipByUserID(user_id) if result == None: return jsonify(Error="MEMBERSHIP NOT FOUND") else: mapped_result = [] for r in result: result2 = dao1.getUserById(r[0]) result3 = dao2.getChatById(r[1]) r[0] = result2[1] + " " + result2[2] r[1] = result3[1] mapped_result.append(self.mapToDict(r)) return jsonify(Members=mapped_result)
def getChatsAdministratedByUser(self, user_id): dao = AdminDAO() dao1 = UserDAO() dao2 = ChatDAO() result = dao.getChatsAdministratedByUser(user_id) if result == None: return jsonify(Error="CHAT NOT FOUND") else: mapped_result = [] for r in result: result2 = dao1.getUserById(r[0]) result3 = dao2.getChatById(r[1]) r[0] = result2[1] + " " + result2[2] r[1] = result3[1] mapped_result.append(self.mapToDict(r)) return jsonify(Admins=mapped_result)
def getAdminByChatID(self, chat_id): dao = AdminDAO() dao1 = UserDAO() dao2 = ChatDAO() result = dao.getAdminsByChatID(chat_id) # print(result) if result == None: return jsonify(Error="ADMIN NOT FOUND") else: mapped_result = [] for r in result: result2 = dao1.getUserById(r[0]) result3 = dao2.getChatById(r[1]) r[0] = result2[1] + " " + result2[2] r[1] = result3[1] mapped_result.append(self.mapToDict(r)) return jsonify(Admins=mapped_result)
def insertMember(self, cid, usrID): result = ChatDAO().insertMember(cid, usrID) if result: return jsonify(Member=self.buildChatID(result)) else: jsonify(ERROR='User is member')