diff --git a/backend/app/routes.py b/backend/app/routes.py index f70aab3..00f61c7 100644 --- a/backend/app/routes.py +++ b/backend/app/routes.py @@ -340,3 +340,22 @@ def delete_content(id): db.session.delete(c) db.session.commit() return jsonify(c.to_dict()) + + +@bp.route("/content/", methods=["PUT"]) +@login_required +@instructor_required +def update_content(id): + c = Content.query.get(id) + if not c: + return error_response(400, f"Content with id {id} does not exist") + + data = request.get_json() + expected_fields = ["name", "body"] + for d in data: + if d not in expected_fields: + return error_response(400, f"Field {d} was not expected") + + c.from_dict(data) + db.session.commit() + return jsonify(c.to_dict())