Exemple #1
0
def create():
    english = Subject.get_by_id(3)
    math = Subject.get_by_id(4)
    life_skills = Subject.get_by_id(5)

    tutor_1 = Tutor.get_by_id(1)
    tutor_2 = Tutor.get_by_id(2)

    start_1 = datetime.datetime(2021, 2, 1, 10, 0)
    end_1 = datetime.datetime(2021, 2, 1, 12, 0)
    duration_1 = (end_1 - start_1).seconds // 60  # convert to minute

    start_2 = datetime.datetime(2021, 2, 1, 11, 0)
    end_2 = datetime.datetime(2021, 2, 1, 13, 0)
    duration_2 = (end_2 - start_2).seconds // 60  # convert to minute

    session = Tutor_session(subject=english,
                            tutor=tutor_1,
                            title="Some title",
                            price=100,
                            duration=duration_1,
                            start_time=start_1,
                            end_time=end_1,
                            max_student_capacity=10,
                            status="Confirmed",
                            zoom_host="",
                            zoom_participant="")

    if session.save():
        flash("session created")
    else:
        flash("error creating session")
    return render_template('home.html', errors=session.errors)
Exemple #2
0
def new():
    params = request.json
    tutor_id = get_jwt_identity()
    tutor = Tutor.get_by_id(tutor_id)

    try:
        new_tutor_session = Tutor_session(
            subject=params.get('subject'),
            tutor_id=tutor.id,
            title=params.get('title'),
            price=params.get('price'),
            description=params.get('description'),
            start_time=(datetime(int(params.get('start_year')),
                                 int(params.get('start_month')),
                                 int(params.get('start_day')),
                                 int(params.get('start_hour')),
                                 int(params.get('start_minute')))),
            end_time=(datetime(int(params.get('end_year')),
                               int(params.get('end_month')),
                               int(params.get('end_day')),
                               int(params.get('end_hour')),
                               int(params.get('end_minute')))),
            max_student_capacity=params.get('max_student_capacity'),
            status="Confirmed",
            status_timestamp=datetime.now(),
            zoom_host=params.get('zoom_host'),
            zoom_participant=params.get('zoom_participant'))
    except:
        responseObject = {
            "status": "failed",
            "message": ['All fields are required!']
        }
        return make_response(jsonify(responseObject)), 400

    if new_tutor_session.save():
        responseObject = ({
            "message": "Successfully created new tutor session.",
            "status": "success!",
            "session": {
                "id": new_tutor_session.id,
                "title": new_tutor_session.title,
                "description": new_tutor_session.description,
                "subject": new_tutor_session.subject_id,
                "tutor_id": new_tutor_session.tutor.id,
                "start_time": new_tutor_session.start_time,
                "end_time": new_tutor_session.end_time,
                "max_student_capacity": new_tutor_session.max_student_capacity,
                "price": new_tutor_session.price,
                "status": new_tutor_session.status,
                "status_timestamp": new_tutor_session.status_timestamp,
                "zoom_host": new_tutor_session.zoom_host,
                "zoom_participant": new_tutor_session.zoom_participant
            }
        })
        return make_response(jsonify(responseObject)), 201
    else:
        return make_response(jsonify([err for err in new_tutor_session.errors
                                      ])), 400
Exemple #3
0
def new():
    student = Student.get_by_id(get_jwt_identity())
    params = request.json

    if student:
        student_tutor_session = Student_tutor_session.get_by_id(params.get("student_tutor_session"))
        tutor_session =  Tutor_session.get_by_id(student_tutor_session.tutor_session_id)
        # duration = tutor_session.duration
        # amount = tutor_session.price * duration # price per hour * hrs
        amount = tutor_session.price

        new_payment = Payment(
            student_tutor_session_id = student_tutor_session.id,
            amount = amount,
            status = 'complete',
            status_timestamp = datetime.now()
        )

    if new_payment.save():
        responseObject = (
            {
                "message" : "Payment completed." ,
                "status" : "success!",
                "payment" : {
                    "id" : new_payment.id,
                    "amount" : new_payment.amount,
                    "status" : new_payment.status,
                    "status_timestamp" : new_payment.status_timestamp,
                    "student_tutor_session" : new_payment.student_tutor_session_id
                }
            }
        )
        return make_response(jsonify(responseObject)), 201
    else:
        return make_response(jsonify([err for err in new_payment.errors])), 400
