def add_job(job_structure): if Job.check_job_structure(job_structure): if not Job.check_job_type(job_structure["job_type"]): return INVALID_JOB_TYPE company_object = Company(job_structure["company"]) recruiter_object = Recruiter(job_structure["recruiter"]) if company_object.check_company() == COMPANY_DOESNOT_EXISTS: return COMPANY_DOESNOT_EXISTS if recruiter_object.check_user_status() == USER_DOESNOT_EXISTS: return USER_DOESNOT_EXISTS JobModel.objects.create( recruiter=recruiter_object.get_recruiter_object(), company=company_object.get_company_object(), job_title=job_structure["job_title"], job_type=job_structure["job_type"], job_qualification=job_structure["job_qualification"], job_location=job_structure["job_location"], salary_range_min=job_structure["salary_range_min"], salary_range_max=job_structure["salary_range_max"], work_experience_min=job_structure["work_experience_min"], work_experience_max=job_structure["work_experience_max"], no_of_opening=job_structure["no_of_opening"], job_description=job_structure["job_description"]) return JOB_ADDED_SUCCESS else: return INVALID_JOB_STRUCTURE
def update_details(self, details): if not User.check_user_type(self.user_type): return INVALID_USER_TYPE if self.user_type == RECRUITER: recruiter = Recruiter(self._user_id) return recruiter.update_details(details) elif self.user_type == FREELANCER: freelancer = Freelancer(self._user_id) return freelancer.update_details(details) elif self.user_type == CANDIDATE: candidate = Candidate(self._user_id) return candidate.update_details(details)
def createUser(user_structure): """ :param user_structure: { "first_name" : "abc", "last_name": "abc", "email_id": "*****@*****.**", "phone_number": "9876543210", "password": "******", "type": "recruiter", ... } :return: code """ # Check valid user type if not User.check_user_structure(user_structure["type"]): return INVALID_USER_TYPE # Check phone number if not User.check_phone_number(user_structure["phone_number"]): return INVALID_PHONE_NUMBER # Create user if user_structure["type"] == RECRUITER: return Recruiter.create_user(user_structure) elif user_structure["type"] == FREELANCER: return Freelancer.create_user(user_structure) elif user_structure["type"] == CANDIDATE: return Candidate.create_user(user_structure)
def check_user(login_structure): """Check user exists or not""" if "password" not in login_structure and \ "type" not in login_structure \ and ("email_id" not in login_structure or "phone_number" not in login_structure): return INVALID_ATTRIBUTES if not User.check_user(login_structure["type"]): return INVALID_USER_TYPE if "email_id" in login_structure: email_id = login_structure["email_id"] password = process_password(login_structure["password"]) if login_structure["type"] == RECRUITER: return Recruiter.check_recruiter_email(email_id=email_id, password=password) elif login_structure["type"] == FREELANCER: return Freelancer.check_freelancer(email_id=email_id, password=password) elif login_structure["type"] == CANDIDATE: return Candidate.check_candidate_email(email_id=email_id, password=password) elif "phone_number" in login_structure: phone_number = login_structure["phone_number"] password = process_password(login_structure["password"]) if login_structure["type"] == RECRUITER: return Recruiter.check_recruiter_phone(phone_number=phone_number, password=password) elif login_structure["type"] == FREELANCER: return Freelancer.check_freelancer(phone_number=phone_number, password=password) elif login_structure["type"] == CANDIDATE: return Candidate.check_candidate_phone(phone_number=phone_number, password=password)
def get_id_from_email(email_id, user_type): if not User.check_user_structure(user_type): return INVALID_USER_TYPE if user_type == RECRUITER: return Recruiter.get_id_from_email(email_id) elif user_type == FREELANCER: return Freelancer.get_id_from_email(email_id) elif user_type == CANDIDATE: return Candidate.get_id_from_email(email_id)
def get_job_by_recruiter(request): if request.method == 'GET': try: token = Token(request) user_id = token.get_user_id() user_type = token.get_user_type() recruiter = Recruiter(user_id=user_id) data = json.loads(request.body.decode()) if "page_number" not in data: return INVALID_ATTRIBUTES res = recruiter.all_jobs_by_recruiter( page_number=data["page_number"]) page_size = recruiter.get_page_count_for_all_jobs() if res == INVALID_PAGE: return HttpResponseBadRequest(json.dumps({'message': res}), content_type='application/json') else: return HttpResponse(json.dumps({ 'pages': page_size, 'data': res }), content_type='application/json') except Exception as e: return HttpResponseServerError(json.dumps({'message': str(e)}), content_type='application/json') else: return HttpResponseBadRequest(json.dumps( {"message": "only get method"}), content_type='application/json')
def add_job(request): if request.method == 'POST': # add job try: job_structure = json.loads(request.body.decode()) res = Job.createUser(job_structure) if res == JOB_ADDED_SUCCESS: return HttpResponse(json.dumps({'message': res}), content_type='application/json') else: return HttpResponseBadRequest(json.dumps({'message': res}), content_type='application/json') except Exception as e: return HttpResponseServerError(json.dumps({'message': str(e)}), content_type='application/json') # Update job elif request.method == 'PUT': try: token = Token(request) user_id = token.get_user_id() user_type = token.get_user_type() recruiter = Recruiter(user_id=user_id) if not recruiter.has_recruiter_posted_job(): return HttpResponseBadRequest(json.dumps( {'message': 'invalid access'}), content_type='application/json') job_structure = json.loads(request.body.decode()) if "id" not in job_structure: return HttpResponseBadRequest(json.dumps( {'message': INVALID_JOB_STRUCTURE}), content_type='application/json') job_object = Job(job_structure["id"]) res = job_object.update_job(job_structure) if res == JOB_UPDATED_SUCCESS: return HttpResponse(json.dumps({'message': res}), content_type='application/json') else: return HttpResponseBadRequest(json.dumps({'message': res}), content_type='application/json') except Exception as e: return HttpResponseServerError(json.dumps({'message': str(e)}), content_type='application/json') else: return HttpResponseBadRequest(json.dumps( {'message': 'invalid request method'}), content_type='application/json')