Skip to content

Commit 58264c2

Browse files
fix: api response와 불일치 interface 수정
1 parent e5676b5 commit 58264c2

File tree

4 files changed

+29
-10
lines changed

4 files changed

+29
-10
lines changed

apps/client/src/pages/jobPins/JobPins.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ const JobPins = () => {
4747
>
4848
{articlesToDisplay.map((article) => (
4949
<Card
50-
key={article.id}
50+
key={article.articleId}
5151
type="bookmark"
5252
variant="save"
5353
title={article.title}
5454
imageUrl={article.thumbnailUrl}
5555
content={article.memo}
56-
category={article.categoryName}
57-
categoryColor={article.categoryColor}
56+
category={article.category.categoryName}
57+
categoryColor={article.category.categoryColor}
5858
nickname={article.ownerName}
5959
onClick={() => window.open(article.url, '_blank')}
6060
/>
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
import apiRequest from '@shared/apis/setting/axiosInstance';
2+
import { JobPinsResponse } from '@pages/jobPins/types/api';
23

3-
export const getJobPinsArticles = async (page: number, size: number) => {
4+
interface ApiResponse<T> {
5+
code: string;
6+
message: string;
7+
data: T;
8+
}
9+
10+
export const getJobPinsArticles = async (
11+
page: number,
12+
size: number
13+
): Promise<JobPinsResponse> => {
414
const { data } = await apiRequest.get('/api/v3/articles/shared/job', {
515
params: {
616
page,
717
size,
818
},
919
});
1020

11-
return data.data;
21+
return (data as ApiResponse<JobPinsResponse>).data;
1222
};

apps/client/src/pages/jobPins/apis/queries.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { useInfiniteQuery } from '@tanstack/react-query';
2+
import { JobPinsResponse } from '@pages/jobPins/types/api';
23
import { getJobPinsArticles } from './axios';
34

45
export const useGetJobPinsArticles = () => {
5-
return useInfiniteQuery({
6+
return useInfiniteQuery<JobPinsResponse>({
67
queryKey: ['jobPinsArticles'],
7-
queryFn: ({ pageParam = 0 }) => getJobPinsArticles(pageParam, 20),
8+
queryFn: ({ pageParam = 0 }) => getJobPinsArticles(pageParam as number, 20),
89
initialPageParam: 0,
910
getNextPageParam: (lastPage, allPages) => {
1011
if (lastPage.articles.length === 0) {

apps/client/src/pages/jobPins/types/api.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
export interface JobPinArticle {
1+
interface JobPinCategory {
2+
categoryId: number;
3+
categoryName: string;
4+
categoryColor: string;
5+
}
6+
7+
interface JobPinArticle {
8+
articleId: number;
29
url: string;
310
title: string;
411
thumbnailUrl: string;
5-
categoryName: string;
6-
categoryColor: string;
12+
memo: string;
13+
ownerName: string;
14+
category: JobPinCategory;
715
}
816

917
export interface JobPinsResponse {

0 commit comments

Comments
 (0)