-
Notifications
You must be signed in to change notification settings - Fork 1
Api(client): Dashboard article 전체 조회 API 연결 #82
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 4 commits
e85bb00
ab903be
ff723d9
d255a18
1db4d82
a7ef5cd
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,15 @@ | ||||||||||||||||||||||||||||
| import apiRequest from '@shared/apis/setting/axiosInstance'; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| export const getBookmarkReadArticles = async (page: number, size: number) => { | ||||||||||||||||||||||||||||
| const { data } = await apiRequest.get( | ||||||||||||||||||||||||||||
| `/api/v1/articles?page=${page}&size=${size}` | ||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||
| return data.data; | ||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| export const getBookmarkUnreadArticles = async (page: number, size: number) => { | ||||||||||||||||||||||||||||
| const { data } = await apiRequest.get( | ||||||||||||||||||||||||||||
| `/api/v1/articles/unread?page=${page}&size=${size}` | ||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||
| return data.data; | ||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||
|
Comment on lines
+10
to
+15
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 axios params 사용 및 반환 타입 명시 동일하게 params 사용과 제네릭으로 안전성을 높여주세요. -export const getBookmarkUnreadArticles = async (page: number, size: number) => {
- const { data } = await apiRequest.get(
- `/api/v1/articles/unread?page=${page}&size=${size}`
- );
- return data.data;
-};
+export const getBookmarkUnreadArticles = async (page: number, size: number): Promise<UnreadBookmarkArticleResponse> => {
+ const { data } = await apiRequest.get<ApiResponse<UnreadBookmarkArticleResponse>>(
+ '/api/v1/articles/unread',
+ { params: { page, size } }
+ );
+ return data.data;
+};📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { useQuery, UseQueryResult } from '@tanstack/react-query'; | ||
| import { AxiosError } from 'axios'; | ||
| import { getBookmarkReadArticles, getBookmarkUnreadArticles } from './axios'; | ||
| import { | ||
| BookmarkArticleResponse, | ||
| UnreadBookmarkArticleResponse, | ||
| } from '@pages/myBookmark/types/api'; | ||
|
|
||
| export const useGetBookmarkReadArticles = ( | ||
| page: number, | ||
| size: number | ||
| ): UseQueryResult<BookmarkArticleResponse, AxiosError> => { | ||
| return useQuery({ | ||
| queryKey: ['bookmarkReadArticles', page, size], | ||
| queryFn: () => getBookmarkReadArticles(page, size), | ||
| }); | ||
| }; | ||
|
|
||
| export const useGetBookmarkUnreadArticles = ( | ||
| page: number, | ||
| size: number | ||
| ): UseQueryResult<UnreadBookmarkArticleResponse, AxiosError> => { | ||
| return useQuery({ | ||
| queryKey: ['bookmarkUnreadArticles', page, size], | ||
| queryFn: () => getBookmarkUnreadArticles(page, size), | ||
| }); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| interface BookmarkArticle { | ||
| articleId: number; | ||
| url: string; | ||
| memo: string; | ||
| createdAt: string; | ||
| isRead: boolean; | ||
| } | ||
|
|
||
| // 북마크 전체 조회 | ||
| export interface BookmarkArticleResponse { | ||
| totalArticle: number; | ||
| totalUnreadArticle: number; | ||
| articles: BookmarkArticle[]; | ||
| } | ||
|
|
||
| // 북마크 안 읽음 조회 | ||
| export interface UnreadBookmarkArticleResponse { | ||
| totalUnreadArticle: number; | ||
| articles: BookmarkArticle[]; | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,13 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import apiRequest from '@shared/apis/setting/axiosInstance'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const getRemindArticles = async ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| nowDate: string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| readStatus: boolean, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| page: number, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| size: number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { data } = await apiRequest.get( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| `/api/v1/articles/remind?now=${nowDate}&readStatus=${readStatus}&page=${page}&size=${size}` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return data.data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+3
to
+13
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 쿼리 문자열 직접 합성 지양하고 axios params 사용 + 반환 타입 명시 직접 문자열 합성은 인코딩 이슈(nowDate에 +import { ArticleListResponse } from '@pages/remind/types/api';
+
+type ApiResponse<T> = { data: T };
+
export const getRemindArticles = async (
nowDate: string,
readStatus: boolean,
page: number,
size: number
-) => {
- const { data } = await apiRequest.get(
- `/api/v1/articles/remind?now=${nowDate}&readStatus=${readStatus}&page=${page}&size=${size}`
- );
+) : Promise<ArticleListResponse> => {
+ const { data } = await apiRequest.get<ApiResponse<ArticleListResponse>>(
+ '/api/v1/articles/remind',
+ { params: { now: nowDate, readStatus, page, size } }
+ );
return data.data;
};📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { useQuery, UseQueryResult } from '@tanstack/react-query'; | ||
| import { AxiosError } from 'axios'; | ||
| import { getRemindArticles } from './axios'; | ||
| import { ArticleListResponse } from '@pages/remind/types/api'; | ||
|
|
||
| export const useGetRemindArticles = ( | ||
| nowDate: string, | ||
| readStatus: boolean, | ||
| page: number, | ||
| size: number | ||
| ): UseQueryResult<ArticleListResponse, AxiosError> => { | ||
| return useQuery({ | ||
| queryKey: ['remindArticles', nowDate, readStatus, page, size], | ||
| queryFn: () => getRemindArticles(nowDate, readStatus, page, size), | ||
| }); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // 리마인드 전체 조회 | ||
| interface Category { | ||
| categoryId: number; | ||
| categoryName: string; | ||
| categoryColor: string; | ||
| } | ||
|
Comment on lines
+2
to
+6
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 공유 Category 타입과의 혼동 방지(이름 충돌 회피)
-interface Category {
+interface RemindCategory {
categoryId: number;
categoryName: string;
categoryColor: string;
}그리고 Line 15의 참조를 함께 갱신하세요: - category: Category;
+ category: RemindCategory;🤖 Prompt for AI Agents |
||
|
|
||
| interface ArticleWithCategory { | ||
| articleId: number; | ||
| url: string; | ||
| memo: string; | ||
| createdAt: string; | ||
| isRead: boolean; | ||
| remindAt: string; | ||
| category: Category; | ||
| } | ||
|
|
||
| export interface ArticleListResponse { | ||
| readArticleCount: number; | ||
| unreadArticleCount: number; | ||
| articles: ArticleWithCategory[]; | ||
| } | ||
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
이름과 실제 동작 불일치(“Read”가 아닌 “All”)
/api/v1/articles는 전부 조회(ALL)로 보입니다. 함수명을getBookmarkAllArticles로 바꾸거나 최소한 주석으로 명확히 해주세요. 혼동은 호출부/키 캐싱에도 영향을 줍니다.호환성 필요 시, 아래 별칭도 함께 유지 가능합니다:
+export const getBookmarkReadArticles = getBookmarkAllArticles;📝 Committable suggestion
🤖 Prompt for AI Agents