Skip to content
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
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
REACT_APP_BASE_URL=https://panda-market-api.vercel.app
82 changes: 82 additions & 0 deletions src/api/authServices.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
const BASE_URL = process.env.REACT_APP_BASE_URL || "";

const handleError = async (res) => {
try {
const errorData = await res.json();
throw new Error(errorData.message || "요청 처리 중 오류가 발생했습니다.");
} catch {
throw new Error("알 수 없는 오류가 발생했습니다.");
}
};

// POST: 회원가입
const postSignUp = async (signUpData) => {
try {
const res = await fetch(`${BASE_URL}/auth/signUp`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(signUpData),
});

if (!res.ok) {
return handleError(res);
}

return res.json();
} catch (error) {
console.error("회원가입 요청 실패:", error);
throw new Error("회원가입 요청 중 네트워크 오류가 발생했습니다.");
}
};

// POST: 로그인
const postSignIn = async (signInData) => {
try {
const res = await fetch(`${BASE_URL}/auth/signIn`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(signInData),
});

if (!res.ok) {
return handleError(res);
}

return res.json();
} catch (error) {
console.error("로그인 요청 실패:", error);
throw new Error("로그인 요청 중 네트워크 오류가 발생했습니다.");
}
};

// POST: 토큰 갱신
const postRefreshToken = async (refreshToken) => {
try {
const res = await fetch(`${BASE_URL}/auth/refresh-token`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ refreshToken }),
});

if (!res.ok) {
return handleError(res);
}

return res.json();
} catch (error) {
console.error("토큰 갱신 요청 실패:", error);
throw new Error("토큰 갱신 요청 중 네트워크 오류가 발생했습니다.");
}
};

export const authService = {
postSignUp,
postSignIn,
postRefreshToken,
};
15 changes: 0 additions & 15 deletions src/api/commentService.js

This file was deleted.

85 changes: 85 additions & 0 deletions src/api/commentServices.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
const BASE_URL =
process.env.REACT_APP_BASE_URL || "https://panda-market-api.vercel.app";

// POST: 댓글 작성
const postComment = async (productId, content) => {
const accessToken = localStorage.getItem("accessToken");

const res = await fetch(`${BASE_URL}/products/${productId}/comments`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${accessToken}`,
},
body: JSON.stringify({ content }),
});

if (!res.ok) {
const error = await res.json();
throw new Error(error.message || "댓글 등록에 실패하였습니다.");
}

return await res.json();
};

// GET: 댓글 목록 조회
const getComments = async (productId, limit = 5, cursor = null) => {
let url = `${BASE_URL}/products/${productId}/comments?limit=${limit}`;
if (cursor) url += `&cursor=${cursor}`;

const res = await fetch(url);

if (!res.ok) {
const error = await res.json();
throw new Error(error.message || "댓글 목록 조회에 실패하였습니다.");
}

return await res.json();
};

// PATCH: 댓글 수정
const patchComment = async (commentId, content) => {
const accessToken = localStorage.getItem("accessToken");

const res = await fetch(`${BASE_URL}/comments/${commentId}`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${accessToken}`,
},
body: JSON.stringify({ content }),
});

if (!res.ok) {
const error = await res.json();
throw new Error(error.message || "댓글 수정에 실패하였습니다.");
}

return await res.json();
};

// DELETE: 댓글 삭제
const deleteComment = async (commentId) => {
const accessToken = localStorage.getItem("accessToken");

const res = await fetch(`${BASE_URL}/comments/${commentId}`, {
method: "DELETE",
headers: {
Authorization: `Bearer ${accessToken}`,
},
});

if (!res.ok) {
const error = await res.json();
throw new Error(error.message || "댓글 삭제에 실패하였습니다.");
}

return await res.json();
};

export const commentServices = {
postComment,
getComments,
patchComment,
deleteComment,
};
4 changes: 4 additions & 0 deletions src/asset/icon/back.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/asset/icon/kebab.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/asset/icon/large_heart.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/asset/image/inquiry_empty.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading