Esempio n. 1
0
def update_user_about():
    user = get_user(request)

    rjson = request.get_json()

    if rjson is None:
        return jsonify({
            'status': 'error',
            'message': 'No payload present'
        })

    about = rjson.get('about')

    if about is None or len(about) == 0:
        return jsonify({
            'status': 'error',
            'message': 'Please include "about" field.'
        })

    user.about = about
    db.session.add(user)
    db.session.commit()

    return jsonify({
        'status': 'success',
        'message': 'About updated'
    })
Esempio n. 2
0
def get_job_info(id):
    if id is None:
        return jsonify({
            'status': 'error',
            'message': "Invalid Job ID"
        }), 400

    job = Job.query.filter_by(id=id).first()

    user = get_user(request)

    if job is None:
        return jsonify({
            'status': 'error',
            'message': 'Invalid Job ID'
        }), 400

    job_info = job.to_dict()

    if not job.is_owner(user):
        job_info['applied'] = job.has_applied(user)

    return jsonify({
        'status': 'success',
        'message': '',
        'job': job_info
    })
Esempio n. 3
0
def index():
    user = get_user(request)

    return jsonify({
        'status': 'success',
        'message': '',
        'user': user.to_dict()
    })
Esempio n. 4
0
def user_skills_endpoint():
    user = get_user(request)

    rjson = request.get_json()

    if rjson is None:
        return jsonify({
            'status': 'error',
            'message': 'No payload provided'
        })

    if request.method == "DELETE":
        skill = rjson.get('skill')

        user_skill = UserSkills.query.filter_by(user_id=user.id,name=skill).first()

        if user_skill is None:
            return jsonify({
                'status': 'error',
                'message': 'Invalid skill'
            })

        db.session.delete(user_skill)
        db.session.commit()

        return jsonify({
            'status': 'success',
            'message': 'Skill deleted'
        })

    if request.method == "POST":
        skill = rjson.get('skill')

        user_skill = UserSkills.query.filter_by(user_id=user.id,name=skill).first()

        if user_skill is not None:
            return jsonify({
                'status': 'error',
                'message': 'User skill already exists'
            })


        user_skill = UserSkills(user_id=user.id,name=skill)

        user.skills.append(user_skill)

        db.session.add(user_skill)
        db.session.add(user)

        db.session.commit()

        return jsonify({
            'status': 'success',
            'message': 'Skill Added'
        })
Esempio n. 5
0
def add_user_skills_experience():
    user = get_user(request)
    rjson = request.get_json()

    if rjson is None:
        return jsonify({
            'status': 'error',
            'message': 'No data present in the request'
        })

    skills = rjson.get('skills')

    if skills is None or len(skills) == 0:
        return jsonify({
            'status': 'error',
            'message': "Invalid Payload"
        })

    for _skill in skills:
        job_cat_id = _skill['id']
        years_experience = _skill['years_experience']

        job_cat = JobCategory.query.filter_by(id=job_cat_id).first()

        if job_cat is None:
            return jsonify({
                'status': 'error',
                'message': 'Invalid job category id'
            })

        user_experience = UserJobExperience.query.filter_by(user_id=user.id,job_category=job_cat).first()

        if user_experience is None:
            user.job_experience.append(UserJobExperience(job_category=job_cat,years_experience=years_experience))
        else:
            user_experience.years_experience = years_experience
            db.session.add(user_experience)
        db.session.add(user)
    db.session.commit()

    return jsonify({
        'status': 'success',
        'message': 'Experience updated'
    })
Esempio n. 6
0
def list_jobs(filter="all"):
    jobs_info = []
    jobs = Job.query.all()

    if not is_validated_user_request(request):
        if len(jobs) > 0:
            for job in jobs:
                jobs_info.append(job.to_dict())
    else:
        user = get_user(request)

        if filter == "applied":
            if len(user.jobs_applied) > 0:
                for job_app in user.jobs_applied:
                    job = job_app.job

                    ji = job.to_dict()

                    if not job.is_owner(user):
                        ji['applied'] = job.has_applied(user)

                    jobs_info.append(ji)

            return jsonify({
                'status': 'success',
                'message': '',
                'jobs': jobs_info
            })

        if len(jobs) > 0:
            for job in jobs:
                ji = job.to_dict()
                if not job.is_owner(user):
                    ji['applied'] = job.has_applied(user)
                jobs_info.append(ji)

    return jsonify({
        'status': "success",
        'message': "",
        'jobs': jobs_info
    }), 200
Esempio n. 7
0
def apply():
    rjson = request.get_json()

    if rjson is None:
        return jsonify({
            'status': 'error',
            'message': "No data provided"
        }), 400

    job = Job.query.filter_by(id=rjson.get('id')).first()

    if job is None:
        return jsonify({
            'status': 'error',
            'message': 'Invalid Job ID'
        }), 400

    user = get_user(request)

    application = JobApplication.query.filter_by(user_id=user.id, job_id=job.id).first()

    if application is not None:
        return jsonify({
            'status': "error",
            'message': "An application has already been submitted for this job."
        }), 400

    user.jobs_applied.append(JobApplication(user_id=user.id, job_id=job.id))

    db.session.add(user)

    db.session.commit()

    return jsonify({
        'status': 'success',
        'message': "Applied successfully"
    })
Esempio n. 8
0
def search():
    # todo implement job title search.

    rjson = request.get_json()

    if rjson is None:
        return jsonify({
            'status': 'error',
            'message': 'No data provided'
        })

    user = get_user(request)

    search_options = rjson.get('search')

    # radius search variables
    radius_search = False
    radius_km = None
    user_long = None
    user_lat = None

    category = None
    job_type = None

    if 'radius' in search_options.keys():
        user_long = float(search_options['long'])
        user_lat = float(search_options['lat'])

        radius_km = search_options['radius']

        radius_search = True

    if 'category' in search_options.keys():
        category = search_options['category']

        category = JobCategory.query.filter_by(name=category).first()

        if category is None:
            return jsonify({
                'status': 'error',
                'message': 'Invalid category name provided',
                'payload': search_options
            }), 400

    if 'job_type' in search_options.keys():
        job_type = JobType.query.filter_by(name=search_options['job_type']).first()

        if job_type is None:
            return jsonify({
                'status': 'error',
                'message': 'Invalid job type provided',
                'payload': search_options
            }), 400

    if radius_search is False and (category is None or job_type is None):
        return jsonify({
            'status': 'error',
            'message': 'Please check your search settings and try again',
            'payload': search_options
        }), 400

    jobs = None
    # retrieve the jobs in this category

    if job_type is not None:
        jobs = job_type.jobs

    elif category is not None:
        jobs = category.jobs

    jobs = Job.query.all()

    jobs_found = []

    # todo look into reducing the list

    for job in jobs:

        # If doing a radius-based search, check the distance between the user and the jobs host location.
        if radius_search is True and haversine(float(job.longitude), float(job.latitude), user_long, user_lat) > int(
                radius_km):
            continue

        jobs_found.append(job.to_dict())

    return jsonify({
        'status': 'success',
        'message': '',
        'jobs': jobs_found,
        'search_settings': search_options
    })