Course content #72

Merged
juggy1233 merged 6 commits from #70-course-content into master 2023-04-14 17:02:53 -04:00
Showing only changes of commit 8626fd9a44 - Show all commits

View File

@@ -340,3 +340,22 @@ def delete_content(id):
db.session.delete(c)
db.session.commit()
return jsonify(c.to_dict())
@bp.route("/content/<int:id>", 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())