diff --git a/src/app/api/seminar/open/route.tsx b/src/app/api/seminar/open/route.tsx new file mode 100644 index 0000000..ee213fe --- /dev/null +++ b/src/app/api/seminar/open/route.tsx @@ -0,0 +1,51 @@ +import { Client } from '@notionhq/client'; +import { NextRequest } from 'next/server'; + +const notion = new Client({ + auth: process.env.NOTION_SECRET_KEY, +}); + +async function queryOpenSeminarData(databaseId: string): Promise { + try { + const response = await notion.databases.query({ + database_id: databaseId, + sorts: [ + { + property: 'Date', + direction: 'ascending' + } + ] + }); + + return response.results; + } catch (error) { + console.error('Error querying Notion database and fetching seminar data:', JSON.stringify(error)); + throw error; + } +} + +type Data = { + items?: any[]; + message: string; + }; + + export async function GET(req: NextRequest) { + const databaseId = process.env.NOTION_OPEN_SEMINAR_DATABASE_ID || ''; + + try { + const data = await queryOpenSeminarData(databaseId); + return new Response(JSON.stringify({ data, message: 'Success' }), { + status: 200, + headers: { + 'Content-Type': 'application/json', + }, + }); + } catch (error) { + return new Response(JSON.stringify({ message: `Failed: ${error?.toString()}` }), { + status: 500, + headers: { + 'Content-Type': 'application/json', + }, + }); + } + } \ No newline at end of file diff --git a/src/app/api/seminar/route.tsx b/src/app/api/seminar/route.tsx index bd6fa1f..e1b3b90 100644 --- a/src/app/api/seminar/route.tsx +++ b/src/app/api/seminar/route.tsx @@ -37,8 +37,19 @@ type Data = { }; export async function GET(req: NextRequest) { + const url = new URL(req.url); + const tag = url.searchParams.get('Tag'); // 쿼리 파라미터에서 세미나 ID 가져오기 + + if (!tag) { + return new Response(JSON.stringify({ message: 'Tag is required' }), { + status: 400, + headers: { + 'Content-Type': 'application/json', + }, + }); + } + const databaseId = process.env.NOTION_SEMINAR_DATABASE_ID || ''; - const tag = '🏕️ Camping Seminar'; try { const data = await querySeminarData(databaseId, tag); diff --git a/src/app/seminar/page.tsx b/src/app/seminar/page.tsx index 001d04d..550affa 100644 --- a/src/app/seminar/page.tsx +++ b/src/app/seminar/page.tsx @@ -1,26 +1,39 @@ import SeminarHeader from '@/components/seminar/header/SeminarHeader'; import SeminarThumbnailList from '@/components/seminar/thumbnail/SeminarThumbnailList'; import SeminarToggle from '@/components/seminar/toggle/SeminarToggle'; -import { refactorSeminarData } from '@/hooks/seminar/notionDataRefactor'; +import { refactorOpenSeminarData, refactorSeminarData } from '@/hooks/seminar/notionDataRefactor'; +import NotFoundPage from '../not-found'; const SeminarPage = async () => { // seminar 데이터 가져오기 - const seminarResponse = await fetch('http://localhost:3001/api/seminar'); + const tag = '🏕️ Camping Seminar' + const seminarResponse = await fetch(`http://localhost:3001/api/seminar?Tag=${tag}`); const seminarList = await seminarResponse.json(); - const seminars = refactorSeminarData(seminarList.data || []); + // open seminar 데이터 가져오기 + const openSeminarResponse = await fetch('http://localhost:3001/api/seminar/open'); + const openSeminar = await openSeminarResponse.json(); + const openSeminars = refactorOpenSeminarData(openSeminar.data || {}); + + // 세미나 데이터 + if (!seminars) { + return ; + } + return
-{/* header */} - + + {/* header */} + {/* toggle */} - + {/* seminar list */} - + +