Ejemplo n.º 1
0
class Account(Resource):
    decorators = [flask_jwt_extended.jwt_required]

    def __init__(self):
        self.user_controller = UserController()
        self.response_creator = ResponseCreator()

    @errorhandler.internal_server_error
    @errorhandler.user_does_not_exist
    def delete(self):
        username = flask_jwt_extended.get_jwt_identity()
        self.user_controller.delete_user(username)
        return self.response_creator.ok()
Ejemplo n.º 2
0
class Videos(Resource):
    def __init__(self):
        self.video_controller = VideoController()
        self.response_creator = ResponseCreator()
        self.user_controller = UserController()

    @errorhandler.internal_server_error
    @errorhandler.invalid_api_key
    def post(self):
        api_key = request.headers.get('x-api-key')

        user = self.user_controller.get_user_by_api_key(api_key)

        self.video_controller.create_video(request.json, user)
        return self.response_creator.ok()

    @flask_jwt_extended.jwt_required
    @errorhandler.internal_server_error
    def get(self):
        username = flask_jwt_extended.get_jwt_identity()
        videos_dict = self.video_controller.get_videos_by_username(username)
        videos_json = json.dumps(videos_dict)
        return self.response_creator.create_response(videos_json)