示例#1
0
    def get(self, movie_name):
        movie = Movie.get_movie_by_name(movie_name)
        if movie:
            mov = movie_schema.dump(movie)
            return mov, HTTPStatus.OK

        return {'message': 'movie not found'}, HTTPStatus.NOT_FOUND
示例#2
0
    def put(self, movie_name):
        data = request.get_json()
        mov = Movie.get_movie_by_name(movie_name)
        if mov:
            return movie_schema.dump(mov), HTTPStatus.OK

        return {'message': 'movie not found'}, HTTPStatus.NOT_FOUND
示例#3
0
    def post(self):
        data = request.get_json()
        movie_data = {}

        if Movie.get_movie_by_name(data['name']):
            return {'message': 'movie already exist'}, HTTPStatus.BAD_REQUEST

        movie_data = movie_schema.load(data)

        new_movie = Movie(**movie_data)
        db.session.add(new_movie)
        db.session.commit()

        new_movie = movie_schema.dump(new_movie)

        return new_movie, HTTPStatus.CREATED