Esempio n. 1
0
    def get(self):

        #get the data based on a filter
        data = load_json()

        #dict of filter parameters
        #ex. 'first_name' : "first name filter" etc
        '''
        filters: last name, graduation year, company, job title, industry 

        '''

        filter_params = {}

        try:
            filter_params = data['filter']
        except:
            return {'message': f"filter not defined properly"}, 400

        results = []

        try:
            if (filter_params['grad_year'] != ""):

                results = db.session.query(AlumniModel).join(
                    SchoolModel).filter(
                        AlumniModel.last_name.like(filter_params['last_name'] +
                                                   "%"),
                        AlumniModel.job_company.like(
                            filter_params['job_company'] + "%"),
                        AlumniModel.job_title.like(filter_params['job_title'] +
                                                   "%"),
                        AlumniModel.job_company_industry.like(
                            filter_params['job_company_industry'] + "%"),
                        SchoolModel.name.like("Georgetown%"),
                        extract('year', SchoolModel.end_date) == dt.strptime(
                            filter_params['grad_year'], "%Y").year).all()

            else:
                results = AlumniModel.query.filter(
                    AlumniModel.last_name.like(filter_params['last_name'] +
                                               "%"),
                    AlumniModel.job_company.like(filter_params['job_company'] +
                                                 "%"),
                    AlumniModel.job_title.like(filter_params['job_title'] +
                                               "%"),
                    AlumniModel.job_company_industry.like(
                        filter_params['job_company_industry'] + "%")).all()
        except:
            return {'message': f"error with filters"}, 500

        try:
            alumni = [object_as_dict(person) for person in results]

            return {'alumni': alumni}, 200

        except:
            return {'message': f"error returning alumni"}, 500
Esempio n. 2
0
    def get(self):

        # get the data
        try:
            alumni = [
                object_as_dict(person) for person in AlumniModel.query.all()
            ]

            return {'alumni': alumni}, 200

        except:
            return {'message': f"error returning alumni"}, 500
Esempio n. 3
0
    def get(self):
        # get the admin_data and authenticate the admin
        token = load_header_token()

        # validate the admin
        message, error_code = validate_admin_token(token)
        if message:
            return message, error_code

        # get the data from all the users
        users = [object_as_dict(user) for user in UserModel.query.all()]

        return {'users': users}, 201
Esempio n. 4
0
    def get(self):
        # get the admin_data and authenticate the admin
        token = load_header_token()

        # validate the admin
        message, error_code = validate_admin_token(token)
        if message:
            return message, error_code

        # get all the constants
        constants = [object_as_dict(constant)
                     for constant in FloatConstantModel.query.all()]

        return {'status': 'success', 'constants': constants}, 201
Esempio n. 5
0
    def get(self):
        token = load_header_token()

        privileges, code = validate_admin_token(token)

        if code >= 400:
            return privileges, code

        # else get all the data
        streamers_raw = StreamerModel.query.all()

        # format the streamers raw into a viable dictionary
        streamer_dicts = [
            object_as_dict(streamer) for streamer in streamers_raw
        ]

        return {'status': 'success', 'streamers': streamer_dicts}, 201