Skip to content

Commit 7fdff56

Browse files
authored
Merge pull request #55 from ArtNeplatform/feature/#52
Refactor/#52 - 작품 구매자/작가 마이페이지 API 연결
2 parents bdf3bd7 + 7b079b8 commit 7fdff56

9 files changed

Lines changed: 62 additions & 61 deletions

File tree

src/apis/axios.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ type TAnotherToken = {
2525
type TAuthResponse = {
2626
accessToken: string;
2727
};
28-
2928
const DUMMY_ACCESS_TOKEN =
3029
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InJ5dXNlb25naG83QGRndS5hYy5rciIsImlhdCI6MTczOTIwNDY5NiwiZXhwIjoxNzQxNzk2Njk2fQ.iWwnAhIzse5UwvHpR5uWa2o0HRM5G14ikeAtYf_BDec';
31-
// localStorage.setItem('accessToken', DUMMY_ACCESS_TOKEN);
30+
localStorage.setItem('accessToken', DUMMY_ACCESS_TOKEN);
3231
export const instance: AxiosInstance = axios.create({
3332
baseURL: import.meta.env.VITE_APP_SERVER_URL,
3433
headers: {

src/apis/mypage-author/myPage/myPage.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ import { TGetResponse } from '@/apis/type';
88
* @author 노찬영
99
**/
1010
export const getAuthorMypage = async (): Promise<TArtistMypage> => {
11+
const AUTHOR_TOKEN =
12+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InJ5dXNlb25naG83QGRndS5hYy5rciIsImlhdCI6MTczOTIwNDY5NiwiZXhwIjoxNzQxNzk2Njk2fQ.iWwnAhIzse5UwvHpR5uWa2o0HRM5G14ikeAtYf_BDec';
13+
console.log('작가 accessToken:', AUTHOR_TOKEN);
14+
15+
localStorage.setItem('accessToken', AUTHOR_TOKEN);
16+
instance.defaults.headers.common.Authorization = `Bearer ${AUTHOR_TOKEN}`;
17+
1118
const response = await instance.get<TGetResponse<TArtistMypage>>(
1219
`/api/mypage`
1320
);

src/apis/mypage-buyer/myPage/myPage.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,17 @@ import { TGetResponse } from '@/apis/type';
88
* @author 노찬영
99
**/
1010
export const getBuyerMypage = async (): Promise<TBuyerMypage> => {
11-
const DUMMY_ACCESS_TOKEN = localStorage.getItem('accessToken'); // 기존 토큰 저장
1211
const BUYER_TOKEN =
1312
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6Imh5c29uZzR1QGdtYWlsLmNvbSIsImlhdCI6MTczOTU1MzczMSwiZXhwIjoxNzQyMTQ1NzMxfQ.6ePJhRS1JUNK9BPIOk9oXrYoggois21uBtGsp4gvKrU';
13+
console.log('구매자 accessToken:', BUYER_TOKEN);
1414

15-
try {
16-
// 기존 토큰 삭제 후 구매자 토큰 저장
17-
localStorage.removeItem('accessToken');
18-
localStorage.setItem('accessToken', BUYER_TOKEN);
15+
// 구매자 토큰으로 변경
16+
localStorage.setItem('accessToken', BUYER_TOKEN);
17+
instance.defaults.headers.common.Authorization = `Bearer ${BUYER_TOKEN}`;
1918

20-
const response = await instance.get<TGetResponse<TBuyerMypage>>(
21-
`/api/mypage`
22-
);
19+
const response = await instance.get<TGetResponse<TBuyerMypage>>(
20+
`/api/mypage`
21+
);
2322

24-
return response.data.result;
25-
} finally {
26-
// 원래 있던 DUMMY_ACCESS_TOKEN으로 복원
27-
localStorage.setItem('accessToken', DUMMY_ACCESS_TOKEN ?? '');
28-
}
23+
return response.data.result;
2924
};

src/constants/queryKeys.ts

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,42 +36,33 @@ export const getArtistListQuery = () => {
3636
};
3737

3838
/**
39-
* 작품 구매자 마이페이지 조회를 위한 쿼리 키 반환 함수
40-
* @returns 쿼리 키 배열 ['userMypage']을 반환하여 캐시를 사용자별로 관리할 수 있도록 설정
39+
* 마이페이지 조회를 위한 쿼리 키 반환 함수
40+
* @returns 쿼리 키 배열 ['Mypage']을 반환하여 캐시를 사용자별로 관리할 수 있도록 설정
4141
* @author 노찬영
4242
*/
43-
export const getBuyerMypageQueryKey = () => ['buyerMypage'];
43+
export const getMypageQueryKey = (role: 'author' | 'buyer') => ['Mypage', role];
4444

4545
/**
4646
* 작품 구매자 마이페이지 조회 API를 위한 React Query 설정 함수
4747
* @returns queryKey와 queryFn을 포함한 객체를 반환하여 React Query에서 사용 가능하도록 설정
48-
* @example - const { data } = useQuery(getUserMypageQuery(123));
4948
* @author 노찬영
5049
*/
5150
export const getBuyerMypageQuery = () => {
5251
return {
53-
queryKey: getBuyerMypageQueryKey(),
54-
queryFn: () => getBuyerMypage(), // 마이페이지 데이터를 조회하는 함수
52+
queryKey: getMypageQueryKey('buyer'),
53+
queryFn: () => getBuyerMypage(), // 작품 구매자 마이페이지 데이터를 조회하는 함수
5554
};
5655
};
5756

58-
/**
59-
* 작가 마이페이지 조회를 위한 쿼리 키 반환 함수
60-
* @returns 쿼리 키 배열 ['userMypage']을 반환하여 캐시를 사용자별로 관리할 수 있도록 설정
61-
* @author 노찬영
62-
*/
63-
export const getAuthorMypageQueryKey = () => ['authorMypage'];
64-
6557
/**
6658
* 작가 마이페이지 조회 API를 위한 React Query 설정 함수
6759
* @returns queryKey와 queryFn을 포함한 객체를 반환하여 React Query에서 사용 가능하도록 설정
68-
* @example - const { data } = useQuery(getUserMypageQuery(123));
6960
* @author 노찬영
7061
*/
7162
export const getAuthorMypageQuery = () => {
7263
return {
73-
queryKey: getAuthorMypageQueryKey(),
74-
queryFn: () => getAuthorMypage(), // 마이페이지 데이터를 조회하는 함수
64+
queryKey: getMypageQueryKey('author'),
65+
queryFn: () => getAuthorMypage(), // 작가 마이페이지 데이터를 조회하는 함수
7566
};
7667
};
7768

src/pages/artBuyerPage/components/menuMyPage/MyCollection/index.tsx

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,31 @@ import {
1111

1212
import { Artwork } from '@/components/common/ArtWork';
1313

14+
import { useNavigate } from 'react-router-dom';
1415
import { useGetBuyerMypage } from '@/pages/artBuyerPage/hooks/useGetBuyerMypage';
1516

1617
/**
1718
* @description 작품 구매자의 작품과 전시를 표시하는 컴포넌트
1819
* @author 노찬영
1920
*/
2021
const MyCollection = () => {
22+
const navigate = useNavigate();
2123
const { userMypageData } = useGetBuyerMypage();
2224

2325
// 작품 구매자 작품 데이터
24-
const artworks = userMypageData.myCollection.artworks;
25-
26+
const artworks = userMypageData?.myCollection?.artworks || [];
2627
// 작품 구매자 전시 데이터
27-
const exhibitions = userMypageData.myCollection.exhibitions;
28+
const exhibitions = userMypageData?.myCollection?.exhibitions || [];
29+
30+
// 작품 클릭 시 작품 상세 페이지로 이동
31+
const handleArtworkClick = (artworkId: number) => {
32+
navigate(`/artwork/${artworkId}`);
33+
};
34+
35+
// 전시 클릭 시 전시 상세 페이지로 이동
36+
const handleExhibitionClick = (exhibitionId: number) => {
37+
navigate(`/exhibition/${exhibitionId}`);
38+
};
2839

2940
return (
3041
<MyCollectionContainer>
@@ -33,7 +44,7 @@ const MyCollection = () => {
3344
<ArtworkContainer>
3445
<SectionTitle>작품</SectionTitle>
3546
<ArtworkGrid>
36-
{artworks?.map((artwork) => (
47+
{artworks.map((artwork) => (
3748
<Artwork
3849
key={artwork.id}
3950
imageUrl={artwork.thumbnail_image_url}
@@ -42,6 +53,8 @@ const MyCollection = () => {
4253
artworkWidth={artwork.width}
4354
artworkHeight={artwork.height}
4455
artworkId={artwork.id}
56+
isLiked={true}
57+
onClick={() => handleArtworkClick(artwork.id)}
4558
/>
4659
))}
4760
</ArtworkGrid>
@@ -51,7 +64,11 @@ const MyCollection = () => {
5164
<SectionTitle>전시</SectionTitle>
5265
<ExhibitionGrid>
5366
{exhibitions.map((exhibition) => (
54-
<ExhibitionItem key={exhibition.id}>
67+
<ExhibitionItem
68+
key={exhibition.id}
69+
onClick={() => handleExhibitionClick(exhibition.id)}
70+
style={{ cursor: 'pointer' }}
71+
>
5572
<ExhibitionImage
5673
src={exhibition.image_url}
5774
alt={exhibition.title}

src/pages/artBuyerPage/hooks/useGetBuyerMypage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useSuspenseQuery } from '@tanstack/react-query';
22
import { toast } from 'sonner';
33
import { AxiosError } from 'axios';
4-
import { getBuyerMypageQuery } from '@/constants/queryKeys';
4+
import { getMypageQueryKey } from '@/constants/queryKeys';
55
import { TBuyerMypage } from '@/apis/mypage-buyer/myPage/type';
66
import { getBuyerMypage } from '@/apis/mypage-buyer/myPage/myPage';
77

@@ -19,7 +19,7 @@ export const useGetBuyerMypage = () => {
1919
isLoading,
2020
error,
2121
} = useSuspenseQuery<TBuyerMypage>({
22-
queryKey: getBuyerMypageQuery().queryKey,
22+
queryKey: getMypageQueryKey('buyer'),
2323
queryFn: () => getBuyerMypage(),
2424
staleTime: 1000 * 60 * 30, // 30분
2525
gcTime: 1000 * 60 * 60, // 1시간

src/pages/authorPage/components/menuMyPage/Auction/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
import { useGetAuthorMypage } from '@/pages/authorPage/hooks/useGetAuthorMypage';
1010

1111
/**
12-
* @description 작품 구매자의 경매 내역을 표시하는 컴포넌트
12+
* @description 작가의 경매 내역을 표시하는 컴포넌트
1313
* @author 노찬영
1414
*/
1515

src/pages/authorPage/hooks/useGetAuthorMypage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useSuspenseQuery } from '@tanstack/react-query';
22
import { toast } from 'sonner';
33
import { AxiosError } from 'axios';
4-
import { getAuthorMypageQuery } from '@/constants/queryKeys';
4+
import { getMypageQueryKey } from '@/constants/queryKeys';
55
import { getAuthorMypage } from '@/apis/mypage-author/myPage/myPage';
66
import { TArtistMypage } from '@/apis/mypage-author/myPage/type';
77

@@ -19,7 +19,7 @@ export const useGetAuthorMypage = () => {
1919
isLoading,
2020
error,
2121
} = useSuspenseQuery<TArtistMypage>({
22-
queryKey: getAuthorMypageQuery().queryKey,
22+
queryKey: getMypageQueryKey('author'),
2323
queryFn: () => getAuthorMypage(),
2424
staleTime: 1000 * 60 * 30, // 30분
2525
gcTime: 1000 * 60 * 60, // 1시간

src/router.tsx

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Route, Routes } from 'react-router-dom';
2-
import NotFound from '@/pages/not-found';
32
import { AuthCheckRoute } from '@components/common/AuthCheckRoute';
3+
import NotFound from './pages/not-found';
44
import Test from '@pages/test.tsx';
55
import ArtBuyerPage from './pages/artBuyerPage/ArtBuyerPage';
66
import AuthorPage from './pages/authorPage/AuthorPage';
@@ -19,7 +19,6 @@ import { Main } from '@/pages/main';
1919
import { ArtWork } from '@/pages/artwork';
2020
import { ArtworkDetail } from '@/pages/artwork-detail';
2121
import { AuctionDetail } from './pages/auction-detail';
22-
import { LoginRedirect } from './pages/login-redirect';
2322
type TRoutes = {
2423
path: string;
2524
element: JSX.Element;
@@ -31,37 +30,31 @@ type TRoutes = {
3130
* @author 홍규진
3231
* */
3332

33+
/**
34+
* 작품구매자_마이페이지는 /artBuyerPage 이고,
35+
* 작가_마이페이지는 /authorPage 로 구분했습니다.
36+
* @author 노찬영
37+
* */
38+
3439
// eslint-disable-next-line react-refresh/only-export-components
3540
export const routes: TRoutes[] = [
3641
{ path: '/', element: <Main />, isTabBar: true },
37-
{
38-
path: '/mypage/art-buyer',
39-
element: <ArtBuyerPage />,
40-
isTabBar: true,
41-
isCheckAuth: true,
42-
},
43-
{
44-
path: '/mypage/author',
45-
element: <AuthorPage />,
46-
isTabBar: true,
47-
isCheckAuth: true,
48-
},
42+
{ path: '/mypage/art-buyer', element: <ArtBuyerPage />, isTabBar: true },
43+
{ path: '/mypage/author', element: <AuthorPage />, isTabBar: true },
4944

5045
{ path: '/test', element: <Test />, isTabBar: true },
5146
{ path: '/login', element: <Login />, isTabBar: true },
52-
{ path: '/login/redirect', element: <LoginRedirect />, isTabBar: true },
5347
{ path: '/register', element: <Register />, isTabBar: true },
48+
5449
{
5550
path: '/artwork-register',
5651
element: <ArtworkRegister />,
5752
isTabBar: true,
58-
isCheckAuth: true,
5953
},
6054
{
6155
path: '/auction-register',
6256
element: <AuctionRegister />,
6357
isTabBar: true,
64-
isCheckAuth: true,
6558
},
6659
{
6760
path: '/author',
@@ -87,7 +80,6 @@ export const routes: TRoutes[] = [
8780
path: '/exhibit-register',
8881
element: <ExhibitRegister />,
8982
isTabBar: true,
90-
isCheckAuth: true,
9183
},
9284
{
9385
path: '/auction',
@@ -98,8 +90,8 @@ export const routes: TRoutes[] = [
9890
path: '/auction/:id',
9991
element: <AuctionDetail />,
10092
isTabBar: true,
101-
isCheckAuth: true,
10293
},
94+
{ path: '/main', element: <Main />, isTabBar: true },
10395
{ path: '/artwork', element: <ArtWork />, isTabBar: true },
10496
{ path: '/artwork/:id', element: <ArtworkDetail />, isTabBar: true },
10597
];
@@ -118,7 +110,7 @@ export default function Router() {
118110
key={path}
119111
path={path}
120112
element={
121-
<AuthCheckRoute redirectPath="/login">{element}</AuthCheckRoute>
113+
<AuthCheckRoute redirectPath="/">{element}</AuthCheckRoute>
122114
}
123115
/>
124116
) : (

0 commit comments

Comments
 (0)