-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Feat - seminar detail notion api 변경(all로) #44
- Loading branch information
Showing
6 changed files
with
74 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Client } from '@notionhq/client'; | ||
import { NextRequest } from 'next/server'; | ||
|
||
const notion = new Client({ | ||
auth: process.env.NOTION_SECRET_KEY, | ||
}); | ||
|
||
// seminar 데이터 query select, 오름차순 | ||
async function queryAllSeminarData(databaseId: string): Promise<any[]> { | ||
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 member data:', JSON.stringify(error)); | ||
throw error; | ||
} | ||
} | ||
|
||
type Data = { | ||
items?: any[]; | ||
message: string; | ||
}; | ||
|
||
export async function GET(req: NextRequest) { | ||
const databaseId = process.env.NOTION_SEMINAR_DATABASE_ID || ''; | ||
|
||
try { | ||
const data = await queryAllSeminarData(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', | ||
}, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters