Skip to content

Commit e301391

Browse files
authored
Merge pull request #171 from huiseong29/React-김희성
[김희성] sprint 7
2 parents dbf4e2a + edc7684 commit e301391

11 files changed

Lines changed: 1126 additions & 17 deletions

File tree

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
REACT_APP_BASE_URL=https://panda-market-api.vercel.app

src/api/authServices.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
const BASE_URL = process.env.REACT_APP_BASE_URL || "";
2+
3+
const handleError = async (res) => {
4+
try {
5+
const errorData = await res.json();
6+
throw new Error(errorData.message || "요청 처리 중 오류가 발생했습니다.");
7+
} catch {
8+
throw new Error("알 수 없는 오류가 발생했습니다.");
9+
}
10+
};
11+
12+
// POST: 회원가입
13+
const postSignUp = async (signUpData) => {
14+
try {
15+
const res = await fetch(`${BASE_URL}/auth/signUp`, {
16+
method: "POST",
17+
headers: {
18+
"Content-Type": "application/json",
19+
},
20+
body: JSON.stringify(signUpData),
21+
});
22+
23+
if (!res.ok) {
24+
return handleError(res);
25+
}
26+
27+
return res.json();
28+
} catch (error) {
29+
console.error("회원가입 요청 실패:", error);
30+
throw new Error("회원가입 요청 중 네트워크 오류가 발생했습니다.");
31+
}
32+
};
33+
34+
// POST: 로그인
35+
const postSignIn = async (signInData) => {
36+
try {
37+
const res = await fetch(`${BASE_URL}/auth/signIn`, {
38+
method: "POST",
39+
headers: {
40+
"Content-Type": "application/json",
41+
},
42+
body: JSON.stringify(signInData),
43+
});
44+
45+
if (!res.ok) {
46+
return handleError(res);
47+
}
48+
49+
return res.json();
50+
} catch (error) {
51+
console.error("로그인 요청 실패:", error);
52+
throw new Error("로그인 요청 중 네트워크 오류가 발생했습니다.");
53+
}
54+
};
55+
56+
// POST: 토큰 갱신
57+
const postRefreshToken = async (refreshToken) => {
58+
try {
59+
const res = await fetch(`${BASE_URL}/auth/refresh-token`, {
60+
method: "POST",
61+
headers: {
62+
"Content-Type": "application/json",
63+
},
64+
body: JSON.stringify({ refreshToken }),
65+
});
66+
67+
if (!res.ok) {
68+
return handleError(res);
69+
}
70+
71+
return res.json();
72+
} catch (error) {
73+
console.error("토큰 갱신 요청 실패:", error);
74+
throw new Error("토큰 갱신 요청 중 네트워크 오류가 발생했습니다.");
75+
}
76+
};
77+
78+
export const authService = {
79+
postSignUp,
80+
postSignIn,
81+
postRefreshToken,
82+
};

src/api/commentService.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/api/commentServices.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
const BASE_URL =
2+
process.env.REACT_APP_BASE_URL || "https://panda-market-api.vercel.app";
3+
4+
// POST: 댓글 작성
5+
const postComment = async (productId, content) => {
6+
const accessToken = localStorage.getItem("accessToken");
7+
8+
const res = await fetch(`${BASE_URL}/products/${productId}/comments`, {
9+
method: "POST",
10+
headers: {
11+
"Content-Type": "application/json",
12+
Authorization: `Bearer ${accessToken}`,
13+
},
14+
body: JSON.stringify({ content }),
15+
});
16+
17+
if (!res.ok) {
18+
const error = await res.json();
19+
throw new Error(error.message || "댓글 등록에 실패하였습니다.");
20+
}
21+
22+
return await res.json();
23+
};
24+
25+
// GET: 댓글 목록 조회
26+
const getComments = async (productId, limit = 5, cursor = null) => {
27+
let url = `${BASE_URL}/products/${productId}/comments?limit=${limit}`;
28+
if (cursor) url += `&cursor=${cursor}`;
29+
30+
const res = await fetch(url);
31+
32+
if (!res.ok) {
33+
const error = await res.json();
34+
throw new Error(error.message || "댓글 목록 조회에 실패하였습니다.");
35+
}
36+
37+
return await res.json();
38+
};
39+
40+
// PATCH: 댓글 수정
41+
const patchComment = async (commentId, content) => {
42+
const accessToken = localStorage.getItem("accessToken");
43+
44+
const res = await fetch(`${BASE_URL}/comments/${commentId}`, {
45+
method: "PATCH",
46+
headers: {
47+
"Content-Type": "application/json",
48+
Authorization: `Bearer ${accessToken}`,
49+
},
50+
body: JSON.stringify({ content }),
51+
});
52+
53+
if (!res.ok) {
54+
const error = await res.json();
55+
throw new Error(error.message || "댓글 수정에 실패하였습니다.");
56+
}
57+
58+
return await res.json();
59+
};
60+
61+
// DELETE: 댓글 삭제
62+
const deleteComment = async (commentId) => {
63+
const accessToken = localStorage.getItem("accessToken");
64+
65+
const res = await fetch(`${BASE_URL}/comments/${commentId}`, {
66+
method: "DELETE",
67+
headers: {
68+
Authorization: `Bearer ${accessToken}`,
69+
},
70+
});
71+
72+
if (!res.ok) {
73+
const error = await res.json();
74+
throw new Error(error.message || "댓글 삭제에 실패하였습니다.");
75+
}
76+
77+
return await res.json();
78+
};
79+
80+
export const commentServices = {
81+
postComment,
82+
getComments,
83+
patchComment,
84+
deleteComment,
85+
};

src/asset/icon/back.svg

Lines changed: 4 additions & 0 deletions
Loading

src/asset/icon/kebab.svg

Lines changed: 5 additions & 0 deletions
Loading

src/asset/icon/large_heart.svg

Lines changed: 3 additions & 0 deletions
Loading

src/asset/image/inquiry_empty.png

6.07 KB
Loading

0 commit comments

Comments
 (0)