def getChatById(self, chat_id): dao = ChatsDAO() row = dao.getChatById(chat_id) if not row: return jsonify(Error="Chat Not Found"), 404 else: chat = self.build_chat_dict(row) return jsonify(Chat=chat)
def insertUserToChat(self, chat_id, user_id): dao = ChatsDAO() chat = dao.getChatById(chat_id) user = UsersDAO().getUserById(user_id) if not chat: return jsonify(Error="Chat not found."), 404 elif not user: return jsonify(Error="User not found."), 404 else: dao.insertUserToChat(chat_id, user_id) return jsonify(InsertStatus="OK"), 200
def removeChat(self, chat_id, owner_id): dao = ChatsDAO() o_id = dao.getChatOwner(chat_id) chat = dao.getChatById(chat_id) if owner_id != o_id[0][0]: return jsonify(Error="Operation invalid."), 404 elif not chat: return jsonify(Error="Chat not found."), 404 else: dao.removeChat(chat_id) return jsonify(DeleteStatus="OK"), 200
def getChatUsers(self, chat_id): dao = ChatsDAO() chat = dao.getChatById(chat_id) user_list = dao.getChatUsers(chat_id) if not user_list: return jsonify(Chat=user_list), 404 elif not chat: return jsonify(Error="Chat not found"), 404 else: result_list = [] for row in user_list: user = UserHandler.build_user_dict(UserHandler, row) result_list.append(user) return jsonify(Chat=result_list)