def post(self): data = parser.parse_args() if CourseModel.query.filter_by(title=data['title']).first(): msg = "A course with title:'{}' already exists.".format( data['title']) return {"message": msg}, 400 course = CourseModel(**data) try: course.save() except: return {"message": "An error occurred while inserting Course"}, 500 return course.json(), 201
def put(self, course_id): data = parser.parse_args() course = CourseModel.find_by_id(course_id) if course is None: new_course = CourseModel(**data) try: new_course.save() except: return {"message": "An error occurred while inserting Course."}, 500 return new_course.json(), 201 try: course.update(**data) except: return {"message": "An error occurred while updating Course."}, 500 return course.json(), 200