feat(M01): 새로 만들기 모달에 새 길 잇기 — 절 목록으로 원문 절 고르기 · 절로 표 거르기 · 표 조건 값 목록 · 초안 시험 계산 · 자체 로직 저장(GX) · 본떠 만들기
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WRFJmmhPi4exAzHgPZHMT
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
* ========================================================================== */
|
||||
|
||||
import { API_BASE_URL } from "@config/config_frontend";
|
||||
import { ApiError, type ElementBrief } from "./M01_MasterData_UI_Logic_Api";
|
||||
import { ApiError, type ElementBrief, type LogicRow } from "./M01_MasterData_UI_Logic_Api";
|
||||
|
||||
export interface TableBrief {
|
||||
file: string;
|
||||
@@ -19,10 +19,26 @@ export interface TableBrief {
|
||||
용도?: { 공종?: string; 대상?: string[]; 로직키?: string[] };
|
||||
}
|
||||
|
||||
/** 표 통째 — `줄` 에서 조건 값 목록을 뽑음 */
|
||||
export interface TableFull extends TableBrief {
|
||||
줄?: Record<string, unknown>[];
|
||||
주?: string[];
|
||||
/** 표 조건 칸의 값만(`/table/options`) — 줄을 통째로 받지 않음 */
|
||||
export interface TableInfo {
|
||||
키: string;
|
||||
이름: string;
|
||||
조건?: Record<string, string>;
|
||||
값칸?: Record<string, string>;
|
||||
/** 고르기 조건 = 줄에 나온 값 차례 · 범위 조건 = [[아래, 위]…] */
|
||||
값?: Record<string, (string | number)[] | [number, number][]>;
|
||||
}
|
||||
|
||||
async function postJson<T>(path: string, body: unknown): Promise<T> {
|
||||
const response = await fetch(`${API_BASE_URL}/m01${path}`, {
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
const data = (await response.json().catch(() => ({}))) as { detail?: unknown } & T;
|
||||
if (!response.ok) throw new ApiError(response.status, data.detail ?? response.statusText);
|
||||
return data;
|
||||
}
|
||||
|
||||
async function getJson<T>(path: string, params: Record<string, string>): Promise<T> {
|
||||
@@ -34,31 +50,58 @@ async function getJson<T>(path: string, params: Record<string, string>): Promise
|
||||
return data;
|
||||
}
|
||||
|
||||
/** 책 + 절 번호의 표 — 소요량·계수 둘을 다 봄 · 하위 절(13-4-1-1)도 같이 */
|
||||
/** 원문 절 한 줄 — `/sections` */
|
||||
export interface SectionBrief {
|
||||
book: string;
|
||||
division: string;
|
||||
chapter: string;
|
||||
chapterNo: string;
|
||||
section: string;
|
||||
title: string;
|
||||
/** 그 절(아래 절 포함)의 마스터 표·로직 수 — 0 이면 아직 안 올린 절 */
|
||||
tables: number;
|
||||
logics: number;
|
||||
}
|
||||
|
||||
export const fetchSections = (book: string, division = ""): Promise<SectionBrief[]> =>
|
||||
getJson<{ sections: SectionBrief[] }>("/sections", {
|
||||
book,
|
||||
...(division ? { division } : {}),
|
||||
limit: "2000",
|
||||
}).then((d) => d.sections);
|
||||
|
||||
/** 그 절(아래 절 포함)의 표 — 소요량·계수 둘을 다 봄 */
|
||||
export async function fetchSectionTables(book: string, section: string): Promise<TableBrief[]> {
|
||||
const found = await Promise.all(
|
||||
["소요량", "계수"].map((group) =>
|
||||
getJson<{ tables: TableBrief[] }>("/tables", { group, q: section, size: "100" }),
|
||||
getJson<{ tables: TableBrief[] }>("/tables", { group, section, size: "100" }),
|
||||
),
|
||||
);
|
||||
return found
|
||||
.flatMap((f) => f.tables)
|
||||
.filter(
|
||||
(t) => t.구분 === book && (t.원문번호 === section || t.원문번호.startsWith(`${section}-`)),
|
||||
);
|
||||
return found.flatMap((f) => f.tables).filter((t) => t.구분 === book);
|
||||
}
|
||||
|
||||
const tableCache = new Map<string, Promise<TableFull>>();
|
||||
const tableCache = new Map<string, Promise<TableInfo>>();
|
||||
|
||||
export function fetchTableFull(file: string, key: string): Promise<TableFull> {
|
||||
export function fetchTableInfo(file: string, key: string): Promise<TableInfo> {
|
||||
let got = tableCache.get(key);
|
||||
if (!got) {
|
||||
got = getJson<{ table: TableFull }>("/table", { file, key }).then((d) => d.table);
|
||||
got = getJson<TableInfo>("/table/options", { file, key });
|
||||
tableCache.set(key, got);
|
||||
}
|
||||
return got;
|
||||
}
|
||||
|
||||
/** 자체 로직 만들기 — 키(GX)는 서버가 붙임 */
|
||||
export interface Made {
|
||||
file: string;
|
||||
version: string;
|
||||
key: string;
|
||||
logic: LogicRow;
|
||||
}
|
||||
export const createLogic = (logic: LogicRow): Promise<Made> => postJson("/logic/new", { logic });
|
||||
export const copyLogic = (key: string, name: string): Promise<Made> =>
|
||||
postJson("/logic/copy", { key, 이름: name });
|
||||
|
||||
/** 공표 직종 찾기 */
|
||||
export const searchJobs = (q: string): Promise<{ items: ElementBrief[] }> =>
|
||||
getJson("/pick", { kind: "job", q, limit: "100" });
|
||||
|
||||
Reference in New Issue
Block a user