- 장 파일 137 개의 표 3,028 · 로직 1,351 줄에 구분(원문 + 부문 · 「건설품셈 공통」) · 상세구분(「03장 토공사」) 칸을 직접 둠 · 파일 머리의 부문·차례는 목록 차례로 남김 - 열 차례 — 표는 키 · 원문번호 · 구분 · 상세구분 · 이름 · 기준 · 출처 · 비고 · 조건 · 범위규칙 · 값칸 · 줄 · 주 · 그룹(맨 뒤) · 로직은 소유 다음에 비고 - 서버 — GET /subs?group= 이 구분·상세구분 목록(장 차례대로) · GET /tables 가 파일을 가로질러 구분·상세구분·찾기로 거르고 쪽 나눔 · GET /logics 도 구분·상세구분으로 거름 · 새 줄은 서버가 갈래를 채움 · 죽은 book 칸 걷어냄 - check_master 가 구분·상세구분이 파일 머리·이름과 맞는지 봄 · adopt 가 빌더 줄에 갈래를 찍어 되돌리기 시험 글자까지 같음 · _틀.md · 화면 계약 · 화면 트리 · 시험 같이 고침 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JgUhN55Z3BCYhUJTjwTNfj
134 lines
3.2 KiB
Python
134 lines
3.2 KiB
Python
"""M01 마스터 데이터 관리자 API — 계약 `resources/master_data/_화면_계약.md`.
|
|
|
|
⚠ 권한은 등록하는 쪽(`main.py`)이 `system_admin_only` 로 붙임.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from decimal import Decimal
|
|
from typing import Any, Literal
|
|
|
|
from fastapi import APIRouter, HTTPException
|
|
from pydantic import BaseModel
|
|
|
|
from M01_MasterData import M01_MasterData_Store as store
|
|
|
|
router = APIRouter(prefix="/api/m01", tags=["M01 MasterData"])
|
|
|
|
|
|
class CalcBody(BaseModel):
|
|
key: str
|
|
inputs: dict[str, Any] = {}
|
|
row: dict[str, Any] | None = None # 저장 전 고친 로직 줄(없으면 저장된 파일로)
|
|
file: str | None = None # 새 로직이면 더할 로직 파일
|
|
|
|
|
|
class Change(BaseModel):
|
|
op: Literal["edit", "add", "delete"]
|
|
key: str | None = None
|
|
row: dict[str, Any] | None = None
|
|
|
|
|
|
class FileChanges(BaseModel):
|
|
file: str
|
|
version: str
|
|
changes: list[Change]
|
|
|
|
|
|
class SaveBody(BaseModel):
|
|
files: list[FileChanges]
|
|
|
|
|
|
def _num(v):
|
|
"""Decimal → JSON 수(그냥 두면 글자로 나감)."""
|
|
if isinstance(v, Decimal):
|
|
return int(v) if v == v.to_integral_value() else float(v)
|
|
if isinstance(v, list):
|
|
return [_num(x) for x in v]
|
|
if isinstance(v, dict):
|
|
return {k: _num(x) for k, x in v.items()}
|
|
return v
|
|
|
|
|
|
def _call(fn, *args):
|
|
try:
|
|
return _num(fn(*args))
|
|
except store.StoreError as e:
|
|
raise HTTPException(status_code=e.status, detail=e.detail) from e
|
|
|
|
|
|
@router.get("/groups")
|
|
def get_groups() -> dict:
|
|
return {"groups": _call(store.groups)}
|
|
|
|
|
|
@router.get("/groups/{group}/files")
|
|
def get_files(group: str) -> dict:
|
|
return {"files": _call(store.files_of, group)}
|
|
|
|
|
|
@router.get("/subs")
|
|
def get_subs(file: str = "", group: str = "") -> dict:
|
|
return _call(store.subs, file, group)
|
|
|
|
|
|
@router.get("/rows")
|
|
def get_rows(
|
|
file: str,
|
|
page: int = 1,
|
|
size: int = 50,
|
|
q: str = "",
|
|
unlinked: bool = False,
|
|
sub: str = "",
|
|
detail: str = "",
|
|
) -> dict:
|
|
return _call(store.rows, file, page, size, q, unlinked, sub, detail)
|
|
|
|
|
|
@router.get("/tables")
|
|
def get_tables(
|
|
file: str = "",
|
|
group: str = "",
|
|
sub: str = "",
|
|
detail: str = "",
|
|
q: str = "",
|
|
page: int = 1,
|
|
size: int = 30,
|
|
) -> dict:
|
|
return _call(store.tables, file, group, sub, detail, q, page, size)
|
|
|
|
|
|
@router.get("/table")
|
|
def get_table(file: str, key: str) -> dict:
|
|
return _call(store.table, file, key)
|
|
|
|
|
|
@router.get("/logics")
|
|
def get_logics(sub: str = "", detail: str = "", q: str = "", blocked: int | None = None) -> dict:
|
|
return {"logics": _call(store.logics, sub, detail, q, blocked)}
|
|
|
|
|
|
@router.get("/logic")
|
|
def get_logic(key: str) -> dict:
|
|
return _call(store.logic, key)
|
|
|
|
|
|
@router.get("/elements")
|
|
def get_elements(group: str, q: str = "", limit: int = 50) -> dict:
|
|
return _call(store.elements, group, q, limit)
|
|
|
|
|
|
@router.get("/pick")
|
|
def get_pick(kind: str, q: str = "", limit: int = 50) -> dict:
|
|
return _call(store.pick, kind, q, limit)
|
|
|
|
|
|
@router.post("/calc")
|
|
def post_calc(body: CalcBody) -> dict:
|
|
return _call(store.calc, body.key, body.inputs, body.row, body.file)
|
|
|
|
|
|
@router.post("/save")
|
|
def post_save(body: SaveBody) -> dict:
|
|
return {"files": _call(store.save, [f.model_dump() for f in body.files])}
|