def delete_applicant(): email = request.args.get('email') res = session.query(Applicant).filter(Applicant.email == email).all() if not res: response = jsonify({"code": -1, "message": "Email not found"}) return make_response(response, 401) applications = [ application.to_json() for application in session.query(Application).filter( Application.applicant == email) ] paths = [ '/'.join(application['video_name'].split('/')[3:7]) for application in applications ] session.query(Applicant).filter(Applicant.email == email).delete() # #delete profile pic from s3 and all applications applicant submitted bucket = s3_resource.Bucket(bucket_name) bucket.objects.filter(Prefix=f'applicant/{email}').delete() for path in paths: bucket.objects.filter(Prefix=path).delete() session.commit() response = jsonify({ "code": 1, "message": "Successfully deleted applicant" }) return make_response(response, 201)
def get_applications(): applications = [ application.to_json() for application in session.query(Application).all() ] response = jsonify({"code": 1, "applications": applications}) return make_response(response, 201)
def get_application_by_email(): applicant = request.args.get('applicant') applications = [ application.to_json() for application in session.query(Application).filter( Application.applicant == applicant).all() ] response = jsonify({"code": 1, "applications": applications}) return make_response(response, 201)
def get_recruiter(): email = request.args.get('email') recruiter = session.query(Recruiter).filter(Recruiter.email == email).all() if not recruiter: response = jsonify({ "code": -1, "message": "Invalid Email or User not in DB" }) return make_response(response, 401) response = jsonify({"code": 1, "recruiter": recruiter[0].to_json()}) return make_response(response, 201)
def get_job(): recruiter_email = request.args.get('recruiter_email') role = request.args.get('role') job = session.query(Job).filter(Job.recruiter_email == recruiter_email, Job.role == role).all() if not job: response = jsonify({"code": -1, "message": "Invalid Email or role"}) return make_response(response, 401) response = jsonify({"code": 1, "applicant": job[0].to_json()}) return make_response(response, 201)
def register(): req = request.json # CHECKING IF USER EXISTS IN SQL DB try: user_exists = session.query(Applicant).filter(Applicant.email == req["email"]).all() except: try: user_exists = session.query(Recruiter).filter(Recruiter.email == req["email"]).all() except: response = jsonify({"code": -1, "message": "Couldn't Query SQL database for user "+req["email"]+" of user type Applicant nor Recruiter!"}) return make_response(response, 401) if len(user_exists) > 0: response = jsonify({"code": -1, "message": "User "+req["email"]+" already exists in SQL DB!"}) return make_response(response, 401) # ADDING USER TO SQL DB if req["recruiter"]: attr = ['email', 'name', 'company', 'role', 'company_logo_name', 'company_info'] data = [(req['email'], '-', '-','-','-','-')] user_type = Recruiter else: attr = ['email', 'name', 'school_name', 'school_year', 'gpa', 'current_location', 'picture_name'] data = [(req['email'], '-','-','-',3.84,'-','-')] user_type = Applicant try: add_object_to_db(attr, data, user_type) except: response = jsonify({"code": -1, "message": "Couldn't add User to SQL DB!"}) return make_response(response, 401) # ADDING USER TO FIREBASE AUTH DB try: token = auth.create_user_with_email_and_password(req['email'], req['password']) # Create user (Returns error object if unsuccessful - error.message) user = auth.get_account_info(token['idToken']) # (Returns error object if unsuccessful) auth.send_email_verification(token['idToken']) # Send verification email to the user (will set emailVerified field in user object to true if user verifies email) response = jsonify({"code": 1, "message": "Successfully registered "+str(req['email'])+"!"}) return make_response(response, 201) except: response = jsonify({"code": -1, "message": "Couldn't Register User to Firebase, User might exist!"}) return make_response(response, 401)
def get_applicant(): email = request.args.get('email') applicant = session.query(Applicant).filter(Applicant.email == email).all() if not applicant: response = jsonify({ "code": -1, "message": "Invalid Email or User not in DB" }) return make_response(response, 401) response = jsonify({"code": 1, "applicant": applicant[0].to_json()}) return make_response(response, 201)
def get_applied_jobs(): email = request.args.get('email') applicant = session.query(Applicant).filter(Applicant.email == email).all() if not applicant: response = jsonify({ "code": -1, "message": "Invalid Email or User not in DB" }) return make_response(response, 401) jobs_applied = [job.to_json() for job in applicant[0].jobs] response = jsonify({"code": 1, "jobs": jobs_applied}) return make_response(response, 201)
def get_posted_jobs(): email = request.args.get('email') recruiter = session.query(Recruiter).filter(Recruiter.email == email).all() if not recruiter: response = jsonify({ "code": -1, "message": "Invalid Email or User not in DB" }) return make_response(response, 401) jobs = [job.to_json() for job in recruiter[0].jobs] response = jsonify({"code": 1, "jobs": jobs}) return make_response(response, 201)
def get_application(): applicant = request.args.get('applicant') recruiter = request.args.get('recruiter') role = request.args.get('role') application = session.query(Application).filter( Application.applicant == applicant, Application.recruiter == recruiter, Application.role == role).all() if not application: response = jsonify({ "code": -1, "message": "Application does not exists" }) return make_response(response, 401) response = jsonify({"code": 1, "application": application[0].to_json()}) return make_response(response, 201)
def delete_recruiter(): email = request.args.get('email') res = session.query(Recruiter).filter(Recruiter.email == email).delete() if res == 0: response = jsonify({"code": -1, "message": "Email not found!"}) return make_response(response, 401) #delete company logo from s3 bucket = s3_resource.Bucket(bucket_name) bucket.objects.filter(Prefix=f'recruiter/{email}').delete() bucket.objects.filter(Prefix=f'application/{email}').delete() session.commit() response = jsonify({ "code": 1, "message": "Successfully deleted recruiter!" }) return make_response(response, 201)
def add_files(): recruiter = request.args.get('recruiter') role = request.args.get('role') applicant = request.args.get('applicant') resume = request.files['myResume'] cover = request.files['myCover'] video = request.files['myVideo'] files = [resume, cover, video] resume_destination = f'application/{recruiter}/{role}/{applicant}/{resume.filename}' cover_destination = f'application/{recruiter}/{role}/{applicant}/{cover.filename}' video_destination = f'application/{recruiter}/{role}/{applicant}/{video.filename}' destinations = [resume_destination, cover_destination, video_destination] resume_url = f'https://{bucket_name}.s3.amazonaws.com/' + resume_destination cover_url = f'https://{bucket_name}.s3.amazonaws.com/' + cover_destination video_url = f'https://{bucket_name}.s3.amazonaws.com/' + video_destination application = session.query(Application).filter( Application.applicant == applicant, Application.recruiter == recruiter, Application.role == role).all() if not application: response = jsonify({ "code": -1, "message": "Invalid Email or User not in DB" }) return make_response(response, 401) #update applicant object with s3 obj url application[0].resume_name = resume_url application[0].cover_letter_name = cover_url application[0].video_name = video_url session.commit() #write files to s3 for file, destination in zip(files, destinations): if file == video: upload_file(file, destination, video=True) else: upload_file(file, destination) response = jsonify({"code": 1, "message": 'added files to application'}) return make_response(response, 201)
def adding_profile_pic(): email = request.args.get('email') file = request.files['myFile'] file_name = file.filename destination = f'applicant/{email}/{file_name}' #update applicant object with s3 obj url obj_url = f'https://{bucket_name}.s3.amazonaws.com/applicant/{email}/{file_name}' applicant = session.query(Applicant).filter(Applicant.email == email).all() if not applicant: response = jsonify({ "code": -1, "message": "Invalid Email or User not in DB" }) return make_response(response, 401) upload_file(file, destination) applicant[0].picture_name = obj_url session.commit() response = jsonify({"code": 1, "message": 'added profile pic'}) return make_response(response, 201)
def adding_profile_pic(): email = request.args.get('email') file = request.files['myFile'] file_name = file.filename destination = f'recruiter/{email}/{file_name}' upload_file(file, destination) #update recruiter object with s3 obj url obj_url = f'https://{bucket_name}.s3.amazonaws.com/recruiter/{email}/{file_name}' recruiter = session.query(Recruiter).filter(Recruiter.email == email).all() if not recruiter: response = jsonify({ "code": -1, "message": "Invalid Email or User not in DB" }) return make_response(response, 401) recruiter[0].company_logo_name = obj_url session.commit() response = jsonify({"code": 1, "message": 'added company logo'}) return make_response(response, 201)
def remove_application(): applicant = request.args.get('applicant') recruiter = request.args.get('recruiter') role = request.args.get('role') res = session.query(Application).filter(Application.applicant == applicant, Application.recruiter == recruiter, Application.role == role).delete() if res == 0: response = jsonify({"code": -1, "message": "application not found"}) return make_response(response, 401) #Delete static files from s3 bucket = s3_resource.Bucket(bucket_name) bucket.objects.filter( Prefix=f'application/{recruiter}/{role}/{applicant}').delete() session.commit() response = jsonify({ "code": 1, "message": "Successfully deleted application" }) return make_response(response, 201)
def get_jobs(): jobs = [job.to_json() for job in session.query(Job).all()] response = jsonify({"code": 1, "jobs": jobs}) return make_response(response, 201)
def get_recruiters(): recruiters = [ recruiter.to_json() for recruiter in session.query(Recruiter).all() ] response = jsonify({"code": 1, "recruiter": recruiters}) return make_response(response, 201)