summaryrefslogtreecommitdiff
path: root/app/api/projects/code-to-id/route.ts
blob: f2fdb3c5190c086367b0da950c63fffd46699f71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// app/api/projects/code-to-id/route.ts
import { NextRequest, NextResponse } from "next/server"
import { getProjectIdByCode } from "@/lib/swp/project-utils"

/**
 * 프로젝트 코드로 프로젝트 ID 조회
 * 
 * GET /api/projects/code-to-id?code=PROJ_CODE
 */
export async function GET(request: NextRequest) {
  try {
    const { searchParams } = new URL(request.url)
    const code = searchParams.get("code")

    if (!code) {
      return NextResponse.json(
        { success: false, message: "프로젝트 코드(code)가 필요합니다" },
        { status: 400 }
      )
    }

    const projectId = await getProjectIdByCode(code)

    if (!projectId) {
      return NextResponse.json(
        { success: false, message: "프로젝트를 찾을 수 없습니다" },
        { status: 404 }
      )
    }

    return NextResponse.json({
      success: true,
      projectId,
    })

  } catch (error) {
    console.error("❌ 프로젝트 ID 조회 오류:", error)
    return NextResponse.json(
      { 
        success: false, 
        message: error instanceof Error ? error.message : "조회 중 오류 발생" 
      },
      { status: 500 }
    )
  }
}