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

Release: v1.0.2 #392

Merged
merged 6 commits into from
Sep 27, 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
16 changes: 15 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
{
"extends": "next/core-web-vitals"
"extends": "next/core-web-vitals",
"rules": {
"semi": "error",
"quotes": "error",
"jsx-quotes": "error",
"indent": [
"error",
2,
{
"SwitchCase": 1 // Switch 문을 사용할 때 case가 switch보다 한 단계 들여쓰기되도록 합니다.
}
],
"no-tabs": "error",
"max-len": "off"
}
}
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "solitour-frontend",
"version": "1.0.1",
"version": "1.0.2",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
13 changes: 6 additions & 7 deletions src/app/api/auth/google/route.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import { NextResponse } from "next/server";

export function GET() {
const clientId = process.env.GOOGLE_CLIENT_ID;
const redirectUri = `${process.env.NEXT_PUBLIC_GOOGLE_REDIRECT_URL}`;
const clientId = process.env.GOOGLE_CLIENT_ID;
const redirectUri = `${process.env.NEXT_PUBLIC_GOOGLE_REDIRECT_URL}`;
const scope = [
"email",
"profile",
"https://www.googleapis.com/auth/user.phonenumbers.read",
"https://www.googleapis.com/auth/user.gender.read",
"https://www.googleapis.com/auth/user.birthday.read",
].join(" ");
const responseType = "code";
const state = generateRandomString(16); // CSRF 방지를 위한 임의 문자열

const googleAuthUrl = `https://accounts.google.com/o/oauth2/v2/auth?client_id=${clientId}&redirect_uri=${redirectUri}&scope=${scope}&response_type=${responseType}&state=${state}`;
const responseType = "code";
const state = generateRandomString(16); // CSRF 방지를 위한 임의 문자열

const googleAuthUrl = `https://accounts.google.com/o/oauth2/v2/auth?client_id=${clientId}&redirect_uri=${redirectUri}&scope=${scope}&response_type=${responseType}&state=${state}`;

return NextResponse.redirect(googleAuthUrl);
}
Expand All @@ -28,4 +27,4 @@ function generateRandomString(length: number) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
}
8 changes: 4 additions & 4 deletions src/app/api/auth/kakao/getToken/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export async function POST(request: NextRequest) {
// Query string 파싱
const url = new URL(request.url);
const code = url.searchParams.get("code");
const body = await request.json()
const body = await request.json();

// 백엔드에 액세스 토큰 재요청
const backendResponse = await fetch(
Expand All @@ -60,8 +60,8 @@ export async function POST(request: NextRequest) {
},
body: JSON.stringify({
createUserInfoRequest: {
...body
}
...body,
},
}),
cache: "no-store",
credentials: "include",
Expand Down Expand Up @@ -90,4 +90,4 @@ export async function POST(request: NextRequest) {
} catch (error) {
return new NextResponse("서버 에러", { status: 500 });
}
}
}
6 changes: 4 additions & 2 deletions src/app/api/auth/user-image/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ export async function DELETE(request: NextRequest) {
});

if (!response.ok) {
return new NextResponse(`${response.statusText}`, { status: response.status });
return new NextResponse(`${response.statusText}`, {
status: response.status,
});
}

return response;
return response;
}
22 changes: 12 additions & 10 deletions src/app/api/auth/user/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function GET(request: NextRequest) {
// 리프레시 토큰으로 재발급 받아 재요청 보내기 위한 응답
return new NextResponse("Refresh token not found", { status: 401 });
}

// 사용자 정보 조회 API
const response = await fetch(`${process.env.BACKEND_URL}/api/users/info`, {
method: "GET",
Expand All @@ -24,22 +24,22 @@ export async function GET(request: NextRequest) {
},
cache: "no-store",
});

if (response.ok) {
const data = await response.json();
return new NextResponse(JSON.stringify(data), {
status: 200,
});
}

if (response.status == 401) {
return new NextResponse("토큰 만료", {
status: 401,
});
return new NextResponse("토큰 만료", {
status: 401,
});
}

