Exemple #1
0
 def getAllChatsDev(self):
     dao = ChatDAO()
     result = dao.getAllChatsDev()
     mapped_result = []
     for r in result:
         mapped_result.append(self.mapToChatDict(r))
     return jsonify(Chat=mapped_result)
Exemple #2
0
 def getChatByIDDev(self, id):
     dao = ChatDAO()
     result = dao.getChatByIDDev(id)
     if result == None:
         return jsonify(Error="CHAT DOES NOT EXIST"), 404
     else:
         mapped = self.mapToChatDict(result)
         return jsonify(Chat=mapped)
Exemple #3
0
 def getChatByID(self, id):
     dao = ChatDAO()
     result = dao.getChatByID(id)
     if result == None:
         return jsonify(Error="CHAT NOT FOUND"), 404
     else:
         mapped = self.mapToChatDict(result)
         return jsonify(Chat=mapped)
Exemple #4
0
 def getChatMembersByChatID(self, chid):
     dao = ChatDAO()
     result = dao.getChatByID(chid)
     members = []
     if result == None:
         return jsonify(Error="CHAT NOT FOUND"), 404
     else:
         for x in ChatDAO().getMembers(chid):
             members.append(ContactHandler().mapToContactDict(x))
         return jsonify(members=members)
Exemple #5
0
 def getChatGroupSubscribers(self, chid):
     dao = ChatDAO()
     result = dao.getAllChatSubscribers(chid)
     print(result)
     members = []
     if result == None:
         return jsonify(Error="CHAT NOT FOUND"), 404
     else:
         dao = UserDAO()
         for x in result:
             user = dao.getUserByID(x[0])
             members.append(UserHandler().mapToUserDict(user))
         return jsonify(members=members)
Exemple #6
0
 def insertChat(self, form):
     if form == None:
         return jsonify(Error="Malformed search string."), 400
     if "chatname" in form:
         chatname = form['chatname']
         if chatname == '':
             return jsonify(Error="Missing chatname"), 400
     else:
         return jsonify(
             Error="Malformed post request (Did not include chatname)"), 400
     # chname = form['chatname']
     dao = ChatDAO()
     chid = dao.insert(chatname)
     chat = dao.getChatByID(chid)
     result = self.mapToChatAttributes(chat[0], chat[1], chat[2], chat[3])
     return jsonify(Chat=result), 201
Exemple #7
0
 def searchChats(self, form):
     if len(form) > 1:
         print(form)
         return jsonify(Error="Malformed search string."), 400
     chatname = form["chatname"]
     # print(chatname)
     if chatname:
         dao = ChatDAO()
         chat_list = dao.getChatsByChatName(chatname)
         result_list = []
         for row in chat_list:
             result = self.mapToChatDict(row)
             result_list.append(result)
         return jsonify(Chats=result_list)
     else:
         return jsonify(Error="Malformed search string."), 400
Exemple #8
0
 def deleteChat(self, chid):
     dao = ChatDAO()
     print(chid)
     if not dao.getChatByID(chid):
         return jsonify(Error="Chat not found."), 404
     if dao.validateAdmin(chid) == None:
         return jsonify(Error="You are not the admin of the chat!"), 400
     else:
         members = dao.getMembers(chid)
         print(members)
         for member in members:
             print(member[0])
             dao.deleteMember(chid, member[0])
         dao.delete(chid)
         return jsonify(DeleteStatus="OK"), 200
Exemple #9
0
    def addChatMember(self, chid, form):
        dao = ChatDAO()
        result = dao.getChatByID(chid)

        if result == None:
            return jsonify(Error="CHAT NOT FOUND"), 404
        else:
            if "cid" in form:
                cid = form['cid']
                if cid == '':
                    return jsonify(Error="Missing contact id ('cid')"), 400
            else:
                return jsonify(
                    Error=
                    "Malformed post request (Did not include contact id ('cid'))"
                ), 400
            contact = form['cid']
            if dao.isContactInChat(chid, contact):
                return jsonify(Error="Contact is already in chat"), 400
            else:
                return ContactHandler().getContactByID(
                    dao.insertMember(chid, contact))
Exemple #10
0
    def updateChat(self, chid, form):
        dao = ChatDAO()
        if not dao.getChatByID(chid):
            return jsonify(Error="Chat not found."), 404

        if form == None:
            return jsonify(Error="Malformed search string."), 400

        if dao.validateAdmin(chid) == None:
            return jsonify(Error="You are not the admin of the chat!"), 400

        chatname = form['chatname']
        chid = dao.update(chid, chatname)
        chat = dao.getChatByID(chid)
        result = self.mapToChatAttributes(chat[0], chat[1], chat[2], chat[3])
        return jsonify(Chat=result), 200
Exemple #11
0
 def deleteChatMember(self, chid, form):
     dao = ChatDAO()
     result = dao.getChatByID(chid)
     if "cid" in form:
         cid = form['cid']
         if cid == '':
             return jsonify(Error="Missing contact id ('cid')"), 400
     else:
         return jsonify(
             Error=
             "Malformed post request (Did not include contact id ('cid'))"
         ), 400
     contact = form['cid']
     print(dao.isContactInChat(chid, contact))
     if result == None:
         return jsonify(Error="CHAT NOT FOUND"), 404
     elif dao.validateAdmin(chid) == None:
         return jsonify(Error="You are not the admin of the chat!"), 400
     else:
         if len(dao.isContactInChat(chid, contact)) < 1:
             return jsonify(Error="Contact is not in chat"), 400
         else:
             return ContactHandler().getContactByID(
                 dao.deleteMember(chid, contact))