源码见:"fastapi_study_road-learning_system_online_courses: fastapi框架实战之--在线课程学习系统"
加入课程
我们先看下加入课程
1.是否登录
2.课程是否存在
3.是否已经存在
4.添加
首先实现逻辑
def get_student_course(db: Session, course: int, student: int):
"""查询学生名下某个课程"""
return db.query(StudentCourse).filter(
StudentCourse.course == course, StudentCourse.student == student,
StudentCourse.status == False).first()
def add_student_course(course_id: int, user: UsernameRole, db: Session):
"""添加课程"""
if user.role == "教师":
return response(code=101503, message="老师不能加入课程")
db_course = get_course_by_id(db, course_id)
if not db_course:
return response(code=101501, message="课程不存在")
db_u

最低0.47元/天 解锁文章
840

被折叠的 条评论
为什么被折叠?