cookies().delete("access_token");
cookies().delete("refresh_token");
cookies().delete("refresh_token");
return new NextResponse("서버 에러", {
status: 500,
});
Expand All @@ -58,7 +58,7 @@ export async function PUT(request: NextRequest) {
}

const requestData = await request.json();
console.log("route.ts 파일1 : ",requestData);
console.log("route.ts 파일1 : ", requestData);

// 사용자 정보 조회 API
const response = await fetch(`${process.env.BACKEND_URL}/api/users/info`, {
Expand All @@ -71,7 +71,7 @@ export async function PUT(request: NextRequest) {
cache: "no-store",
});

if(response.ok) {
if (response.ok) {
return response;
}

Expand Down Expand Up @@ -108,7 +108,9 @@ export async function DELETE(request: NextRequest) {
);

if (!response.ok) {
return new NextResponse(`${response.statusText}`, { status: response.status });
return new NextResponse(`${response.statusText}`, {
status: response.status,
});
}

cookies().delete("access_token");
Expand Down
22 changes: 11 additions & 11 deletions src/app/api/bookmark/gathering/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import { NextRequest, NextResponse } from "next/server";
* 정보 북마크 등록
*/
export async function POST(request: NextRequest) {
const access_cookie = request.cookies.get("access_token");
if (!access_cookie) {
const refresh_cookie = request.cookies.get("refresh_token");
if (!refresh_cookie) {
// 리프레시 토큰이 없으므로 요청 중단
return new NextResponse("Refresh token not found", { status: 403 });
}
// 리프레시 토큰으로 재발급 받아 재요청 보내기 위한 응답
return new NextResponse("Refresh token not found", { status: 401 });
const access_cookie = request.cookies.get("access_token");
if (!access_cookie) {
const refresh_cookie = request.cookies.get("refresh_token");
if (!refresh_cookie) {
// 리프레시 토큰이 없으므로 요청 중단
return new NextResponse("Refresh token not found", { status: 403 });
}
// 리프레시 토큰으로 재발급 받아 재요청 보내기 위한 응답
return new NextResponse("Refresh token not found", { status: 401 });
}

const cookie = request.cookies.get("access_token");
const url = new URL(request.url);
const id = url.searchParams.get("gatheringId");
Expand All @@ -41,7 +41,7 @@ export async function POST(request: NextRequest) {
* 정보 북마크 취소
*/
export async function DELETE(request: NextRequest) {
const access_cookie = request.cookies.get("access_token");
const access_cookie = request.cookies.get("access_token");
if (!access_cookie) {
const refresh_cookie = request.cookies.get("refresh_token");
if (!refresh_cookie) {
Expand Down
69 changes: 39 additions & 30 deletions src/app/api/gathering/bookmark/route.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,48 @@
import { NextRequest, NextResponse } from 'next/server';
import { NextRequest, NextResponse } from "next/server";

interface BookmarkRequestBody {
isBookmarked: boolean;
isBookmarked: boolean;
}

// POST 요청을 처리하는 함수
export async function POST(request: NextRequest) {
const access_cookie = request.cookies.get("access_token");
if (!access_cookie) {
const refresh_cookie = request.cookies.get("refresh_token");
if (!refresh_cookie) {
// 리프레시 토큰이 없으므로 요청 중단
return new NextResponse("Refresh token not found", { status: 403 });
}
// 리프레시 토큰으로 재발급 받아 재요청 보내기 위한 응답
return new NextResponse("Unauthorized", { status: 401 });
const access_cookie = request.cookies.get("access_token");
if (!access_cookie) {
const refresh_cookie = request.cookies.get("refresh_token");
if (!refresh_cookie) {
// 리프레시 토큰이 없으므로 요청 중단
return new NextResponse("Refresh token not found", { status: 403 });
}

try {
// 요청 바디 파싱
const { isBookmarked }: BookmarkRequestBody = await request.json();
const response = await fetch(`${process.env.BACKEND_URL}/api/gatherings/bookmark`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ isBookmarked })
});
if (!response.ok) {
throw new Error('Network response was not ok');
}
return NextResponse.json({ message: 'Bookmark status updated successfully' }, { status: 200 });
} catch (error) {
// 에러 응답 반환
return NextResponse.json({ message: 'Internal Server Error' }, { status: 500 });
// 리프레시 토큰으로 재발급 받아 재요청 보내기 위한 응답
return new NextResponse("Unauthorized", { status: 401 });
}

try {
// 요청 바디 파싱
const { isBookmarked }: BookmarkRequestBody = await request.json();

const response = await fetch(
`${process.env.BACKEND_URL}/api/gatherings/bookmark`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ isBookmarked }),
},
);

if (!response.ok) {
throw new Error("Network response was not ok");
}

return NextResponse.json(
{ message: "Bookmark status updated successfully" },
{ status: 200 },
);
} catch (error) {
// 에러 응답 반환
return NextResponse.json(
{ message: "Internal Server Error" },
{ status: 500 },
);
}
}
49 changes: 27 additions & 22 deletions src/app/api/gathering/detail/route.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { NextRequest, NextResponse } from 'next/server';
import { NextRequest, NextResponse } from "next/server";

export async function GET(request: NextRequest) {
const url = new URL(request.url);
const id = url.searchParams.get('id');
const id = url.searchParams.get("id");

if (!id) {
return NextResponse.json({ error: 'ID가 제공되지 않았습니다.' }, { status: 400 });
}

const access_cookie = request.cookies.get("access_token");
return NextResponse.json(
{ error: "ID가 제공되지 않았습니다." },
{ status: 400 },
);
}

const access_cookie = request.cookies.get("access_token");
if (!access_cookie) {
const refresh_cookie = request.cookies.get("refresh_token");
if (!refresh_cookie) {
Expand All @@ -18,25 +21,27 @@ export async function GET(request: NextRequest) {
// 리프레시 토큰으로 재발급 받아 재요청 보내기 위한 응답
return new NextResponse("Refresh token not found", { status: 401 });
}


try {
const response = await fetch(`${process.env.BACKEND_URL}/api/gatherings/${id}`, {
method: "GET",
headers: {
Cookie: `${access_cookie?.name}=${access_cookie?.value}`,
"Content-Type": "application/json",
},
});
const response = await fetch(
`${process.env.BACKEND_URL}/api/gatherings/${id}`,
{
method: "GET",
headers: {
Cookie: `${access_cookie?.name}=${access_cookie?.value}`,
"Content-Type": "application/json",
},
},
);

if (response.status === 200) {
const data = await response.json();
return new NextResponse(JSON.stringify(data), {
status: 200,
});
}
if (response.status === 200) {
const data = await response.json();
return new NextResponse(JSON.stringify(data), {
status: 200,
});
}
} catch (error) {
console.error('서버에서 데이터 처리 중 오류 발생:', error);
return NextResponse.json({ error: '서버 오류' }, { status: 500 });
console.error("서버에서 데이터 처리 중 오류 발생:", error);
return NextResponse.json({ error: "서버 오류" }, { status: 500 });
}
}
12 changes: 4 additions & 8 deletions src/app/api/gathering/finish/route.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { NextRequest } from "next/server";


// 모임 신청 종료 및 재활성화
export async function PUT(
request: NextRequest,
) {
export async function PUT(request: NextRequest) {
try {
const cookie = request.cookies.get("access_token");
const url = new URL(request.url);
const params = url.searchParams;
const cookie = request.cookies.get("access_token");
const url = new URL(request.url);
const params = url.searchParams;
const response = await fetch(
`${process.env.BACKEND_URL}/api/gatherings/${params.get("isFinish") == "false" ? "finish" : "not-finish"}/${params.get("id")}`,
{
Expand All @@ -34,4 +31,3 @@ export async function PUT(
});
}
}

Loading
Loading