コード例 #1
0
 def findChat(self, name):
     dao = Group_ChatDAO()
     result = dao.searchByChatName(name)
     if result == None:
         return jsonify(Error="CHAT NOT FOUND")
     else:
         mapped = self.mapToDict(result)
         return jsonify(Chat=mapped)
コード例 #2
0
ファイル: member_of.py プロジェクト: Ricardo1993/DB-Project
    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 removeGroup(self, form):

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

            # Check if user is the admin by name

            if group_name and first_name and last_name:
                Gdao = Group_ChatDAO()
                Adao = AdministratesDAO()
                Udao = UsersDAO()

                # it is presume user already exists
                group_info = Gdao.searchByChatName(
                    group_name)  #returns chat info
                print(group_info)
                admin_info = Adao.getAdminOfGroupID(
                    group_info[0])  # get admin of group
                print(admin_info)
                users_info = Udao.getUserById(admin_info[0])  # get admin info
                print(users_info)
                # Check if admin is the same as user
                if (users_info[1] == first_name
                        and users_info[2] == last_name):
                    administrates_info = Adao.remove(
                        users_info[0],
                        group_info[0])  # remove by users_id and group_id
                    group_removed = Gdao.remove(group_name)  #remove group
                    result = self.group_attributes(group_name, first_name,
                                                   last_name)
                    return jsonify(users=result), 201
                else:
                    return jsonify(Error="Invalid admin"), 400
            else:
                return jsonify(
                    Error="Unexpected attributes in post request"), 400