Пример #1
0
    def get(self):
        """Get heroes"""
        try:
            heroes = Hero.search_heroes(request.args.get('name'))
            response = {
                'heroes': [],
            }
            # Vamos percorer os herois e transformar em json
            for hero in heroes:
                response['heroes'].append(hero.to_dict())
            if heroes:
                return response['heroes']
            return {'message': 'Hero not found'}, 404

        except Exception as error:
            return {'message': 'Bad request, param name is required'}, 400
    def get(self):
        """Get heroes"""
        try:
            heroes = Hero.search_heroes(request.args.get('name'))
            response = {
                'heroes': [],
            }
            for hero in heroes:
                response['heroes'].append(hero.to_dict())
            if response['heroes']:
                return response['heroes']
            return {'message': 'Bad request, param name is required'}, 400

        except Exception as error:
            return {
                'message': 'Error on get heroes',
                'details': str(error)
            }, 500