def post(self): data = request.get_json() or request.form userId = data['userId'] courseId = data['courseId'] topicId = data['topicId'] sectionTitle = data['sectionTitle'] entityType = data['entityType'] entityId = data['entityId'] sectionId = get_id() if entityId != '': db.insertOne( """ insert into Section (section_id, title, topic_id, entity_type, entity_id) values (%s, %s, %s, %s, %s); """, (sectionId, sectionTitle, topicId, entityType, entityId) ) db.modify( """ update Topic set section_count=section_count+1 where topic_id=%s; """, (topicId,) ) db.modify( """ update Course set section_count=section_count+1 where course_id=%s; """, (courseId,) ) return {"state": "success", "section_id": sectionId}
def post(self): data = request.get_json() or request.form courseId = data['courseId'] title = data['topicTitle'] # Generate ID topicId = get_id() res = db.insertOne( """ insert into Topic (topic_id, title, course_id, section_count) values (%s, %s, %s, %s); """, (topicId, title, courseId, 0) ) if res: db.modify( """ update Course set course_count=course_count+1 where course_id=%s; """, (courseId,) ) return { "state": "success", "topicId": topicId, "title": title }
def post(self): data = request.get_json() or request.form userId = data['userId'] title = data['title'] problemList = data['problems'] relation = data['relation'] topicId = data['topicId'] sectionId = data['sectionId'] courseId = data['courseId'] practiceId = get_id() db.insertOne( """ insert into Practice (practice_id, title, teacher_id, relation, topic_id, section_id, course_id) values (%s, %s, %s, %s, %s, %s, %s); """, (practiceId, title, userId, relation, topicId, sectionId, courseId) ) position = 0 for eachp in problemList: problemId = get_id() content = eachp['content'] choices = eachp['choices'] answer = eachp['answer'] db.insertOne( """ insert into Problem (problem_id, position, content, choices, answer, practice_id) values (%s, %s, %s, %s, %s, %s); """, (problemId, position, content, choices, answer, practiceId) ) position += 1 studentList = db.getAll( """ select student_id from StudnetCourse where course_id=%s; """, (courseId) ) for each in studentList: db.insertOne( """ insert into StudentPractice (student_id, practice_id, status) values (%s, %s, %s); """, (each['student_id'], practiceId, 0) ) db.modify( """ update User set practice_count=practice_count+1 where user_id=%s; """, (each['student_id'],) ) return { "state": "success" }
def post(self): """ POST /api/createCourse """ # Deal with request.data data = request.get_json() or request.form userId = data['userId'] courseTitle = data['courseTitle'] courseDescription = data['courseDescription'] topicCount = data['topics']['count'] topics = data['topics']['details'] # Generate course_id courseId = get_id() respData = {} # SQL Statements db.insertOne( """ insert into Course (course_id, title, description, teacher_id, is_valid) values (%s, %s, %s, %s, %s); """, (courseId, courseTitle, courseDescription, userId, 0) ) res = db.getOne( """ select course_count from User where user_id=%s; """, (userId,) ) if res: courseCount = res['course_count']+1 db.modify( """ update User set course_count=%s where user_id=%s; """, (courseCount, userId) ) if topicCount > 0: db.insertOne( """ insert into Topic (topic_id, title, course_id) values (%s, %s, %s); """, (get_id(), topics[0]['topicTitle'], courseId) ) respData = { "status": "success", "course_id": courseId, "location": "/courseList" } return respData
def post(self): data = request.get_json() or request.form if data['importType'] == 'batch': # Batch Import return { "reason": "Not Supported Temporarily..." } else: # Single Import courseId = data['courseId'] studentList = data['students'] studentCount = len(studentList) for i in range(0, studentCount): studentId = studentList[i]['id'] res = db.query( """ select 1 from User where school_id=%s limit 1; """, (studentId,) ) if res: isIn = db.query( """ select 1 from StudentCourse where student_id=%s and course_id=%s; """, (studentId, courseId) ) if isIn: studentList[i]['state'] = False studentList[i]['reason'] = 'Already Involved.' else: db.insert( """ insert into StudentCourse (student_id, course_id, status) values (%s, %s, %s); """, (studentId, courseId, 0) ) db.modify( """ update User set course_count=course_count+1 where school_id=%s; """, (studentId,) ) studentList[i]['state'] = True else: studentList[i]['state'] = False studentList[i]['reason'] = 'User not Found.' resp = { "state": "success", "students": studentList } return resp
def put(self): data = request.get_json() or request.form courseId = data['courseId'] title = data['title'] description = data['description'] db.modify( """ update Course set title=%s, description=%s where course_id=%s; """, (title, description, courseId) ) return { "state": "success" }
def get(self): state = request.args.get("state") courseId = request.args.get("courseId") cur = 1 if state == False else 0 db.modify( """ update Course set is_valid=%s where course_id=%s; """, (cur, courseId) ) return { "state": "success", "cur": True if cur == 1 else False }
def delete(self): sectionId = request.args.get('sectionId') topicId = db.getOne( """ select topic_id from Section where section_id=%s; """, (sectionId,) )['section_id'] courseId = db.getOne( """ select course_id from Topic where topic_id=%s; """, (topicId,) ) db.delete( """ delete from Section where section_id=%s; """, (sectionId,) ) db.delete( """ delete from Entity where section_id=%s; """, (sectionId,) ) db.modify( """ update Topic set section_count=section_count-1 where topic_id=%s; """, (topicId,) ) db.modify( """ update Course set section_count=section_count-1 where course_id=%s; """, (courseId,) ) return { "state": "success" }
def delete(self): topicId = request.args.get("topicId") courseId = request.args.get("courseId") res = db.delete( """ delete from Topic where topic_id=%s; """, (topicId,) ) if res: sectionIds = db.getAll( """ select section_id from Section where topic_id=%s; """, (topicId,) ) cnt = len(sectionIds) db.delete( """ delete from Section where topic_id=%s; """, (topicId,) ) for i in range(0, cnt): db.delete( """ delete from Entity where section_id=%s; """, (sectionIds[i]['section_id'],) ) db.modify( """ update Course set topic_count=topic_count-1, section_count=section_count-%s; """ ) return { "state": "success" }
def post(self): data = request.get_json() or request.form userId = data['userId'] detail = data['detail'] duration = data['duration'] correctCount = 0 for each in detail: problemId = each['problemId'] answer = each['answer'] correctAnswer = db.getOne( """ select answer from Problem where problem_id=%s; """, (problemId,) ) if answer == correctAnswer: each['status'] = True correctCount += 1 else: each['status'] = False each['correctAnswer'] = correctAnswer db.modify( """ update StudentPractice set status=%s, draft=%s, score=%s, duration=%s where student_id=%s and practice_id=%s; """, (2, detail, correctCount, duration, userId, practiceId) ) respData = { "state": "success", "detail": detail, "score": correctCount } return respData
def put(self): data = request.get_json() or request.form userId = data['userId'] courseId = data['courseId'] topicId = data['topicId'] sectionId = data['sectionId'] sectionTitle = data['sectionTitle'] entityType = data['entityType'] entityId = data['entityId'] db.modify( """ update Section set title=%s, entity_type=%s, entity_id=%s where section_id=%s; """, (sectionTitle, entityType, entityId, sectionId) ) resp = { "state": "success" } return resp
def put(self): data = request.get_json() or request.form topicId = data['topicId'] title = data['topicTitle'] res = db.modify( """ update Topic set title=%s where topic_id=%s; """, (title, topicId) ) if res: return {"state": "success", "topicId": topicId, "title": title}