示例#1
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)
示例#2
0
    def removeMember(self, form, users_id):

        if len(form) != 3:
            return jsonify(Error="Malformed post request"), 400
        else:
            first_name = form['first_name']
            last_name = form['last_name']
            group_name = form['group_name']
            if first_name and last_name and group_name:

                Mdao = MemberDAO()
                Udao = UsersDAO()
                Gdao = Group_ChatDAO()
                Adao = AdministratesDAO()

                group_info = Gdao.searchByChatName(
                    group_name)  # get group info
                print(group_info)
                member_info = Udao.getUserByName(
                    first_name,
                    last_name)  # get member info to wish is desired to remove
                print(member_info)
                check = Mdao.getMembershipsByUserAndGroup(
                    member_info[0],
                    group_info[0])  # check if user already in group
                print(check)
                admin_of_group = Adao.getAdminOfGroupID(
                    group_info[0])  # get admin id
                admin_info = Udao.getUserById(
                    admin_of_group[0])  # get admin info
                print(users_id)
                print(admin_of_group)
                # check if user is in group and the user trying to add is admin
                if check and (users_id == admin_of_group[0]):
                    Mdao.remove(member_info[0],
                                group_info[0])  # add user to group
                    result = self.member_attributes(first_name, last_name,
                                                    group_name)
                    return jsonify(users=result), 201
                else:
                    return jsonify(
                        Error="Invalid admin or user already in group"), 400
            else:
                return jsonify(
                    Error="Unexpected attributes in post request"), 400
示例#3
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)
示例#4
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)
示例#5
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)