diff --git a/srcs/api-gateway-app/app/proxy.py b/srcs/api-gateway-app/app/proxy.py index 5cfb43f..e94e18a 100644 --- a/srcs/api-gateway-app/app/proxy.py +++ b/srcs/api-gateway-app/app/proxy.py @@ -10,7 +10,7 @@ bp = Blueprint("proxy", __name__) -@bp.route('/', methods=["GET", "POST", "DELETE"]) +@bp.route('/', methods=["GET", "POST", "PUT", "DELETE"]) def gateway(path: str): service_mapping = { "movies": diff --git a/srcs/inventory-app/app/movies.py b/srcs/inventory-app/app/movies.py index 11a8d2b..3fd19ec 100644 --- a/srcs/inventory-app/app/movies.py +++ b/srcs/inventory-app/app/movies.py @@ -3,6 +3,8 @@ ) from app.extensions import db +from sqlalchemy.orm.exc import NoResultFound + class Movie(db.Model): __tablename__ = "movies" @@ -88,7 +90,7 @@ def get_movies_id(id): @bp.route("/api/movies/", methods=["PUT"]) -def post_movies_id(id): +def put_movies_id(id): if not request.is_json: return make_response( jsonify({"error": "body must be json"}), 400 @@ -97,15 +99,17 @@ def post_movies_id(id): data = request.get_json() try: movie = Movie.query.filter_by(id=id).one() - movie.title = data["title"] - movie.description = data["description"] + if "title" in data.keys(): + movie.title = data["title"] + if "description" in data.keys(): + movie.description = data["description"] db.session.commit() return { "message": f"movie {movie.id} updated" } - except Exception as inst: + except NoResultFound: return make_response( - jsonify({"error": f"{inst} is required"}), 400 + jsonify(error=f"{id} is not present"), 404 )