Skip to content
Merged
Show file tree
Hide file tree
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
27 changes: 25 additions & 2 deletions backend/app/routers/resumes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@
from ..db import get_db
from ..models import Resume, User
from ..repositories import ResumeRepository
from ..schemas import ResumeCreate, ResumeResponse, ResumeUpdate
from ..schemas import (
ResumeCreate,
ResumePreviewResponse,
ResumeResponse,
ResumeUpdate,
)
from ..services.markdown.generators.resume_generator import (
build_resume_markdown,
)
from ..services.pdf.generators.resume_generator import build_resume_pdf
from ..services.pdf.generators.resume_generator import (
build_resume_pdf,
build_resume_preview,
)
from .download_utils import stream_markdown, stream_pdf

router = APIRouter(prefix="/api/resumes", tags=["resumes"])
Expand Down Expand Up @@ -60,6 +68,21 @@ def create_resume(
) from exc


@router.post("/preview", response_model=ResumePreviewResponse)
def preview_resume(
payload: ResumeCreate,
current_user: User = Depends(get_current_user),
) -> ResumePreviewResponse:
"""保存せずに、職務経歴書を PDF と同じレイアウトに整形した HTML と画面用 CSS を返す。

左右 diff プレビュー(左=保存済み / 右=編集中)の描画に使う。HTML 内の各値ノードには
form パス(``data-fp``)が付与され、FE が変更箇所のハイライト・スクロール先特定に使う。
DB は更新しない。WeasyPrint を通さず HTML 文字列生成のみのため軽量。
"""
html, css = build_resume_preview(payload.model_dump())
return ResumePreviewResponse(html=html, css=css)


@router.get("/latest", response_model=ResumeResponse)
def get_latest_resume(
db: Session = Depends(get_db),
Expand Down
2 changes: 2 additions & 0 deletions backend/app/schemas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
Project,
ProjectTeam,
ResumeCreate,
ResumePreviewResponse,
ResumeQualificationItem,
ResumeResponse,
ResumeUpdate,
Expand Down Expand Up @@ -58,6 +59,7 @@
"Project",
"ProjectTeam",
"ResumeCreate",
"ResumePreviewResponse",
"ResumeQualificationItem",
"ResumeResponse",
"ResumeUpdate",
Expand Down
12 changes: 12 additions & 0 deletions backend/app/schemas/resume.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,15 @@ class ResumeResponse(ResumeBase):
def serialize_as_jst(self, dt: datetime) -> str:
"""UTC datetime を JST (UTC+9) の ISO 8601 文字列にシリアライズする。"""
return to_jst(dt).isoformat()


class ResumePreviewResponse(BaseModel):
"""保存前プレビュー(左右 diff 表示)用の整形済み HTML と画面用 CSS。

DB を更新せず、編集中 payload を PDF と同じレイアウトに整形した HTML を返す。
HTML 内の各値ノードには form パス(``data-fp``)が付与され、FE が変更箇所の
ハイライト・スクロール先特定に使う。
"""

html: str
css: str
Loading
Loading