79 lines
2.6 KiB
TypeScript

import { queryStringFormatter } from '@/utils/common-utils'
import axios from 'axios'
import { NextResponse } from 'next/server'
import { loggerWrapper } from '@/libs/api-wrapper'
import { QnaService } from '../service'
import { ApiError } from 'next/dist/server/api-utils'
import { getIronSession } from 'iron-session'
import { SessionData } from '@/types/Auth'
import { sessionOptions } from '@/libs/session'
import { cookies } from 'next/headers'
/**
* @api {GET} /api/qna/detail 문의 상세 조회 API
* @apiName GET /api/qna/detail
* @apiGroup Qna
* @apiDescription 문의 상세 조회 API
*
* @apiParam {String} compCd 회사 코드
* @apiParam {String} qnaNo 문의 번호
* @apiParam {String} langCd 언어 코드
* @apiParam {String} loginId 로그인 ID
*
* @apiExample {curl} Example usage:
* curl -X GET http://localhost:3000/api/qna/detail
*
* @apiSuccessExample {json} Success-Response:
* {
* "data": {
* "compCd": "5200",
* "qnaNo": 51,
* "qstTitle": "Q.CAST TEST",
* "qstContents": "Q.CAST TEST CONTENTS",
* "regDt": "2025.04.29 16:16:51",
* "regId": "X112",
* "regNm": "株式会社アイ工務店",
* "regEmail": "x112@interplug.co.kr",
* "answerYn": "N",
* "ansContents": null,
* ...
* "listFile": [
* {
* "fileNo": 853
* "encodeFileNo": 853,
* "srcFileNm": "Quotation_4500380_20240808145129.pdf",
* "fileCours": "/temp/20250428/"
* "fileSize":160982,
* "regDt":"2024.08.13"
* }
* ...
* ],
* },
* },
* @apiError {Number} 401 세션 정보 없음 (로그인 필요)
* @apiError {Number} 500 서버 오류
*/
async function getQnaDetail(request: Request): Promise<NextResponse> {
const cookieStore = await cookies()
const session = await getIronSession<SessionData>(cookieStore, sessionOptions)
const service = new QnaService(session)
const { searchParams } = new URL(request.url)
const params = {
compCd: searchParams.get('compCd'),
qnaNo: searchParams.get('qnaNo'),
langCd: searchParams.get('langCd'),
siteTpCd: searchParams.get('siteTpCd'),
}
const result = await service.tryFunction(() =>
axios.get(`${process.env.NEXT_PUBLIC_INQUIRY_API_URL}/api/qna/detail?loginId=${session.userId}&${queryStringFormatter(params)}`),
)
if (result instanceof ApiError) {
return NextResponse.json({ error: result.message }, { status: result.statusCode })
}
return NextResponse.json(result.data)
}
export const GET = loggerWrapper(getQnaDetail)