Ejemplo n.º 1
0
def create_assignment(*,
                      session: Session = Depends(get_session),
                      course_id: int,
                      assignment: AssignmentCreate,
                      current_user: User = Depends(deps.get_current_user)):
    # check that the user is authorized to get this course
    get_course(session, course_id, current_user)
    # create the assignment
    assignment_db = Assignment.from_orm(assignment)
    assignment_db.course_id = course_id  # assign to this course
    session.add(assignment_db)
    session.commit()
    session.refresh(assignment_db)
    return assignment_db
Ejemplo n.º 2
0
def create_course(*,
                  session: Session = Depends(get_session),
                  course: CourseCreate,
                  current_user: User = Depends(deps.get_current_user)):
    db_course = Course.from_orm(course, {"user_id": current_user.id})

    session.add(db_course)
    session.commit()
    session.refresh(db_course)

    new_assignments = []
    for assignment in course.assignments:
        new_assignment = Assignment.from_orm(assignment,
                                             {"course_id": db_course.id})
        new_assignments.append(new_assignment)

    session.add_all(new_assignments)
    db_course.assignments = new_assignments
    session.commit()
    session.refresh(db_course)
    return db_course