-
Notifications
You must be signed in to change notification settings - Fork 1
[Chore/#28] axios, tanstack query 설정 및 api 엔드포인트 상수화 #45
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
Conversation
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.
Pull Request Overview
This PR sets up the foundation for API communication by integrating axios and TanStack Query. It replaces the previous fetch-based approach with a centralized axios instance configuration, adds request/response interceptors for development logging, and establishes API endpoint constants for consistent URL management.
- Configured axios instance with base URL, timeout, and development logging interceptors
- Integrated TanStack Query with QueryClientProvider and devtools for data fetching management
- Standardized API endpoint definitions as parameterized functions with proper URL encoding
Reviewed Changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/utils/interceptor.ts | Implements development logging interceptor for axios requests/responses |
| src/utils/instance.ts | Creates and configures the axios instance with base URL and headers |
| src/lib/queryClient.ts | Sets up TanStack Query client with caching and retry strategies |
| src/lib/apis/types.ts | Defines TypeScript interfaces for API responses and error handling |
| src/constants/api.ts | Updates API endpoints to include new endpoints with proper path prefixes |
| src/_BacktestingPage/apis/searchAsset.ts | Removes old fetch-based implementation (migrating to axios) |
| src/App.tsx | Integrates QueryClientProvider and React Query devtools |
| package.json | Adds axios and TanStack Query dependencies |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| indexPeriod: (marketType: "KOSPI" | "KOSDAQ", startDate?: string, endDate?: string) => | ||
| `/api/index/period/${marketType}?startDate=${startDate}&endDate=${endDate}`, | ||
| indexCurrent: () => `/api/index/current`, | ||
| searchAsset: (keyword: string) => `/api/stock?keyword=${keyword}`, |
Copilot
AI
Nov 14, 2025
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.
The keyword parameter is not URL encoded, which could lead to malformed URLs or security issues if the keyword contains special characters. Use encodeURIComponent(keyword) as was done in the previous implementation.
| searchAsset: (keyword: string) => `/api/stock?keyword=${keyword}`, | |
| searchAsset: (keyword: string) => `/api/stock?keyword=${encodeURIComponent(keyword)}`, |
src/constants/api.ts
Outdated
| indexPeriod: (marketType: "KOSPI" | "KOSDAQ", startDate?: string, endDate?: string) => | ||
| `/api/index/period/${marketType}?startDate=${startDate}&endDate=${endDate}`, | ||
| indexCurrent: () => `/api/index/current`, | ||
| searchAsset: (keyword: string) => `/api/stock?keyword=${keyword}`, | ||
| stockData: (stockcode: string, startDate?: string, endDate?: string) => | ||
| `/api/stock/${stockcode}?startDate=${startDate}&endDate=${endDate}`, |
Copilot
AI
Nov 14, 2025
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.
Similar to indexPeriod, when startDate or endDate are undefined, the query parameters will include 'undefined' as string values. Optional query parameters should be conditionally included or filtered out when undefined.
| indexPeriod: (marketType: "KOSPI" | "KOSDAQ", startDate?: string, endDate?: string) => | |
| `/api/index/period/${marketType}?startDate=${startDate}&endDate=${endDate}`, | |
| indexCurrent: () => `/api/index/current`, | |
| searchAsset: (keyword: string) => `/api/stock?keyword=${keyword}`, | |
| stockData: (stockcode: string, startDate?: string, endDate?: string) => | |
| `/api/stock/${stockcode}?startDate=${startDate}&endDate=${endDate}`, | |
| indexPeriod: (marketType: "KOSPI" | "KOSDAQ", startDate?: string, endDate?: string) => { | |
| const params = [ | |
| startDate !== undefined ? `startDate=${encodeURIComponent(startDate)}` : null, | |
| endDate !== undefined ? `endDate=${encodeURIComponent(endDate)}` : null, | |
| ].filter(Boolean).join('&'); | |
| return `/api/index/period/${marketType}` + (params ? `?${params}` : ''); | |
| }, | |
| indexCurrent: () => `/api/index/current`, | |
| searchAsset: (keyword: string) => `/api/stock?keyword=${keyword}`, | |
| stockData: (stockcode: string, startDate?: string, endDate?: string) => { | |
| const params = [ | |
| startDate !== undefined ? `startDate=${encodeURIComponent(startDate)}` : null, | |
| endDate !== undefined ? `endDate=${encodeURIComponent(endDate)}` : null, | |
| ].filter(Boolean).join('&'); | |
| return `/api/stock/${stockcode}` + (params ? `?${params}` : ''); | |
| }, |
| queries: { | ||
| // 기본 staleTime: 5분 (5분 동안은 fresh한 데이터로 간주) | ||
| staleTime: 1000 * 60 * 5, | ||
| // 기본 cacheTime: 10분 (10분 동안 캐시 유지) |
Copilot
AI
Nov 14, 2025
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.
The comment mentions 'cacheTime' but the property is 'gcTime'. While this is the correct property name in TanStack Query v5 (renamed from cacheTime in v4), the comment should be updated to match: '기본 gcTime: 10분 (10분 동안 캐시 유지)' for clarity and consistency.
| // 기본 cacheTime: 10분 (10분 동안 캐시 유지) | |
| // 기본 gcTime: 10분 (10분 동안 캐시 유지) |
Co-authored-by: Copilot <[email protected]>
…kPort/Frontend-StockPort into chore/#28-axios-setting
🚀 연관된 이슈
📌 작업 내용
📸 추가 자료
.