Exemple #1
0
def get_certificate(certificate_id):
    """ GET /api/v1/projects/:project_id """
    the_certificate = storage.get(Certificate, certificate_id)
    if not the_certificate:
        return {"success": False, "message": "Certificate not found"}, 400
    certificate = certificate_schema.dump(the_certificate)
    return {"success": True, "certificate": certificate}, 201
Exemple #2
0
def get_state(state_id):
    """ GET /api/v1/states/:state_id """
    the_state = storage.get(State, state_id)
    if not the_state:
        return {"failed": True, "message": "data not found"}, 400
    state = state_schema.dump(the_state)
    return {"success": True, "message": "data found", "state": state}
Exemple #3
0
def get_jobs(recruiter_id):
    """ GET /api/v1/jobs """
    the_recruiter = storage.get(Recruiter, recruiter_id)
    if not the_recruiter:
        return {"success": False, "message": "Recruiter not found"}, 400
    jobs = jobs_schema.dump(the_recruiter.jobs)
    return {"success": True, "recruiter": the_recruiter.id, "jobs": jobs}, 200
Exemple #4
0
def update_country(country_id):
    """ PUT /api/v1/:country_id """
    the_country = storage.get(Country, country_id)
    if not the_country:
        return {
           "failed": True,
           "message": "data not found"
        }, 400
    if not request.get_json():
        return {
            "failed": True,
            "message": "not a json"
        }, 400
    ignore = ['id', 'created_at', 'updated_at']
    data = request.get_json()
    for key, value in data.items():
        if key not in ignore:
            setattr(the_country, key, value)
    storage.save()
    country = country_schema.dump(the_country)
    return {
        "success": True,
        "message": "updated successfully",
        "country": country
    }, 200
Exemple #5
0
def get_socials(student_id):
    """ GET /api/v1/:student_id/socials """
    the_student = storage.get(Student, student_id)
    if not the_student:
        return {"success": False, "message": "Student not found"}
    socials = social_schema.dump(the_student.social)
    return {"success": True, "socials": socials}, 200
Exemple #6
0
def get_project(project_id):
    """ GET /api/v1/projects/:project_id """
    the_project = storage.get(Project, project_id)
    if not the_project:
        return {"success": False, "message": "Project not found"}, 400
    project = project_schema.dump(the_project)
    return {"success": True, "project": project}, 201
Exemple #7
0
def get_experience(experience_id):
    """ GET /api/v1/projects/:project_id """
    the_experience = storage.get(Experience, experience_id)
    if not the_experience:
        return {"success": False, "message": "Experience not found"}, 400
    experiences = experience_schema.dump(the_experience)
    return {"success": True, "experiences": experiences}, 201
Exemple #8
0
def get_recruiter(recruiter_id):
    """ GET /api/v1/recruiters/:recruiter_id """
    the_recruiter = storage.get(Recruiter, recruiter_id)
    if not the_recruiter:
        return {"success": False, "message": "Recruiter not found"}, 400
    recruiter = recruiter_schema.dump(the_recruiter)
    return {"success": True, "recruiter": recruiter}
Exemple #9
0
def delete_project(project_id):
    """ DELETE /api/v1/projects/:project_id """
    the_project = storage.get(Project, project_id)
    if not project_id:
        return {"success": False, "message": "Project not found"}, 400
    storage.delete(the_project)
    storage.save()
    return {"success": True, "message": "Project deleted successfully"}, 200
Exemple #10
0
def delete_recruiter(recruiter_id):
    """ DELETE /api/v1/recruiters/:recruiter_id """
    the_recruiter = storage.get(Recruiter, recruiter_id)
    if not the_recruiter:
        return {"success": False, "message": "Recruiter not found"}, 400
    storage.delete(the_recruiter)
    storage.save()
    return {"success": True, "message": "deleted successfully"}, 200
Exemple #11
0
def delete_experience(experience_id):
    """ DELETE /api/v1/experiences/:experience_id """
    the_experience = storage.get(Experience, experience_id)
    if not the_experience:
        return {"success": False, "message": "Experience not found"}, 400
    storage.delete(the_experience)
    storage.save()
    return {"success": True, "message": "Experience deleted successfully"}, 200
Exemple #12
0
def delete_job(job_id):
    """ DELETE /api/v1/jobs/job_id """
    the_job = storage.get(Job, job_id)
    if not the_job:
        return {"success": False, "message": "Job not found"}, 400
    storage.delete(the_job)
    storage.save()
    return {"success": True, "message": "Job deleted successfully"}, 200
