|
| 1 | +import uuid |
| 2 | +from typing import Any, List, Optional |
| 3 | +from fastapi import APIRouter, Depends |
| 4 | + |
| 5 | +from pydantic import BaseModel |
| 6 | + |
| 7 | +# もとの認証依存をラップする関数(認証スキップ用) |
| 8 | +def optional_session_dep(skip_auth: bool = True): |
| 9 | + def dependency(): |
| 10 | + if skip_auth: |
| 11 | + return None |
| 12 | + return None |
| 13 | + return Depends(dependency) |
| 14 | + |
| 15 | +def optional_current_user(skip_auth: bool = True): |
| 16 | + def dependency(): |
| 17 | + if skip_auth: |
| 18 | + return None |
| 19 | + return None |
| 20 | + return Depends(dependency) |
| 21 | + |
| 22 | + |
| 23 | +router = APIRouter(prefix="/recruits", tags=["recruits"]) |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | +# Todo: 以下要変更 |
| 28 | +# -> model{APIに合わせてkeyを指定} |
| 29 | +# -> 各アルゴリズム実装 |
| 30 | + |
| 31 | +# ==== 仮のレスポンス用モデル ==== |
| 32 | +class RecruitSearchResult(BaseModel): |
| 33 | + id: uuid.UUID |
| 34 | + title: str |
| 35 | + company: str |
| 36 | + location: str |
| 37 | + description: str |
| 38 | + |
| 39 | +class RecruitSearchResponse(BaseModel): |
| 40 | + results: List[RecruitSearchResult] |
| 41 | + |
| 42 | +class RecruitFeedback(BaseModel): |
| 43 | + recruit_id: uuid.UUID |
| 44 | + reason: str # 例: "Not relevant", "Too far", etc. |
| 45 | + |
| 46 | +# ==== APIエンドポイント ==== |
| 47 | + |
| 48 | +@router.get("/search", response_model=RecruitSearchResponse) |
| 49 | +def fetch_recruits( |
| 50 | + # session保持してやりたいならここ変えなきゃいけない |
| 51 | + session: Optional[Any] = optional_session_dep(skip_auth=True), |
| 52 | + current_user: Optional[Any] = optional_current_user(skip_auth=True), |
| 53 | +) -> Any: |
| 54 | + |
| 55 | + """ |
| 56 | + フロントエンドのフェッチに反応して求人情報を検索 |
| 57 | + """ |
| 58 | + |
| 59 | + |
| 60 | + dummy_data = [ |
| 61 | + RecruitSearchResult( |
| 62 | + id=uuid.uuid4(), |
| 63 | + title="Software Engineer", |
| 64 | + company="Example Corp", |
| 65 | + location="Tokyo", |
| 66 | + description="Develop awesome things", |
| 67 | + ) |
| 68 | + for _ in range(30) |
| 69 | + ] |
| 70 | + return RecruitSearchResponse(results=dummy_data) |
| 71 | + |
| 72 | +@router.post("/feedback") |
| 73 | +def submit_feedback( |
| 74 | + feedback: RecruitFeedback, |
| 75 | + session: Optional[Any] = optional_session_dep(skip_auth=True), |
| 76 | + current_user: Optional[Any] = optional_current_user(skip_auth=True), |
| 77 | +) -> Any: |
| 78 | + """ |
| 79 | + 求人に対するフィードバックを受け取り保存 |
| 80 | + """ |
| 81 | + print(f"Received feedback: {feedback}") |
| 82 | + return {"message": "Feedback received"} |
0 commit comments