Exemple #4
0
def delete(id):
    tutor_session = Tutor_session.get_by_id(id)
    tutor = Tutor.get_by_id(get_jwt_identity())

    if tutor_session:
        if tutor_session.tutor_id == tutor.id:
            if tutor_session.delete_instance(recursive=True):
                responseObject = ({
                    "message": "Successfully deleted tutor session.",
                    "status": "success!"
                })
                return make_response(jsonify(responseObject)), 200
            else:
                responseObject = {
                    "status": "failed",
                    "message": "Deleting tutor session failed."
                }
                return make_response(jsonify(responseObject)), 400
        else:
            responseObject = ({
                "message": "No permission to delete tutor session.",
                "status": "failed!"
            })
            return make_response(jsonify(responseObject)), 403
    else:
        responseObject = ({
            "message": "Tutor session does not exist.",
            "status": "failed!"
        })
        return make_response(jsonify(responseObject)), 500
Exemple #5
0
def show_all():
    tutor_sessions = Tutor_session.select()

    tutor_sessions_data = []

    for tutor_session in tutor_sessions:
        tutor_session = model_to_dict(tutor_session)
        tutor_sessions_data.append(tutor_session)

    return make_response(jsonify(tutor_sessions_data)), 200
Exemple #6
0
def create():
    student = Student.get_by_id(2)
    tutor_session = Tutor_session.get_by_id(7)

    new_participant = Student_tutor_session(student=student,
                                            tutor_session=tutor_session,
                                            zoom_host="some zoom link",
                                            zoom_participant="some zoom link")

    if new_participant.save():
        flash("successfully saved")
    else:
        flash("not saved")
    return render_template('home.html', errors=new_participant.errors)
Exemple #7
0
def show_me():
    tutor = Tutor.get_by_id(get_jwt_identity())

    if tutor:
        my_tutor_sessions = Tutor_session.select().where(
            Tutor_session.tutor_id == tutor.id)

        my_tutor_sessions_data = []

        for tutor_session in my_tutor_sessions:
            tutor_session = model_to_dict(tutor_session)
            my_tutor_sessions_data.append(tutor_session)

        return make_response(jsonify(my_tutor_sessions_data)), 200
Exemple #8
0
def create():
    student_tutor_session = Student_tutor_session.get_by_id(1)
    tutor_session =  Tutor_session.get_by_id(student_tutor_session.tutor_session)
    duration = tutor_session.duration 
    amount = tutor_session.price*duration/60 # hourly rate * hrs

    print(f"the amount is {amount}")

    new_payment = Payment(
        student_tutor_session=student_tutor_session,
        amount=amount,
    )

    if new_payment.save():
        flash("transaction saved")
    else:
        flash("transaction failed")
    return render_template('home.html', errors = new_payment.errors)
Exemple #9
0
def show_tutor_tutorsesions(id):
    tutor = Tutor.get_by_id(id)

    if tutor:
        tutor_sessions = Tutor_session.select().where(
            Tutor_session.tutor_id == tutor.id)

        tutor_sessions_data = []

        for tutor_session in tutor_sessions:
            tutor_session = model_to_dict(tutor_session)
            tutor_sessions_data.append(tutor_session)

        return make_response(jsonify(tutor_sessions_data)), 200
    else:
        objectResponse = ({
            "message": "Tutor does not exist.",
            "status": "erroe!"
        })
        return make_response(jsonify(objectResponse)), 404
Exemple #10
0
def unenroll():
    params = request.json
    student = Student.get_by_id(get_jwt_identity())
    tutor_session = Tutor_session.get_by_id(params.get('tutor_session_id'))

    if student:
        student_tutor_session = Student_tutor_session.get(
            Student_tutor_session.tutor_session_id == tutor_session.id)

    if student_tutor_session.delete_instance(recursive=True):
        responseObject = ({
            "message": "Successfully uneroll tutor session.",
            "status": "success!"
        })
        return make_response(jsonify(responseObject)), 200

    else:
        responseObject = {
            "status": "failed",
            "message": "Unenroll tutor session failed."
        }
        return make_response(jsonify(responseObject)), 400
Exemple #11
0
def enroll():
    params = request.json
    student = Student.get_by_id(get_jwt_identity())
    tutor_session = Tutor_session.get_by_id(params.get('tutor_session_id'))

    if student:
        new_participant = Student_tutor_session(
            student=student,
            tutor_session=tutor_session,
            zoom_host="some zoom link",
            zoom_participant="some zoom link")

    if new_participant.save():
        responseObject = ({
            "message": "Successfully enroll student.",
            "status": "success!",
            "student_tutor_session_id": new_participant.id,
            "student": {
                "id":
                new_participant.student.id,
                "name":
                new_participant.student.first_name + " " +
                new_participant.student.last_name,
                "age":
                new_participant.student.age,
                "is_female":
                new_participant.student.is_female
            },
            "tutor_session": {
                "id": tutor_session.id,
            }
        })
        return make_response(jsonify(responseObject)), 201
    else:
        return make_response(jsonify([err
                                      for err in new_participant.errors])), 400
Exemple #12
0
def show(id):
    tutor_session = Tutor_session.get_by_id(id)
    tutor_session_data = model_to_dict(tutor_session)

    return make_response(jsonify(tutor_session_data)), 200