Skip to content

Commit ff4d323

Browse files
authored
Merge pull request #80 from SOPT-all/api/author-info/#76
[api/#76] 작가 정보 조회 api 연동
2 parents a180e4c + e92bbcb commit ff4d323

File tree

4 files changed

+67
-6
lines changed

4 files changed

+67
-6
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,24 @@
11
// 작가 정보 조회 API
2+
import { useSuspenseQuery } from "@tanstack/react-query";
3+
import { HTTPMethod, request } from "@/apis/request";
4+
import { API_ENDPOINTS } from "@/apis/constants/api-endpoints";
5+
import { authorQueryKeys } from "@/apis/constants/query-key";
6+
import type { AuthorInfoResponse } from "@/apis/types/author";
7+
8+
const fetchAuthorInfo = (authorId: number, userId: number) =>
9+
request<AuthorInfoResponse>({
10+
method: HTTPMethod.GET,
11+
url: API_ENDPOINTS.AUTHORS.AUTHOR_INFO(authorId), // /authors/{authorId}
12+
query: { userId },
13+
});
14+
15+
export const useAuthorInfoQuery = (authorId: number, userId: number) =>
16+
useSuspenseQuery({
17+
queryKey: [...authorQueryKeys.detail(authorId), userId],
18+
queryFn: () => fetchAuthorInfo(authorId, userId),
19+
retry: false,
20+
refetchOnMount: false,
21+
refetchOnReconnect: false,
22+
refetchOnWindowFocus: false,
23+
staleTime: 5 * 60 * 1000,
24+
});

src/apis/types/author.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
11
// 요청, 응답 타입을 정의합니다
2+
export interface AuthorInfoResponse {
3+
id: number;
4+
name: string;
5+
description: string;
6+
imageUrl: string;
7+
likeCount: number;
8+
isLiked: boolean;
9+
}
Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import { Suspense } from "react";
12
import { MakerInfo } from "@/shared/components/maker-info/maker-info";
23
import { Carousel } from "./components/carousel/carousel";
34
import { ProductMainInfo } from "./components/product-main-info/product-main-info";
45
import { ProductSummary } from "./components/product-summary/product-summary";
6+
import { useAuthorInfoQuery } from "@/apis/queries/use-author-info.query";
57

68
export const ProductInfo = () => {
79
const data = {
@@ -14,19 +16,43 @@ export const ProductInfo = () => {
1416
reviewCount: 634,
1517
salesCount: 4319,
1618
};
19+
20+
const authorId = 1;
21+
const userId = 1;
22+
23+
const AuthorInfoContent = () => {
24+
const { data: author } = useAuthorInfoQuery(authorId, userId);
25+
26+
return (
27+
<MakerInfo
28+
name={author?.name ?? data.authorName}
29+
description={author?.description ?? "작가 정보를 불러오는 중입니다."}
30+
profileImage={author?.imageUrl}
31+
liked={author?.isLiked}
32+
likeCount={author?.likeCount}
33+
/>
34+
);
35+
};
36+
1737
return (
1838
<>
1939
{/** 캐러셀 */}
2040
<Carousel />
2141
{/** 작품 메인 정보 */}
22-
<ProductMainInfo data={data} />
42+
<ProductMainInfo data={{ ...data }} />
2343
{/** 작품 요약 정보 */}
2444
<ProductSummary />
2545
{/** 작가 정보 */}
26-
<MakerInfo
27-
name="SPEDEAR"
28-
description="소중한 시간을 담을 수 있는 아이템입니다."
29-
/>
46+
<Suspense
47+
fallback={
48+
<MakerInfo
49+
name={data.authorName}
50+
description="작가 정보를 불러오는 중입니다."
51+
profileImage={undefined}
52+
/>
53+
}>
54+
<AuthorInfoContent />
55+
</Suspense>
3056
</>
3157
);
3258
};

src/shared/components/maker-info/maker-info.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@ interface MakerInfoProps {
77
name: string;
88
description: string;
99
profileImage?: string;
10+
liked?: boolean;
11+
likeCount?: number;
1012
}
1113

1214
export function MakerInfo({
1315
name,
1416
description,
1517
profileImage = MakerProfileImage,
18+
liked = false,
19+
likeCount = 0,
1620
}: MakerInfoProps) {
1721
// TODO: api 연동해서 LikeButton에 전달 => 낙관적 업데이트
1822

@@ -33,7 +37,7 @@ export function MakerInfo({
3337
<p className={styles.description}>{description}</p>
3438
</div>
3539
</div>
36-
<LikeButton variant="maker" liked={true} count={9999} />
40+
<LikeButton variant="maker" liked={liked} count={likeCount} />
3741
</div>
3842
);
3943
}

0 commit comments

Comments
 (0)