Exemple #13
0
def delete_state(state_id):
    """ DELETE /api/v1/states/:state_id"""
    the_state = storage.get(State, state_id)
    if not the_state:
        return {"failed": True, "message": "data not found"}, 400
    storage.delete(the_state)
    storage.save()
    return {"success": True, "message": "deleted successfully"}, 200
Exemple #14
0
def delete_certificate(certificate_id):
    """ DELETE /api/v1/certificates/:certificate_id """
    the_certificate = storage.get(Certificate, certificate_id)
    if not certificate_id:
        return {"success": False, "message": "Certificate not found"}, 400
    storage.delete(the_certificate)
    storage.save()
    return {
        "success": True,
        "message": "Certificate deleted successfully"
    }, 200
Exemple #15
0
def get_states(country_id):
    """ GET /api/v1/:country_id/states """
    the_country = storage.get(Country, country_id)
    country = country_schema.dump(the_country)
    states = states_schema.dump(the_country.states)
    return {
        "success": True,
        "message": "data found",
        "country": country,
        "states": states
    }
Exemple #16
0
def get_user_education(student_id):
    """ POST /api/v1/:student_id/educations """
    the_student = storage.get(Student, student_id)
    if not the_student:
        return {"failed": True, "message": "Unrecognized student"}, 400
    educations = educations_schema.dump(the_student.educations)
    return {
        "success": True,
        "count": len(the_student.educations),
        "educations": educations
    }, 201
Exemple #17
0
def get_student_projects(student_id):
    """ POST /api/v1/:student_id/projects """
    the_student = storage.get(Student, student_id)
    if not the_student:
        return {"success": False, "message": "Index not found"}, 400
    projects = projects_schema.dump(the_student.projects)
    return {
        "success": True,
        "count": len(the_student.projects),
        "projects": projects
    }, 201
Exemple #18
0
def delete_education(education_id):
    """ DELETE /api/v1/educations/:education_id """
    the_education = storage.get(Education, education_id)
    if not the_education:
        return {"success": False, "message": "Education not found"}, 400
    storage.delete(the_education)
    storage.save()
    return {
        "success": True,
        "message": "Education deleted successfully",
    }, 200
Exemple #19
0
def get_user_experience(student_id):
    """ POST /api/v1/:student_id/experiences """
    the_student = storage.get(Student, student_id)
    if not the_student:
        return {"success": False, "message": "Index not found"}, 400
    experiences = experiences_schema.dump(the_student.experiences)
    return {
        "success": True,
        "count": len(the_student.experiences),
        "experiences": experiences
    }, 201
Exemple #20
0
def get_user_certificates(student_id):
    """ POST /api/v1/:student_id/certificates """
    the_student = storage.get(Student, student_id)
    if not the_student:
        return {"success": False, "message": "Index not found"}, 400
    certificates = certificates_schema.dump(the_student.certificates)
    return {
        "success": True,
        "count": len(the_student.certificates),
        "certificates": certificates
    }, 201
Exemple #21
0
def get_country(country_id):
    """ GET /api/v1/countries/:country_id """
    the_country = storage.get(Country, country_id)
    if not the_country:
        return {
            "failed": True,
            "message": "data not found"
        }, 400
    country = country_schema.dump(the_country)
    return {
        "message": "data found",
        "country": country
    }
Exemple #22
0
def delete_country(country_id):
    """ DELETE /api/v1/countries/:country_id """
    the_country = storage.get(Country, country_id)
    if not the_country:
        return {
           "failed": True,
           "message": "data not found"
        }, 400
    storage.delete(the_country)
    storage.save()
    return {
        "success": True,
        "message": "deleted successfully"
    }, 200
Exemple #23
0
def update_project(project_id):
    """ PUT /api/v1/projects/:project_id """
    the_project = storage.get(Project, project_id)
    if not the_project:
        return {"success": False, "message": "Project not found"}, 400
    if not request.get_json():
        return {"success": False, "message": "Not a json request"}, 400
    ignore = ['id', 'created_at', 'updated_at', 'student_id']
    data = request.get_json()
    for key, value in data.items():
        if key not in ignore:
            setattr(the_project, key, value)
    storage.save()
    return {"success": True, "message": "Project updated successfully"}, 200
