-
Notifications
You must be signed in to change notification settings - Fork 1
Api(client): Dashboard category 전체 조회 & 생성 API 연결 #73
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
Changes from all commits
68dd40f
8a0704f
7a363c0
da51bb9
feb4d43
b07f95a
25586f3
1bd971e
240e16a
382d585
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,13 @@ | ||
| import apiRequest from '@shared/apis/axiosInstance'; | ||
|
|
||
| export const getDashboardCategories = async () => { | ||
| const { data } = await apiRequest.get('/api/v1/categories/dashboard'); | ||
| return data.data; | ||
| }; | ||
|
|
||
| export const postCategory = async (categoryName: string) => { | ||
| const response = await apiRequest.post('/api/v1/categories', { | ||
| categoryName, | ||
| }); | ||
| return response; | ||
| }; |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,23 @@ | ||||||||||||||||||||||||||||||||||
| import { useMutation, useQuery, UseQueryResult } from '@tanstack/react-query'; | ||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||
| getDashboardCategories, | ||||||||||||||||||||||||||||||||||
| postCategory, | ||||||||||||||||||||||||||||||||||
| } from '@shared/components/sidebar/apis/axios'; | ||||||||||||||||||||||||||||||||||
| import { AxiosError } from 'axios'; | ||||||||||||||||||||||||||||||||||
| import { DashboardCategoriesResponse } from '@shared/components/sidebar/types/api'; | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+1
to
+7
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. 🛠️ Refactor suggestion 쿼리 무효화를 위한 useQueryClient 추가 + 쿼리 키 상수화 생성 후 목록 갱신을 위해 queryClient가 필요합니다. 키를 상수로 노출해 오탈자/중복을 줄이는 것도 권장합니다. - import { useMutation, useQuery, UseQueryResult } from '@tanstack/react-query';
+ import { useMutation, useQuery, UseQueryResult, useQueryClient } from '@tanstack/react-query';
@@
import { DashboardCategoriesResponse } from '@shared/components/sidebar/types/api';
+
+export const DASHBOARD_CATEGORIES_QUERY_KEY = ['dashboardCategories'] as const;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| export const useGetDashboardCategories = (): UseQueryResult< | ||||||||||||||||||||||||||||||||||
| DashboardCategoriesResponse, | ||||||||||||||||||||||||||||||||||
| AxiosError | ||||||||||||||||||||||||||||||||||
| > => { | ||||||||||||||||||||||||||||||||||
| return useQuery({ | ||||||||||||||||||||||||||||||||||
| queryKey: ['dashboardCategories'], | ||||||||||||||||||||||||||||||||||
| queryFn: () => getDashboardCategories(), | ||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| export const usePostCategory = () => { | ||||||||||||||||||||||||||||||||||
| return useMutation({ | ||||||||||||||||||||||||||||||||||
| mutationFn: (categoryName: string) => postCategory(categoryName), | ||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| export interface Category { | ||
| id: number; | ||
| name: string; | ||
| unreadCount: number; | ||
| } | ||
|
|
||
| export interface DashboardCategoriesResponse { | ||
| categories: Category[]; | ||
| } |
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.
🛠️ Refactor suggestion
생성 유효성 검증(빈값/중복) + 키 상수화 반영
빈 문자열/공백만 입력, 중복 이름 방지를 최소한으로 막아 주세요. 동시에 앞서 제안한 쿼리 키 상수 사용으로 일관성을 높일 수 있습니다.
📝 Committable suggestion
🤖 Prompt for AI Agents