#35 Added course code field to Course model. Updated class functions to reflect change. Also added duplicate checking for create course endpoint
This commit was merged in pull request #36.
This commit is contained in:
@@ -77,7 +77,7 @@ def register():
|
||||
def create_course():
|
||||
data = request.get_json()
|
||||
|
||||
required_fields = ["name", "description", "instructor"]
|
||||
required_fields = ["name", "course_code", "description", "instructor"]
|
||||
|
||||
if f := check_data(data, required_fields):
|
||||
return error_response(400, f"Must supply {f}")
|
||||
@@ -86,6 +86,10 @@ def create_course():
|
||||
if not u:
|
||||
return error_response(400, f"User with id {data['instructor']} does not exist")
|
||||
|
||||
c = Course.query.filter_by(course_code=data["course_code"]).first()
|
||||
if c:
|
||||
return error_response(400, f"Course with course code {data['course_code']} already exists")
|
||||
|
||||
if u.role != "instructor":
|
||||
return error_response(400, "User is not instructor")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user