-
Notifications
You must be signed in to change notification settings - Fork 37
[윤혜림] Sprint7 #258
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-\uC724\uD61C\uB9BC-sprint7"
[윤혜림] Sprint7 #258
Changes from all commits
d15ab4e
fd53c0b
d6cadc1
eacf748
eaf7637
3def5b2
b442aff
355d4d2
1319769
a993b6d
975819f
eeb62ec
67f70c0
a9c496f
df03083
645380e
2915b45
490ab08
085d86d
6713da0
4204b23
a93e213
96b9194
e02e998
cf7c64c
e0e49be
12f60a1
05b878e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # timeago warning 해결 | ||
| GENERATE_SOURCEMAP=false |
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. api 디렉토리의 경우, 콤포넌트를 위한 디렉토리가 아닌것으로 생각되어요. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,9 @@ | ||
| async function getProductData({ orderBy, pageSize, search, page }) { | ||
| const query = `page=${page}&orderBy=${orderBy}&pageSize=${pageSize}&keyword=${search}`; | ||
| const response = await fetch( | ||
| `https://panda-market-api.vercel.app/products?${query}` | ||
| ); | ||
| const BASE_URL = "https://panda-market-api.vercel.app"; | ||
|
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. 상수로 관리하는거 너무 좋습니당 |
||
|
|
||
| // 베스트/전체 상품 리스트 | ||
| async function getProductData(params = {}) { | ||
|
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. default 값 주신거 너무 좋습니다 👍🏻 |
||
| const query = new URLSearchParams(params).toString(); | ||
| const response = await fetch(`${BASE_URL}/products?${query}`); | ||
|
|
||
| if (!response.ok) { | ||
| throw new Error("상품을 불러오는 데 실패했습니다."); | ||
|
|
@@ -11,4 +12,57 @@ async function getProductData({ orderBy, pageSize, search, page }) { | |
| return body; | ||
| } | ||
|
|
||
| // 디테일 상품 정보 | ||
| export async function getProductId(productId, setProductData) { | ||
|
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. 오, 우리 api 함수들의 역할을 다시 한번만 생각해볼까요? 우선 API에 둔 함수의 역할은 다음과 같이 생각되는데요
이 상황에서 api함수들은 딱 위 작업만 진행을 하고, 화면에 보여질 데이터를 업데이트 해주는 setState액션은 콤포넌트와 가장 가까운 곳에서 작업을 진행해주어야 할 것 같아요! |
||
| const response = await fetch(`${BASE_URL}/products/${productId}`); | ||
|
|
||
| try { | ||
| const body = await response.json(); | ||
| setProductData(body); | ||
| } catch (error) { | ||
| console.log(error); | ||
| } | ||
|
|
||
| if (!response.ok) { | ||
| throw new Error("정보를 불러오는 데 실패했습니다."); | ||
| } | ||
| } | ||
|
|
||
| // 디테일 댓글 | ||
| export async function getComments(productId, setCommentsData) { | ||
| const response = await fetch( | ||
| `${BASE_URL}/products/${productId}/comments?limit=10` | ||
| ); | ||
|
Comment on lines
+32
to
+35
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. 여기서도 limit 정보는 getComments의 인자로 전달받아보면 어떨까요? |
||
| try { | ||
| const body = await response.json(); | ||
| setCommentsData(body); | ||
| } catch (error) { | ||
| console.log(error); | ||
| } | ||
|
|
||
| if (!response.ok) { | ||
| throw new Error("정보를 불러오는 데 실패했습니다."); | ||
| } | ||
| } | ||
|
|
||
| // 디테일 댓글 등록 | ||
| // 로그인 기능 구현 전이므로 코멘트 API POST 구현 보류 (24.12.08) | ||
| // export async function createComment(productId, comment) { | ||
| // const surveyData = { | ||
| // content: comment, | ||
| // }; | ||
| // const response = await fetch(`${BASE_URL}/products/${productId}/comments`, { | ||
| // method: "POST", | ||
| // // 자바스크립트 객체를 JSON 문자열로 변환하여 post 보내기 | ||
| // headers: { | ||
| // "Content-Type": "application/json", | ||
| // accept: "application/json", | ||
| // Authorization: | ||
| // "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NTE3LCJzY29wZSI6ImFjY2VzcyIsImlhdCI6MTczMzU2MzU1NCwiZXhwIjoxNzMzNTY1MzU0LCJpc3MiOiJzcC1wYW5kYS1tYXJrZXQifQ.Wpof71osRiwDAxNq34xcc4JGYqkEb_KaXYUKVc3Pz3M", | ||
| // }, | ||
| // body: JSON.stringify(surveyData), | ||
| // }); | ||
| // const data = await response.json(); | ||
| // } | ||
|
|
||
| export default getProductData; | ||
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.
오 기능 구현에 필요한 라이브러리 탐색하는거 좋습니다