260805_01_ENH: 이메일 템플릿 저장 시 빈 칸 유지, 외부 설문에서 리스트 단건 조회, 리스트 헤더조회, 리스트 단건 수정 기능 사용할수 있도록 api 라우트 생성 및 cors 완화

This commit is contained in:
2026-08-05 12:18:35 +09:00
parent 618718585c
commit 6a2265e767
10 changed files with 220 additions and 15 deletions

View File

@@ -0,0 +1,115 @@
import { NextRequest, NextResponse } from "next/server";
import { RouteContext } from "@/types/common";
import { createContactApiWithApiKey } from "@/lib/http-server";
import { errorToResponse } from "@kri/common/http";
import { ListSearchExternal } from "@/types/list";
const getApiKey = (req: NextRequest) => req.headers.get("x-api-key");
// backend가 제공하는 메소드/경로 그대로 사용 (path variable)
export const GET = async (req: NextRequest, context: RouteContext) => {
try {
const apiKey = getApiKey(req);
if (!apiKey) {
return NextResponse.json({ message: "X-API-Key는 필수입니다." }, { status: 401 });
}
const { slug = [] } = await context.params;
const [action, prjctIdx, sid] = slug;
const contactApi = await createContactApiWithApiKey(apiKey);
if (action === "header" && prjctIdx) {
const result = await contactApi.get<string[]>(`/list-external/header/${prjctIdx}`);
return NextResponse.json(result, { status: 200 });
}
if (action === "search" && prjctIdx && sid) {
const result = await contactApi.get<ListSearchExternal>(
`/list-external/search/${prjctIdx}/${encodeURIComponent(sid)}`,
);
return NextResponse.json(result, { status: 200 });
}
return NextResponse.json({ message: "Not found" }, { status: 404 });
} catch (error: unknown) {
return errorToResponse(error);
}
};
// backend가 제공하는 메소드/경로 그대로 사용 (path variable)
export const PATCH = async (req: NextRequest, context: RouteContext) => {
try {
const apiKey = getApiKey(req);
if (!apiKey) {
return NextResponse.json({ message: "X-API-Key는 필수입니다." }, { status: 401 });
}
const { slug = [] } = await context.params;
const [action, prjctIdx, sid] = slug;
if (action === "update" && prjctIdx && sid) {
const body = await req.json().catch(() => null);
const contactApi = await createContactApiWithApiKey(apiKey);
const result = await contactApi.patch<number>(
`/list-external/update/${prjctIdx}/${encodeURIComponent(sid)}`,
body,
);
return NextResponse.json(result, { status: 200 });
}
return NextResponse.json({ message: "Not found" }, { status: 404 });
} catch (error: unknown) {
return errorToResponse(error);
}
};
// 외부 연동 호환용: 항상 POST, path variable을 모두 url 쿼리 파람으로 받아 backend path variable로 전달
export const POST = async (req: NextRequest, context: RouteContext) => {
try {
const apiKey = getApiKey(req);
if (!apiKey) {
return NextResponse.json({ message: "X-API-Key는 필수입니다." }, { status: 401 });
}
const { slug = [] } = await context.params;
const [action] = slug;
const { searchParams } = req.nextUrl;
const prjctIdx = searchParams.get("prjctIdx");
const sid = searchParams.get("sid");
const contactApi = await createContactApiWithApiKey(apiKey);
if (action === "header") {
if (!prjctIdx) {
return NextResponse.json({ message: "prjctIdx는 필수입니다." }, { status: 400 });
}
const result = await contactApi.get<string[]>(`/list-external/header/${prjctIdx}`);
return NextResponse.json(result, { status: 200 });
}
if (action === "search") {
if (!prjctIdx || !sid) {
return NextResponse.json({ message: "prjctIdx, sid는 필수입니다." }, { status: 400 });
}
const result = await contactApi.get<ListSearchExternal>(
`/list-external/search/${prjctIdx}/${encodeURIComponent(sid)}`,
);
return NextResponse.json(result, { status: 200 });
}
if (action === "update") {
if (!prjctIdx || !sid) {
return NextResponse.json({ message: "prjctIdx, sid는 필수입니다." }, { status: 400 });
}
const body = await req.json().catch(() => null);
const result = await contactApi.patch<number>(
`/list-external/update/${prjctIdx}/${encodeURIComponent(sid)}`,
body,
);
return NextResponse.json(result, { status: 200 });
}
return NextResponse.json({ message: "Not found" }, { status: 404 });
} catch (error: unknown) {
return errorToResponse(error);
}
};

View File

@@ -172,6 +172,24 @@
vertical-align: baseline;
}
/* 에디터 편집 화면은 [&_p]:my-2 유틸리티로 문단 사이 margin을 주지만,
미리보기는 Tailwind preflight가 p의 기본 margin을 0으로 리셋해 내용 없는 빈 <p></p>가
높이 0으로 사라진다. 편집 화면과 동일하게 margin을 줘서 빈 줄이 보이도록 한다. */
.kri-editor-preview p {
margin: 0.5em 0;
}
.kri-editor-preview p:first-child {
margin-top: 0;
}
.kri-editor-preview p:last-child {
margin-bottom: 0;
}
/* 내용이 전혀 없는 <p></p>는 높이가 0이라 위/아래 margin이 서로 collapse되어 사라진다.
min-height로 실제 높이를 줘서 collapse를 막아야 빈 줄이 화면에 보인다. */
.kri-editor-preview p:empty {
min-height: 1em;
}
.ProseMirror .ProseMirror-selectednode img {
outline: 5px solid #0ea5e9;
outline-offset: -5px;