Skip to content

Commit 268e90f

Browse files
authored
Merge branch 'develop' into Feat/98/CrewAPI
2 parents 1ce21b6 + d9d83c4 commit 268e90f

21 files changed

+273
-126
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ yarn-error.log*
2727

2828
# local env files
2929
.env*.local
30+
.env
3031

3132
# vercel
3233
.vercel
@@ -35,7 +36,7 @@ yarn-error.log*
3536
*.tsbuildinfo
3637
next-env.d.ts
3738

38-
*storybook.log
3939

4040
# storybook
41-
/storybook-static
41+
/storybook-static
42+
*storybook.log

next.config.mjs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,5 @@ const nextConfig = {
3030
},
3131
];
3232
},
33-
async rewrites() {
34-
return [
35-
{
36-
source: '/:path*',
37-
destination: `${process.env.NEXT_PUBLIC_API_BASE_URL}/:path*`,
38-
},
39-
];
40-
},
4133
};
4234
export default nextConfig;
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { fetchApi } from '@/src/utils/api';
22
import { CrewDetail } from '@/src/types/crew-card';
33

4-
export async function getCrewDetail(): Promise<{ data: CrewDetail }> {
5-
const response = await fetchApi<CrewDetail[]>('/crewDetail', {
4+
export async function getCrewDetail(id: number): Promise<CrewDetail> {
5+
const url = `/api/crews/${id}`;
6+
7+
const response = await fetchApi<{ data: CrewDetail }>(url, {
68
method: 'GET',
79
headers: {
810
'Content-Type': 'application/json',
911
},
1012
});
11-
12-
return { data: response[0] };
13+
return response.data;
1314
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { fetchApi } from '@/src/utils/api';
2+
import { GatheringDetailType } from '@/src/types/gathering-data';
3+
4+
export async function GetGatheringDetail(
5+
crewId: number,
6+
gatheringId: number,
7+
): Promise<GatheringDetailType> {
8+
const url = `/api/crews/${crewId}/gatherings/${gatheringId}`;
9+
10+
const response = await fetchApi<{ data: GatheringDetailType }>(url, {
11+
method: 'GET',
12+
headers: {
13+
'Content-Type': 'application/json',
14+
},
15+
});
16+
return response.data;
17+
}
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import { fetchApi } from '@/src/utils/api';
22
import { GatheringType } from '@/src/types/gathering-data';
33

4-
export async function getGatheringList(): Promise<GatheringType[]> {
5-
return fetchApi<GatheringType[]>('/gatherings', {
4+
export async function getGatheringList(id: number): Promise<GatheringType[]> {
5+
const url = `/api/crews/${id}/gatherings`;
6+
7+
const response = await fetchApi<{ data: GatheringType[] }>(url, {
68
method: 'GET',
79
headers: {
810
'Content-Type': 'application/json',
911
},
1012
});
13+
return response.data;
1114
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { useQuery } from '@tanstack/react-query';
2+
import { getCrewDetail } from '@/src/_apis/detail/get-crew-detail';
3+
4+
export function useGetCrewDetailQuery(id: number) {
5+
return useQuery({
6+
queryKey: ['crewDetail', id],
7+
queryFn: () => getCrewDetail(id),
8+
});
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { useQuery } from '@tanstack/react-query';
2+
import { GetGatheringDetail } from '@/src/_apis/detail/get-gathering-detail';
3+
4+
export function useGetGatheringDetailQuery(crewId: number, gatheringId: number) {
5+
return useQuery({
6+
queryKey: ['gatheringDetail', crewId, gatheringId],
7+
queryFn: () => GetGatheringDetail(crewId, gatheringId),
8+
});
9+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { useQuery } from '@tanstack/react-query';
2+
import { getGatheringList } from '@/src/_apis/detail/get-gathering-list';
3+
import { GatheringType } from '@/src/types/gathering-data';
4+
5+
export function useGetGatheringListQuery(id: number) {
6+
return useQuery<GatheringType[], Error>({
7+
queryKey: ['gatheringList', id],
8+
queryFn: () => getGatheringList(id),
9+
enabled: !!id,
10+
});
11+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use client';
2+
3+
import { useGetCrewDetailQuery } from '@/src/_queries/detail/crew-detail-queries';
4+
import { ApiError } from '@/src/utils/api';
5+
import DetailCrewCard from '@/src/components/common/crew-list/detail-crew-card';
6+
7+
interface DetailCrewSectionProps {
8+
id: number;
9+
}
10+
11+
export default function DetailCrewSection({ id }: DetailCrewSectionProps) {
12+
const { data, isLoading, error } = useGetCrewDetailQuery(id);
13+
14+
// TODO: 추후 에러 처리 수정
15+
if (isLoading) return <p>Loading...</p>;
16+
17+
if (error) {
18+
if (error instanceof ApiError) {
19+
try {
20+
const errorData = JSON.parse(error.message);
21+
22+
if (errorData.status === 'NOT_FOUND') {
23+
return <p>크루 정보를 찾을 수 없습니다</p>;
24+
}
25+
} catch {
26+
return <p>{`Error ${error.status}: ${error.message}`}</p>;
27+
}
28+
}
29+
return <p>데이터 통신에 실패했습니다.</p>;
30+
}
31+
32+
// data가 있을 때만 DetailCrewCard를 렌더링
33+
return data ? <DetailCrewCard data={data} /> : null;
34+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use client';
2+
3+
import { useGetGatheringListQuery } from '@/src/_queries/detail/gathering-list-queries';
4+
import GatheringCardCarousel from '@/src/components/gathering-list/gathering-card-carousel';
5+
6+
interface GatheringListSectionProps {
7+
id: number;
8+
}
9+
10+
export default function GatheringListSection({ id }: GatheringListSectionProps) {
11+
const { data: gatheringList, isLoading, error } = useGetGatheringListQuery(id);
12+
13+
if (isLoading) return <p>로딩 중...</p>;
14+
15+
if (error) return <p>데이터를 불러오는 데 실패했습니다: {error.message}</p>;
16+
17+
if (!gatheringList || gatheringList.length === 0) return <p>데이터가 없습니다.</p>;
18+
19+
return <GatheringCardCarousel gatheringData={gatheringList} crewId={id} />;
20+
}

0 commit comments

Comments
 (0)