Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[✨Feature] 프로젝트 노션 크롤링 적용 #53

Merged
merged 6 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,

// notion image doamin

images: {
domains: ['prod-files-secure.s3.us-west-2.amazonaws.com'],
},
Expand Down
120 changes: 117 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes
Binary file added public/images/default_project.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 18 additions & 26 deletions src/app/api/member/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,42 @@ const notion = new Client({
auth: process.env.NOTION_SECRET_KEY,
});

// seminar id를 가진 member 불러오기
async function queryMemberData(databaseId: string, seminarId: string): Promise<any[]> {

async function queryAllMemberData(): Promise<any[]> {
try {
const response = await notion.databases.query({
database_id: databaseId,
filter: {
property: 'Seminars',
relation: {
contains: seminarId
}
},
database_id: process.env.NOTION_MEMBER_DATABASE_ID || '',
});

return response.results;
} catch (error) {
console.error('Error querying Notion database and fetching member data:', JSON.stringify(error));
console.error(JSON.stringify(error));

throw error;
}
}

type Data = {
items?: any[];
message: string;
};

export async function GET(req: NextRequest) {
const url = new URL(req.url);
const seminarId = url.searchParams.get('seminarId') || ''; // 쿼리 파라미터에서 세미나 ID 가져오기
const databaseId = process.env.NOTION_MEMBER_DATABASE_ID || '';

try {
const data = await queryMemberData(databaseId, seminarId);
const data = await queryAllMemberData();

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',

return new Response(
JSON.stringify({ message: `Failed: ${error?.toString()}` }),
{
status: 500,
headers: {
'Content-Type': 'application/json',
},
},
});
);
}
}
}

47 changes: 47 additions & 0 deletions src/app/api/project/all/route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Client } from '@notionhq/client';
import { NextRequest } from 'next/server';

const notion = new Client({
auth: process.env.NOTION_SECRET_KEY,
});
const databaseId = process.env.NOTION_PROJECT_DATABASE_ID || '';

async function queryAllProjectData(): Promise<any[]> {
try {
const response = await notion.databases.query({
database_id: databaseId,
sorts: [
{
property: 'Date',
direction: 'ascending',
},
],
});
return response.results;
} catch (error) {
console.error(JSON.stringify(error));
throw error;
}
}

export async function GET(req: NextRequest) {
try {
const data = await queryAllProjectData();
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',
},
},
);
}
}
Loading
Loading