Skip to content

Commit

Permalink
feat: apply new crud-master-py changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nprimo authored and Frenchris committed Nov 29, 2023
1 parent 618e6c7 commit d0cbc30
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion srcs/api-gateway-app/app/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
bp = Blueprint("proxy", __name__)


@bp.route('/<path:path>', methods=["GET", "POST", "DELETE"])
@bp.route('/<path:path>', methods=["GET", "POST", "PUT", "DELETE"])
def gateway(path: str):
service_mapping = {
"movies":
Expand Down
14 changes: 9 additions & 5 deletions srcs/inventory-app/app/movies.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
)
from app.extensions import db

from sqlalchemy.orm.exc import NoResultFound


class Movie(db.Model):
__tablename__ = "movies"
Expand Down Expand Up @@ -88,7 +90,7 @@ def get_movies_id(id):


@bp.route("/api/movies/<int:id>", 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
Expand All @@ -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
)


Expand Down

0 comments on commit d0cbc30

Please sign in to comment.