#70 Add endpoint to update content
This commit was merged in pull request #72.
This commit is contained in:
@@ -340,3 +340,22 @@ def delete_content(id):
|
|||||||
db.session.delete(c)
|
db.session.delete(c)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return jsonify(c.to_dict())
|
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())
|
||||||
|
|||||||
Reference in New Issue
Block a user