diff options
Diffstat (limited to 'app/api/tbe')
| -rw-r--r-- | app/api/tbe/sessions/[sessionId]/vendor-questions/route.ts | 131 | ||||
| -rw-r--r-- | app/api/tbe/sessions/[sessionId]/vendor-remarks/route.ts | 57 |
2 files changed, 188 insertions, 0 deletions
diff --git a/app/api/tbe/sessions/[sessionId]/vendor-questions/route.ts b/app/api/tbe/sessions/[sessionId]/vendor-questions/route.ts new file mode 100644 index 00000000..8308b040 --- /dev/null +++ b/app/api/tbe/sessions/[sessionId]/vendor-questions/route.ts @@ -0,0 +1,131 @@ +// app/api/tbe/sessions/[sessionId]/vendor-questions/route.ts + +import { NextRequest, NextResponse } from "next/server" +import { getServerSession } from "next-auth" +import { authOptions } from "@/app/api/auth/[...nextauth]/route" +import { + addVendorQuestion, + getVendorQuestions, + answerVendorQuestion +} from "@/lib/tbe-last/vendor-tbe-service" + +interface Props { + params: { + sessionId: string + } +} + +// GET: 질문 목록 조회 +export async function GET( + request: NextRequest, + { params }: Props +) { + try { + const session = await getServerSession(authOptions) + if (!session?.user?.companyId) { + return NextResponse.json( + { error: "Unauthorized" }, + { status: 401 } + ) + } + + const vendorId = typeof session.user.companyId === 'string' + ? parseInt(session.user.companyId) + : session.user.companyId + + const sessionId = parseInt(params.sessionId) + + const questions = await getVendorQuestions(sessionId, vendorId) + + return NextResponse.json(questions) + + } catch (error) { + console.error("Get questions error:", error) + return NextResponse.json( + { error: "Failed to get questions" }, + { status: 500 } + ) + } +} + +// POST: 새 질문 추가 +export async function POST( + request: NextRequest, + { params }: Props +) { + try { + const session = await getServerSession(authOptions) + if (!session?.user?.companyId) { + return NextResponse.json( + { error: "Unauthorized" }, + { status: 401 } + ) + } + + const vendorId = typeof session.user.companyId === 'string' + ? parseInt(session.user.companyId) + : session.user.companyId + + const sessionId = parseInt(params.sessionId) + const body = await request.json() + + const question = await addVendorQuestion( + sessionId, + vendorId, + { + category: body.category || "general", + question: body.question, + priority: body.priority || "normal", + status: "open" + } + ) + + return NextResponse.json(question) + + } catch (error) { + console.error("Add question error:", error) + return NextResponse.json( + { error: "Failed to add question" }, + { status: 500 } + ) + } +} + +// PATCH: 질문에 답변 추가 (구매자용) +export async function PATCH( + request: NextRequest, + { params }: Props +) { + try { + const session = await getServerSession(authOptions) + if (!session?.user) { + return NextResponse.json( + { error: "Unauthorized" }, + { status: 401 } + ) + } + + const sessionId = parseInt(params.sessionId) + const body = await request.json() + + const { questionId, answer } = body + + if (!questionId || !answer) { + return NextResponse.json( + { error: "Question ID and answer are required" }, + { status: 400 } + ) + } + + const result = await answerVendorQuestion(sessionId, questionId, answer) + + return NextResponse.json(result) + + } catch (error) { + console.error("Answer question error:", error) + return NextResponse.json( + { error: "Failed to answer question" }, + { status: 500 } + ) + } +}
\ No newline at end of file diff --git a/app/api/tbe/sessions/[sessionId]/vendor-remarks/route.ts b/app/api/tbe/sessions/[sessionId]/vendor-remarks/route.ts new file mode 100644 index 00000000..d2dc7797 --- /dev/null +++ b/app/api/tbe/sessions/[sessionId]/vendor-remarks/route.ts @@ -0,0 +1,57 @@ +// ========================================== +// app/api/tbe/sessions/[sessionId]/vendor-remarks/route.ts +// ========================================== + +import { NextRequest, NextResponse } from "next/server" +import { getServerSession } from "next-auth" +import { authOptions } from "@/app/api/auth/[...nextauth]/route" +import { updateVendorRemarks } from "@/lib/tbe-last/vendor-tbe-service" + +interface Props { + params: { + sessionId: string + } +} + +// PUT: 벤더 의견 업데이트 +export async function PUT( + request: NextRequest, + { params }: Props +) { + try { + const session = await getServerSession(authOptions) + if (!session?.user?.companyId) { + return NextResponse.json( + { error: "Unauthorized" }, + { status: 401 } + ) + } + + const vendorId = typeof session.user.companyId === 'string' + ? parseInt(session.user.companyId) + : session.user.companyId + + const sessionId = parseInt(params.sessionId) + const body = await request.json() + + const { remarks } = body + + if (!remarks) { + return NextResponse.json( + { error: "Remarks are required" }, + { status: 400 } + ) + } + + const updated = await updateVendorRemarks(sessionId, vendorId, remarks) + + return NextResponse.json(updated) + + } catch (error) { + console.error("Update remarks error:", error) + return NextResponse.json( + { error: "Failed to update remarks" }, + { status: 500 } + ) + } +}
\ No newline at end of file |
