def get_jobs(): jobs = Job.query.all() jobs_list = [] for job in jobs: job_object = db_object_as_dict(job) jobs_list.append(job_object) response_object = {'status': 'success', 'data': jobs_list} return jsonify(response_object), 200
def get_jobs_by_status_and_worker(worker_id): jobs = Job.query.filter_by(worker=worker_id, status="Pending") jobs_list = [] for job in jobs: job_object = db_object_as_dict(job) jobs_list.append(job_object) response_object = {'status': 'success', 'data': jobs_list} return jsonify(response_object), 200
def get_jobs_by_status_and_employer(employer_id): jobs = Job.query.filter_by(employer=employer_id, status="pending") jobs_list = [] for job in jobs: job_object = db_object_as_dict(job) jobs_list.append(job_object) db.session.commit() response_object = { 'status': 'success', } return jsonify(response_object), 200
def get_users(): users = User.query.all() users_list = [] for user in users: user_object = db_object_as_dict(user) users_list.append(user_object) response_object = { 'status': 'success', 'data': users_list } return jsonify(response_object), 200
def post_job(): details = request.json job = Job() for key, value in details.items(): try: setattr(job, key, value) except: pass db.session.add(job) db.session.commit() job_object = db_object_as_dict(job) response_object = {'status': 'success', 'data': job_object} return jsonify(response_object), 200
def update_job(job_id): updatedable_fields = [ 'status', 'worker', 'start_time', 'end_time', 'description' ] details = request.json job = Job.query.filter_by(id=job_id).first() for key, value in details.items(): if key in updatedable_fields: setattr(job, key, value) print(job.description) job_object = db_object_as_dict(job) db.session.commit() response_object = {'status': 'success', 'data': job_object} return jsonify(response_object), 201
def get_available_job_employer(employer): job = Job.query.filter_by(employer=employer, status="available").first() job_object = db_object_as_dict(job) response_object = {'status': 'success', 'data': job_object} return jsonify(response_object), 200
def get_single_job(job_id): job = Job.query.filter_by(id=job_id).first() job_object = db_object_as_dict(job) response_object = {'status': 'success', 'data': job_object} return jsonify(response_object), 200