예제 #1
0
 def getChatByID(self, id):
     dao = Group_ChatDAO()
     result = dao.getChatById(id)
     if result == None:
         return jsonify(Error="CHAT NOT FOUND")
     else:
         mapped = self.mapToDict(result)
         return jsonify(Chat=mapped)
예제 #2
0
    def getAllMemberships(self):
        dao = MemberDAO()
        dao1 = UsersDAO()
        dao2 = Group_ChatDAO()
        result = dao.getAllMemberships()

        mapped_result = []
        for r in result:
            membership = []
            user = dao1.getUserById(r[0])
            group = dao2.getChatById(r[1])
            membership.append(user[1] + " " + user[2])
            membership.append(group[1])
            mapped_result.append(self.mapToDict(membership))
        return jsonify(Members=mapped_result)
예제 #3
0
 def getAdminOfChatID(self, group_id):
     dao = AdministratesDAO()
     dao1 = UsersDAO()
     dao2 = Group_ChatDAO()
     result = dao.getAdminOfGroupID(group_id)
     if result == None:
         return jsonify(Error="GROUP NOT FOUND")
     else:
         mapped_result = []
         info = []
         user = dao1.getUserById(result[0])
         group = dao2.getChatById(result[1])
         info.append(user[1] + " " + user[2])  # user name
         info.append(group[1])  # group name
         mapped_result.append(self.mapToDict(info))
         return jsonify(Admins=mapped_result)
예제 #4
0
    def getAllAdmins(self):

        dao = AdministratesDAO()
        dao1 = UsersDAO()
        dao2 = Group_ChatDAO()
        result = dao.getAllAdmins()

        mapped_result = []
        for r in result:
            result2 = dao1.getUserById(r[0])
            result3 = dao2.getChatById(r[1])
            name_chat = ['', '']
            name_chat[0] = result2[1] + " " + result2[2]
            name_chat[1] = result3[1]
            mapped_result.append(self.mapToDict(name_chat))
        return jsonify(Admins=mapped_result)
예제 #5
0
 def getChatsAdministratedByUser(self, users_id):
     dao = AdministratesDAO()
     dao1 = UsersDAO()
     dao2 = Group_ChatDAO()
     result = dao.getChatsAdministratedByUser(users_id)
     if result == None:
         return jsonify(Error="CHAT NOT FOUND")
     else:
         mapped_result = []
         for r in result:
             info = []
             user = dao1.getUserById(r[0])
             group = dao2.getChatById(r[1])
             info.append(user[1] + " " + user[2])  # user name
             info.append(group[1])  # group name
             mapped_result.append(self.mapToDict(info))
         return jsonify(Admins=mapped_result)
예제 #6
0
 def getMembershipByChatID(self, group_id):
     dao = MemberDAO()
     dao1 = UsersDAO()
     dao2 = Group_ChatDAO()
     result = dao.getMembershipsOfGroupID(group_id)
     # print(result)
     if result == None:
         return jsonify(Error="MEMBERSHIP NOT FOUND")
     else:
         mapped_result = []
         for r in result:
             membership = []
             user = dao1.getUserById(r[0])
             group = dao2.getChatById(r[1])
             membership.append(user[1] + " " + user[2])
             membership.append(group[1])
             mapped_result.append(self.mapToDict(membership))
         return jsonify(Members=mapped_result)
예제 #7
0
    def checkMember(self, users_id, group_id):

        dao = MemberDAO()
        dao1 = UsersDAO()
        dao2 = Group_ChatDAO()
        result = dao.getMembershipsByUserAndGroup(users_id, group_id)

        if result == None:
            return None
        else:
            mapped_result = []
            for r in result:
                membership = []
                user = dao1.getUserById(r[0])
                group = dao2.getChatById(r[1])
                membership.append(user[1] + " " + user[2])
                membership.append(group[1])
                mapped_result.append(self.mapToDict(membership))
            return jsonify(Members=mapped_result)
예제 #8
0
    def getMembershipByUName(self, first_name, last_name):
        dao = MemberDAO()
        dao1 = UsersDAO()
        dao2 = Group_ChatDAO()
        result = dao.getMembershipsByUserName(first_name, last_name)
        # print(result)
        if result == None:
            return jsonify(Error="MEMBERSHIP NOT FOUND")
        else:
            mapped_result = []
            for r in result:
                membership = []
                user = dao1.getUserById(r[1])
                group = dao2.getChatById(r[0])
                # print(user)
                # print(group)
                membership.append(user[1] + " " + user[2])
                membership.append(group[1])
                membership.append(group[0])
                membership.append(user[0])
                print(membership[2])

                mapped_result.append(self.mapToDict(membership))
            return jsonify(Chats=mapped_result)