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 tutor_login():
    params = request.json

    email = params['email']
    password = params['password']

    try:
        user = Tutor.get_or_none(email=email)

        if user and check_password_hash(user.password, password):
            token = create_access_token(identity=user.id)

            responseObject = {
                "token": token,
                "status": "success!",
                "message": "Succesfully logged in.",
                "email": user.email,
                "id": user.id
            }
            return make_response(jsonify(responseObject)), 200
        else:
            response_object = {
                'status': 'error',
                'message': 'Wrong password or email. Try again.'
            }
            return jsonify(response_object), 404

    except Exception as e:
        print(e)
        response_object = {'status': 'error', 'message': 'Try again.'}
        return make_response(jsonify(response_object)), 500
Exemple #3
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 #4
0
def me():
    tutor = Tutor.get_by_id(get_jwt_identity())
    if tutor:
        tutor_data = model_to_dict(tutor)

        return make_response(jsonify(tutor_data)), 200
    else:
        return abort(404)
Exemple #5
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 #6
0
def show_all():
    tutors = Tutor.select()

    tutor_data = []

    for tutor in tutors:
        tutor = model_to_dict(tutor)
        tutor_data.append(tutor)

    return make_response(jsonify(tutor_data)), 200
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 upload():
    tutor = Tutor.get_by_id(1) #hard coded for testing purposes

    file = request.files["profile_photo"]
    file.filename = secure_filename(file.filename)
    image_path = upload_file_to_s3(file, "tutor", tutor.username)

    # save photo url in database
    tutor.profile_image=image_path

    if tutor.save(only=[Tutor.profile_image]):
        flash("Profile photo saved to database successfully!",'info')
    else:
        flash("Unable to save profile photo to database.",'danger')
    return render_template('home.html',errors=tutor.errors)
Exemple #9
0
def update_profile_picture():
    tutor = Tutor.get_by_id(get_jwt_identity())

    file = request.files['profile_image']
    file.filename = secure_filename(file.filename)
    image_path = upload_file_to_s3(file, "tutor", tutor.username)

    tutor.profile_image = image_path

    if tutor.save(only=[Tutor.profile_image]):
        objectResponse = ({
            "message": "Succesfully updated profile image.",
            "status": "success!",
            "image": {
                "url": f"{app.config.get('S3_LOCATION')}{image_path}"
            }
        })
        return make_response(jsonify(objectResponse)), 200
    else:
        return make_response(jsonify([err for err in tutor.errors])), 400
Exemple #10
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 #11
0
    def _write(self):
        self.user = User.get_user_properties({
            'phone': self.phone,
            'login_type': str(self.login_type)
        })

        if not self.is_valid_otp():
            return False
        access_token = generate_access_token()
        self.token_obj = AccessToken.create_token_obj({
            'user_id': self.user.id,
            'token': access_token,
        })

        if self.login_type == 1:
            self.profile_obj = Student.get_or_create({"user_id": self.user.id})
        else:
            self.profile_obj = Tutor.get_or_create({"user_id": self.user.id})

        self.otp_obj.update_otp_obj(is_active=False)
        return True
Exemple #12
0
def new():
    params = request.json

    try:
        new_tutor = Tutor(first_name=params.get("first_name"),
                          last_name=params.get("last_name"),
                          email=params.get("email"),
                          password=params.get("password"),
                          age=params.get("age"),
                          is_female=params.get("is_female"))
    except:
        responseObject = {
            'status': 'failed',
            'message': ['All fields are required!']
        }
        return make_response(jsonify(responseObject)), 400

    if new_tutor.save():
        token = create_access_token(identity=new_tutor.id)
        username = new_tutor.first_name.lower() + new_tutor.last_name.lower(
        ) + str(new_tutor.id)
        new_tutor.username = username
        new_tutor.save(only=[Tutor.username])
        responseObject = ({
            "token": token,
            "message": "Successfully created tutor and signed in.",
            "status": "success!",
            "tutor": {
                "id": new_tutor.id,
                "name": new_tutor.first_name + " " + new_tutor.last_name,
                "age": new_tutor.age,
                "is_female": new_tutor.is_female
            }
        })
        return make_response(jsonify(responseObject)), 201
    else:
        return make_response(jsonify([err for err in new_tutor.errors])), 400
Exemple #13
0
def show(id):
    tutor = Tutor.get_by_id(id)
    tutor_data = model_to_dict(tutor)

    return make_response(jsonify(tutor_data)), 200