Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 26 additions & 11 deletions backend/API/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from functools import wraps
import logging

import os

# --- logger 설정 ---
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
Expand All @@ -24,9 +26,7 @@ def create(schema_cls, data: dict):
class ResultAdapter:
@staticmethod
def to_dict_list(keys, rows):
def sanitize(key, value):
defaults = {"experience": "0", "image": ""}
return value if value is not None else defaults.get(key, "")
sanitize = lambda k, v: v if v is not None else {"experience": "0", "image": ""}.get(k, "")
return [dict(zip(keys, [sanitize(k, v) for k, v in zip(keys, row)])) for row in rows]

# --- Decorator Pattern ---
Expand Down Expand Up @@ -65,32 +65,32 @@ def get_db():
finally:
db.close()

# 1. /get-company-name-and-detail-job
# 입력 없이 회사명과 직무를 드롭다운(초기 접근 시 사용)
@app.post("/get-company-name-and-detail-job", response_model=list[schemas.CompanyAndDetailJob], tags=['회사 기준 검색'])
@safe_handler
def get_company_name_and_detail_job(req: schemas.JobCategoryRequest, db: Session = Depends(get_db)):
req = RequestFactory.create(schemas.JobCategoryRequest, req.dict())
return db.query(RecruitQualification.company_name, RecruitQualification.detail_job)\
.filter(RecruitQualification.job_category == req.job_category).all()

# 회사명을 입력받아 직무를 드롭다운(회사명 우선 선택 시)
@app.post("/get-detail-job-by-company-name", response_model=list[schemas.DetailJob], tags=['회사 기준 검색'])
@safe_handler

def get_detail_job_by_company_name(req: schemas.CompanyNameRequest, db: Session = Depends(get_db)):
req = RequestFactory.create(schemas.CompanyNameRequest, req.dict())
return db.query(RecruitQualification.detail_job)\
.filter(RecruitQualification.company_name == req.company_name).all()


# 직무를 입력받아 회사명을 드롭다운(직무 우선 선택 시)
@app.post("/get-company-name-by-detail-job", response_model=list[schemas.CompanyName], tags=['회사 기준 검색'])
@safe_handler

def get_company_name_by_detail_job(req: schemas.DetailJobRequest, db: Session = Depends(get_db)):
req = RequestFactory.create(schemas.DetailJobRequest, req.dict())
return db.query(RecruitQualification.company_name)\
.filter(RecruitQualification.detail_job == req.detail_job).all()


# 선택한 회사와 직무를 기준으로 모집공고를 받아옴
@app.post("/get-job-posting", response_model=list[schemas.JobPosting], tags=['회사 기준 검색'])
@safe_handler
def get_job_posting(req: schemas.JobPostingRequest, db: Session = Depends(get_db)):
Expand Down Expand Up @@ -124,6 +124,7 @@ def get_job_posting(req: schemas.JobPostingRequest, db: Session = Depends(get_db

return ResultAdapter.to_dict_list(keys, results)

# 회사와 직무를 입력받아 합격자들을 받아옴
@app.post("/get-applicants-by-company-detail-job", response_model=list[schemas.ApplicantSchema], tags=["스펙 기준 검색"])
@safe_handler
def get_applicants_by_company_detail_job(req: schemas.ApplicantSearchByCompanyDetailJobRequest, db: Session = Depends(get_db)):
Expand All @@ -133,6 +134,7 @@ def get_applicants_by_company_detail_job(req: schemas.ApplicantSearchByCompanyDe
Applicant.detail_job == req.detail_job
).all()

# 직무를 입력받아 회사를 드롭다운(직무 먼저 선택 시)
@app.post("/get-company-by-detail-job", response_model=list[schemas.CompanyList], tags=['스펙 기준 검색'])
@safe_handler
def get_companies_by_detail_job(req: schemas.DetailJobOnlyRequest, db: Session = Depends(get_db)):
Expand All @@ -142,6 +144,7 @@ def get_companies_by_detail_job(req: schemas.DetailJobOnlyRequest, db: Session =
query = query.filter(Applicant.detail_job == req.detail_job)
return [{"company": r[0]} for r in query.distinct().all()]

# 회사를 입력받아 직무를 드롭다운(직무 먼저 선택 시)
@app.post("/get-detail-job-by-company", response_model=list[schemas.DetailJobList], tags=['스펙 기준 검색'])
@safe_handler
def get_detail_jobs_by_company(req: schemas.CompanyOnlyRequest, db: Session = Depends(get_db)):
Expand All @@ -151,14 +154,25 @@ def get_detail_jobs_by_company(req: schemas.CompanyOnlyRequest, db: Session = De
query = query.filter(Applicant.company == req.company)
return [{"detail_job": r[0]} for r in query.distinct().all() if r[0] is not None]

# @app.get("/get-all-universities", response_model=list[str], tags=["스펙 기준 검색"])
# @safe_handler
# def get_all_universities(db: Session = Depends(get_db)):
# return [r[0] for r in db.query(Applicant.university)
# .filter(Applicant.university.isnot(None))
# .filter(Applicant.university != "")
# .distinct().all()]

# 모든 대학 드롭다운
@app.get("/get-all-universities", response_model=list[str], tags=["스펙 기준 검색"])
@safe_handler
def get_all_universities(db: Session = Depends(get_db)):
return [r[0] for r in db.query(Applicant.university)
.filter(Applicant.university.isnot(None))
.filter(Applicant.university != "")
.distinct().all()]
extract = lambda row: row[0]
return list(map(extract, db.query(Applicant.university)
.filter(Applicant.university.isnot(None))
.filter(Applicant.university != "")
.distinct().all()))

# 학교를 입력받아 합격자들 드롭다운
@app.post("/get-applicants-by-school", response_model=list[schemas.CompanyAndJob], tags=["스펙 기준 검색"])
@safe_handler
def get_applicants_by_school(req: schemas.SchoolRequest, db: Session = Depends(get_db)):
Expand All @@ -169,6 +183,7 @@ def get_applicants_by_school(req: schemas.SchoolRequest, db: Session = Depends(g
return [{"company": r[0], "detail_job": r[1]} for r in results]


# root
@app.get("/")
def root():
return {"message": "Spectrackr API is live!"}
Expand Down