-
Notifications
You must be signed in to change notification settings - Fork 39
[이지현] Sprint7 #204
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
The head ref may contain hidden characters: "React-\uC774\uC9C0\uD604-sprint7"
[이지현] Sprint7 #204
Changes from all commits
0a865cd
bd28813
80c5f21
eb5ce0a
4f95c76
cb55fe9
0727ae9
0f948a6
84510d7
038d8b8
21ef977
259882f
0e6ce50
97e95dc
8924fb9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❗️ 수정요청 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import baseAPI from "./axios"; | ||
|
|
||
| export const commentAPI = { | ||
| postComment: async (productId, content) => { | ||
|
Comment on lines
+3
to
+4
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💊 제안 |
||
| try { | ||
| const response = await baseAPI.post(`/products/${productId}/comments`, { | ||
| content, | ||
| }); | ||
| return response.data; | ||
| } catch (error) { | ||
| console.error("댓글 작성 실패", error); | ||
| throw new Error("댓글 작성 실패"); | ||
| } | ||
| }, | ||
| patchComment: async (commentId, content) => { | ||
| try { | ||
| const response = await baseAPI.patch(`/comments/${commentId}`, { | ||
| content, | ||
| }); | ||
| return response.data; | ||
| } catch (error) { | ||
| console.error("댓글 수정 실패", error); | ||
| throw new Error("댓글 수정 실패"); | ||
| } | ||
| }, | ||
| deleteComment: async (commentId) => { | ||
| try { | ||
| const response = await baseAPI.delete(`/comments/${commentId}`); | ||
| return response.data; | ||
| } catch (error) { | ||
| console.error("댓글 삭제 실패", error); | ||
| throw new Error("댓글 삭제 실패"); | ||
| } | ||
| }, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import baseAPI from "./axios"; | ||
|
|
||
| export const productCommentAPI = { | ||
| getProductComment: async (productId, limit = 5, cursor = null) => { | ||
| try { | ||
| const response = await baseAPI.get(`/products/${productId}/comments`, { | ||
| params: { limit, cursor }, | ||
| }); | ||
| return response.data; | ||
| } catch (error) { | ||
| console.error("상품 댓글 불러오기 실패", error); | ||
| throw new Error("상품 댓글을 불러오는 데 실패했습니다."); | ||
| } | ||
| }, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import baseAPI from "./axios"; | ||
|
|
||
| export const productIdAPI = { | ||
| getProductId: async (productId) => { | ||
| try { | ||
| const response = await baseAPI.get(`/products/${productId}`); | ||
| return response.data; | ||
| } catch (error) { | ||
| console.error("상품 불러오기 실패", error); | ||
| throw new Error("상품을 불러오는 데 실패했습니다."); | ||
| } | ||
| }, | ||
| // 추후 로그인 회원가입 기능으로 토큰 얻고 기능추가 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 칭찬 |
||
| // postProductIdFavorite: async (productId) => { | ||
| // try { | ||
| // const response = await baseAPI.post(`/products/${productId}/favorite`); | ||
| // return response.data; | ||
| // } catch (error) { | ||
| // console.error("상품 좋아요 실패", error); | ||
| // throw new Error("상품 좋아요를 실패했습니다."); | ||
| // } | ||
| // }, | ||
| // deleteProductIdFavorite: async (productId) => { | ||
| // try { | ||
| // const response = await baseAPI.delete(`/products/${productId}/favorite`); | ||
| // return response.data; | ||
| // } catch (error) { | ||
| // console.error("상품 좋아요 취소 실패", error); | ||
| // throw new Error("상품 좋아요 취소를 실패했습니다."); | ||
| // } | ||
| // }, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,20 @@ | ||
| import baseAPI from "./axios"; | ||
|
|
||
| export const productsAPI = { | ||
| getProducts: async (page = 1, pageSize = 10, orderBy = "recent") => { | ||
| getProducts: async ( | ||
| page = 1, | ||
| pageSize = 10, | ||
| orderBy = "recent", | ||
| keyword = "" | ||
| ) => { | ||
| try { | ||
| const response = await baseAPI.get(`/products`, { | ||
| params: { page, pageSize, orderBy }, | ||
| params: { page, pageSize, orderBy, keyword }, | ||
| }); | ||
| return response.data; | ||
| } catch (error) { | ||
| console.error("상품 불러오기 실패", error); | ||
| throw new Error("상품을 불러오는 데 실패했습니다."); | ||
| console.error("전체 상품 불러오기 실패", error); | ||
| throw new Error("전체 상품들을 불러오는 데 실패했습니다."); | ||
| } | ||
| }, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,52 @@ | ||
| import { useState, useEffect } from "react"; | ||
| import { productsAPI } from "@/api/productsAPI"; | ||
|
|
||
| const useProducts = (page = 1, pageSize = 10, orderBy = "recent") => { | ||
| /** | ||
| * 상품 목록을 가져오는 커스텀 훅 | ||
| * @param {number} page - 현재 페이지 번호 (기본값: 1) | ||
| * @param {number} pageSize - 한 페이지당 아이템 수 (기본값: 10) | ||
| * @param {string} orderBy - 정렬 기준 (기본값: "recent") | ||
| * @param {string} keyword - 검색어 (기본값: "") | ||
| */ | ||
|
|
||
| const useProducts = ( | ||
| page = 1, | ||
| pageSize = 10, | ||
| orderBy = "recent", | ||
| keyword = "" | ||
| ) => { | ||
| const [items, setItems] = useState([]); | ||
| const [loading, setLoading] = useState(true); | ||
| const [error, setError] = useState(null); | ||
| const [totalCount, setTotalCount] = useState(0); // 전체 아이템 수 | ||
|
|
||
| useEffect(() => { | ||
| const fetchItems = async () => { | ||
| try { | ||
| const response = await productsAPI.getProducts(page, pageSize, orderBy); | ||
| setLoading(true); | ||
| const response = await productsAPI.getProducts( | ||
| page, | ||
| pageSize, | ||
| orderBy, | ||
| keyword | ||
| ); | ||
| const itemsData = response.list || []; | ||
| const total = response.totalCount || 0; // 서버에서 totalCount도 내려줘야 함 | ||
| setItems(itemsData); | ||
| setLoading(false); | ||
| setTotalCount(total); | ||
| setError(null); | ||
| } catch (err) { | ||
| console.error("상품 데이터 로딩 실패:", err); | ||
| setError(err.message); | ||
| } finally { | ||
| setLoading(false); | ||
| } | ||
| }; | ||
|
|
||
| fetchItems(); | ||
| }, [page, pageSize, orderBy]); | ||
| }, [page, pageSize, orderBy, keyword]); | ||
|
|
||
| return { items, loading, error }; | ||
| return { items, totalCount, loading, error }; | ||
| }; | ||
|
|
||
| export default useProducts; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❗️ 수정요청
같은 이미지가 왜 다른 확장자로 두개 존재해야하는지 모르겠어요~