#35-course-code #36
@@ -108,7 +108,7 @@ def get_courses(id):
|
||||
return resp
|
||||
|
||||
|
||||
@bp.route("/user/<int:uid>/enroll/<int:cid>", methods=["POST"])
|
||||
@bp.route("/user/<int:uid>/enroll/<int:cid>", methods=["POST", "DELETE"])
|
||||
@login_required
|
||||
def enroll_student(uid, cid):
|
||||
u = User.query.get(uid)
|
||||
@@ -119,25 +119,14 @@ def enroll_student(uid, cid):
|
||||
if not c:
|
||||
return error_response(400, f"Course with id {cid} does not exist")
|
||||
|
||||
if request.method == "POST":
|
||||
if not u.enroll(c):
|
||||
return error_response(400, f"User {uid} is already enrolled in course {cid}")
|
||||
|
||||
resp = {"user": u.to_dict(), "course": c.to_dict()}
|
||||
return jsonify(resp)
|
||||
|
||||
|
||||
@bp.route("/user/<int:uid>/enroll/<int:cid>", methods=["DELETE"])
|
||||
@login_required
|
||||
def unenroll_student(uid, cid):
|
||||
u = User.query.get(uid)
|
||||
if not u:
|
||||
return error_response(400, f"User with id {uid} does not exist")
|
||||
|
||||
c = Course.query.get(cid)
|
||||
if not c:
|
||||
return error_response(400, f"Course with id {cid} does not exist")
|
||||
|
||||
elif request.method == "DELETE":
|
||||
if not u.unenroll(c):
|
||||
return error_response(400, f"User {uid} is not enrolled in course {cid}")
|
||||
|
||||
resp = {"user": u.to_dict(), "course": c.to_dict()}
|
||||
return jsonify(resp)
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
work correctly both with client-side routing and a non-root public URL.
|
||||
Learn how to configure a non-root public URL by running `npm run build`.
|
||||
-->
|
||||
<title>React App</title>
|
||||
<title>LearningTree</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
Reference in New Issue
Block a user