-
Notifications
You must be signed in to change notification settings - Fork 48
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
전남대 FE 이은진 3주차 과제 Step2 #43
Open
eunjin210
wants to merge
8
commits into
kakao-tech-campus-2nd-step2:eunjin210
Choose a base branch
from
eunjin210:eunjin
base: eunjin210
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8c4232f
docs : Readme.md 작성
9112661
Feat : axios 추가
2d46f94
feat: api/index.ts theme 카테고리 구현
a15a16b
add : 실시간 급상승 랭킹 api 연동
024b798
fix : 데이터가 없을 때 발생하는 오류 해결
854d865
feat : themeGoodsection api 연동
81c7ece
Feat : error 및 loading 처리
7249899
fix : Loading 코드 불필요한 부분 삭제 finally문으로 수정
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# 3주차 상품리스트 구현 - api | ||
## step1 📝구현사항 | ||
+ 첨부된 oas.yaml 파일을 토대로 Request, Response Type을 정의하기 | ||
+ axios 라이브러리 설치 | ||
* 메인페이지 - theme | ||
* /api/v1/themes API를 사용하여 Section을 구현 | ||
* API는 Axios또는 React Query 등을 모두 활용해서 구현 가능 | ||
* 메인 페이지 - 실시간 급상승 선물랭킹 | ||
* /api/v1/ranking/products API를 사용하여 Section을 구현 | ||
* 필터 조건을 선택 하면 해당 조건에 맞게 API를 요청하여 보여지게 해야함 | ||
* Theme 페이지 - header | ||
* url의 pathParams와 /api/v1/themes API를 사용하여 Section을 구현 | ||
* themeKey가 잘못 된 경우 메인 페이지로 연결 | ||
* Theme 페이지 - 상품 목록 섹션 | ||
* /api/v1/themes/{themeKey}/products API를 사용하여 상품 목록을 구현 | ||
*API 요청 시 한번에 20개의 상품 목록이 내려오게 구현 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// src/api/index.ts | ||
import axios from 'axios'; | ||
|
||
import type { GoodsData, RankingFilterOption, ThemeData } from '@/types'; | ||
|
||
const api = axios.create({ | ||
baseURL: 'https://react-gift-mock-api-eunjin.vercel.app', | ||
}); | ||
|
||
export const fetchTheme = async (): Promise<ThemeData[]> => { | ||
const response = await api.get<{ themes: ThemeData[] }>('/api/v1/themes'); | ||
return response.data.themes; | ||
}; | ||
|
||
export const fetchThemes = async (themeKey: string): Promise<ThemeData> => { | ||
console.log('Fetching theme with key:', themeKey); | ||
const response = await api.get<ThemeData>(`/api/v1/themes/${themeKey}`); | ||
console.log('Fetched theme data:', response.data); | ||
return response.data; | ||
}; | ||
|
||
export const getThemeProducts = async (themeKey: string): Promise<GoodsData[]> => { | ||
const response = await api.get<{ products: GoodsData[] }>(`/api/v1/themes/${themeKey}/products`, { | ||
params: { | ||
maxResults: 20, | ||
}, | ||
}); | ||
return response.data.products; | ||
}; | ||
|
||
export const getRankingGoods = async (filterOption: RankingFilterOption): Promise<GoodsData[]> => { | ||
const response = await api.get<{ products: GoodsData[] }>('/api/v1/ranking/products', { | ||
params: filterOption, | ||
}); | ||
return response.data.products; | ||
}; | ||
|
||
export default api; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
이미 null 인 상태라 null 로 초기화 할 필요 없을거 같습니다.
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.
시간 내주셔서 리뷰해주심에 항상 감사드립니다 !
실시간 급상승 랭킹에서 남성이 위시로 받은 페이지에서, 아이템을 가져올 때 오류가 발생하여
catch (err) {
setErrorMessage('데이터를 불러오는데 실패하였습니다.');
} 코드가 실행됩니다.
이후 다른 페이지를 누르면 불러 올 상품 데이터가 있더라도, ErrorMessage에 '데이터를 불러오는데 실패하였습니다.' 이 문자열이 들어있어 제대로 상품들이 출력 되지 않아 코드에 setErrorMessage(null); 이 문장을 넣어 해결하였습니다!
위 방식으로 문제를 해결하였는데, 혹시 이 방법이 setErrorMessage(null); 이 코드를 없애고도 위 문제를 해결 할 수 있거나, 더 좋은 방식이 있다면 답변 부탁드립니다