- B09_Estimation_Edits: 고친 값 한 벌 — 기본 조립(cached_build) 복사본에 얹음(캐시 키에 고친 값) · 기본 벌은 그대로(골든셋 무관)
· 얹지 못한 값은 edit_skipped 로 남김 · 값 없는 슬롯은 받지 않음(422 + 까닭)
- 새 라우터 B09_Estimation_Router_Edits(GET/PUT /estimation/edits) — Router.py 는 _build_for 가 고친 값을 얹게만 바꿈
- 화면: 줄마다 채택 슬롯 고르개 · 일괄(변동없음/1~5 단가/최소단가) · 고친 줄 「사용자」 + ↺(지우면 계산값으로)
- 곁: 사용자 식 셈(B09_Estimation_Expression — ROUND·ROUNDDOWN·INT·SQRT, eval 없음)과 본표 편집 칸(UI_DetailEdit)을 먼저 둠 — 서버 편집 문이 서기 전까지 잠자 있음
- 검증: 시험 1656 통과 · ORCA 채택 저장 → 「사용자」·↺ → ↺ 뒤 고친 값 {} 로 복구 · 값 없는 슬롯 422 「경유: 1번 원천에 값이 없어」
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016VBGFXB9AbJBwXP19z75Qq
87 lines
3.2 KiB
Python
87 lines
3.2 KiB
Python
"""B09 원가계산 라우터 — **사용자가 고친 값** 읽기·저장 (PLAN 12장 2차 · `B09_Estimation_Edits`).
|
|
|
|
⚠ `B09_Estimation_Router.py` 는 쪼개기 차례를 기다리는 중이라(브레인 판정) 새 문을 여기 둠.
|
|
⚠ 저장은 고친 값만 — 금액은 다음 조회 때 서버가 조립 뒤 고친 값을 얹어 **다시 계산**함.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
from typing import Any
|
|
from uuid import UUID
|
|
|
|
from fastapi import APIRouter
|
|
from fastapi.responses import JSONResponse
|
|
from pydantic import BaseModel, Field
|
|
|
|
from B09_Estimation.B09_Estimation_Edits import (
|
|
EDITS_KEY,
|
|
EditError,
|
|
merge_changes,
|
|
normalize,
|
|
)
|
|
|
|
logger = logging.getLogger(__name__)
|
|
router = APIRouter(prefix="/api/projects", tags=["B09 Estimation Edits"])
|
|
|
|
|
|
class EditChange(BaseModel):
|
|
"""고칠 칸 하나 — `value` 가 `null` 이면 그 칸을 지움(↺ 계산값으로 돌아감)."""
|
|
|
|
section: str
|
|
key: str
|
|
value: Any = None
|
|
|
|
|
|
class EditRequest(BaseModel):
|
|
changes: list[EditChange] = Field(default_factory=list)
|
|
|
|
|
|
@router.get("/{project_id}/estimation/edits")
|
|
async def get_edits(project_id: UUID) -> JSONResponse:
|
|
"""고친 값 한 벌 — 화면이 「사용자」 표시·↺ 를 붙이는 데 씀."""
|
|
from B09_Estimation.B09_Estimation_Router import _build_for, _project_root_of
|
|
from common_util.common_util_project_settings import estimation_settings
|
|
|
|
root = await _project_root_of(project_id)
|
|
settings = estimation_settings(root) if root else {}
|
|
build = await _build_for(project_id)
|
|
return JSONResponse(
|
|
content={
|
|
"status": "success",
|
|
EDITS_KEY: normalize(settings.get(EDITS_KEY)),
|
|
"skipped": list(getattr(build, "edit_skipped", [])),
|
|
}
|
|
)
|
|
|
|
|
|
@router.put("/{project_id}/estimation/edits")
|
|
async def put_edits(project_id: UUID, payload: EditRequest) -> JSONResponse:
|
|
"""고친 값 저장 — 칸마다 검사하고(값 없는 슬롯 등은 받지 않음) 구획째 갈아 끼움."""
|
|
from B09_Estimation.B09_Estimation_Router import _build_for, _project_root_of
|
|
from common_util.common_util_project_settings import estimation_settings, save_section
|
|
|
|
root = await _project_root_of(project_id)
|
|
if root is None:
|
|
return JSONResponse(
|
|
status_code=404,
|
|
content={"status": "error", "message": "프로젝트 저장 폴더를 찾지 못했습니다."},
|
|
)
|
|
settings = estimation_settings(root)
|
|
try:
|
|
build = await _build_for(project_id)
|
|
edits = merge_changes(
|
|
settings.get(EDITS_KEY), build, [change.model_dump() for change in payload.changes]
|
|
)
|
|
except EditError as error:
|
|
return JSONResponse(status_code=422, content={"status": "error", "message": str(error)})
|
|
try:
|
|
save_section(root, "estimation", {EDITS_KEY: edits}, replace_keys=(EDITS_KEY,))
|
|
except Exception:
|
|
logger.exception("B09 고친 값 저장 실패: project_id=%s", project_id)
|
|
return JSONResponse(
|
|
status_code=500,
|
|
content={"status": "error", "message": "고친 값을 저장하지 못했습니다."},
|
|
)
|
|
return JSONResponse(content={"status": "success", EDITS_KEY: edits})
|