Exemple #24
0
def update_recruiter(recruiter_id):
    """ PUT /api/v1/recruiters/:recruiter_id """
    the_recruiter = storage.get(Recruiter, recruiter_id)
    if not the_recruiter:
        return {"success": False, "message": "Recruiter not found"}, 400
    if not request.get_json():
        return {"success": False, "message": "Not a json"}, 400
    ignore = ['id', 'created_at', 'updated_at', 'user_id']
    data = request.get_json()
    for key, value in data.items():
        if key not in ignore:
            setattr(the_recruiter, key, value)
    storage.save()
    return {"success": True, "message": "Recruiter updated successfully"}, 200
Exemple #25
0
def update_experience(experience_id):
    """ PUT /api/v1/experiences/:experience_id """
    the_experience = storage.get(Experience, experience_id)
    if not request.get_json():
        return {"success": False, "message": "Not a json request"}, 400
    if not the_experience:
        return {"success": False, "message": "Experience not found"}, 400

    ignore = ['id', 'created_at', 'updated_at', 'student_id']
    data = request.get_json()
    for key, value in data.items():
        if key not in ignore:
            setattr(the_experience, key, value)
    storage.save()
    return {"success": True, "message": "Experience updated successfully"}, 200
Exemple #26
0
def upload_logo(recruiter_id):
    """ POST /:recruiter_id/logo """
    the_recruiter = storage.get(Recruiter, recruiter_id)
    if not the_recruiter:
        return {"success": False, "message": "Recruiter not found"}, 400
    target = os.path.join(UPLOAD_FOLDER, recruiter_id)
    if not os.path.isdir(target):
        os.mkdir(target)
    file = request.files['logo']
    filename = secure_filename(file.filename)
    destination = "/".join([target, filename])
    file.save(destination)
    setattr(the_recruiter, 'logo', destination)
    storage.save()
    return {"success": True, "message": "Logo uploaded successfully"}, 200
Exemple #27
0
def update_student_address(student_id):
    """ PUT /api/v1/students/:student_id/address """
    the_student = storage.get(Student, student_id)
    if not the_student:
        return {"success": False, "message": "Recruiter not found"}, 400
    if not request.get_json():
        return {"success": False, "message": "Not a json"}, 400
    ignore = ['id', 'created_at', 'updated_at']
    data = request.get_json()
    the_address = the_student.address
    for key, value in data.items():
        if key not in ignore:
            setattr(the_address, key, value)
    storage.save()
    return {"success": True, "message": "Address updated successfully"}, 200
Exemple #28
0
def create_stacks(recruiter_id):
    """ POST /api/v1/:recruiter_id/stacks """
    the_recruiter = storage.get(Recruiter, recruiter_id)
    if not request.get_json():
        return {"success": False, "message": "Not a json"}, 400
    if not the_recruiter:
        return {"success": False, "message": "Recruiter not found"}, 400
    data = request.get_json()
    for each in data:
        instance = Stack(**each)
        instance.recruiter_id = the_recruiter.id
        instance.save()
    return {
        "success": True,
        "message": "Stacks added successfully",
    }, 201
Exemple #29
0
def add_student_address(student_id):
    """ POST /api/v1/students/:student_id/address """
    the_student = storage.get(Student, student_id)
    if not the_student:
        return {"success": False, "message": "Recruiter not found"}, 400
    if not request.get_json():
        return {"success": False, "message": "not a json"}, 400
    data = request.get_json()
    the_address = Address(**data)
    setattr(the_student, "address_id", the_address.id)
    try:
        the_address.save()
        the_student.save()
        return {"success": True, "message": "Address added successfully"}, 201
    except (IntegrityError, OperationalError) as error:
        the_student.rollback()
        return {"success": False, "message": error.orig.args[1]}, 400
Exemple #30
0
def update_job(job_id):
    """ PUT /api/v1/jobs/:job_id """
    the_job = storage.get(Job, job_id)
    if not the_job:
        return {"success": False, "message": "Job not found"}, 400
    if not request.get_json():
        return {"success": False, "message": "Not a json request"}, 400
    ignore = ['id', 'created_at', 'updated_at', 'recruiter_id']
    data = request.get_json()
    for key, value in data.items():
        if key not in ignore:
            setattr(the_job, key, value)
    storage.save()
    return {
        "success": True,
        "message": "Job updated successfully",
    }, 200