Skip to content

Commit ca98c0a

Browse files
authored
[FRONTEND] 임시 api 연결 (#91)
임시 api 연결
1 parent 50ef5e9 commit ca98c0a

File tree

6 files changed

+88
-12
lines changed

6 files changed

+88
-12
lines changed

frontend/.env

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
VITE_KAKAO_CLIENT_ID=e84faf4e473047e82fd05e50e9b0c0ce
22
VITE_KAKAO_AUTH_URL=https://kauth.kakao.com/oauth/authorize
33
VITE_KAKAO_REDIRECT_URI=http://localhost:3000/oauth/kakao/redirect
4-
VITE_API_URL=https://api.com-together.org
4+
# VITE_API_URL=https://api.com-together.org
5+
6+
VITE_API_URL=http://13.211.131.16:8080/

frontend/src/api/core/query-config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ export const queryKeys = {
6161
AUTO_COMPLETE: (query: string) =>
6262
['glossary', 'autocomplete', query] as const,
6363
DETAIL: (query: string) => ['glossary', 'detail', query] as const,
64+
HISTORY: (size?: number) =>
65+
size ? ['glossary', 'history', size] : ['glossary', 'history'] as const,
6466
},
6567

6668
PRODUCTS: {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
2+
import { queryKeys } from '../core/query-config';
3+
import { glossaryService } from '@/api/services/glossaryService';
4+
5+
/**
6+
* 검색 기록을 가져오는 React Query 훅
7+
* @param size 조회할 검색 기록 개수 (기본값: 30)
8+
*/
9+
export const useGlossaryHistory = (size: number = 30) => {
10+
return useQuery({
11+
queryKey: queryKeys.GLOSSARY.HISTORY(size),
12+
queryFn: () => glossaryService.getGlossaryHistory(size),
13+
staleTime: 1000 * 60 * 5, // 5분
14+
gcTime: 1000 * 60 * 10, // 10분
15+
});
16+
};
17+
18+
/**
19+
* 검색 기록을 삭제하는 React Query 훅
20+
*/
21+
export const useDeleteGlossaryHistory = () => {
22+
const queryClient = useQueryClient();
23+
24+
return useMutation({
25+
mutationFn: (historyId: number) => glossaryService.deleteGlossaryHistory(historyId),
26+
onSuccess: () => {
27+
// 삭제 성공 시 검색 기록 목록을 다시 불러옴
28+
queryClient.invalidateQueries({ queryKey: queryKeys.GLOSSARY.HISTORY() });
29+
},
30+
});
31+
};

frontend/src/api/services/glossaryService.ts

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { client as apiClient } from '@/api/core';
2-
import type { GlossaryAutoCompleteResponse, GlossaryDetail } from '@/types';
2+
import type { GlossaryAutoCompleteResponse, GlossaryDetail, SearchHistoryResponseDto } from '@/types';
33

44
export const glossaryService = {
55
/**
@@ -8,7 +8,6 @@ export const glossaryService = {
88
* @param size 반환할 결과의 최대 개수 (기본값 5)
99
*/
1010
getAutoComplete: async (query: string, size: number = 5) => {
11-
console.log('🔍 [Glossary] 자동완성 요청:', { query, size });
1211
try {
1312
const response = await apiClient.get<GlossaryAutoCompleteResponse>(
1413
'/glossary/autocomplete',
@@ -19,18 +18,11 @@ export const glossaryService = {
1918
},
2019
},
2120
);
22-
console.log('✅ [Glossary] 자동완성 성공:', response);
23-
console.log(' - response.data:', response.data);
24-
console.log(' - response.data type:', typeof response.data);
25-
26-
// response는 ApiResponse 형태: { success, message, data }
27-
// response.data는 실제 데이터: { suggestions: string[] }
21+
2822
const suggestions = (response.data as GlossaryAutoCompleteResponse)?.suggestions || [];
29-
console.log(' - suggestions:', suggestions);
3023

3124
return suggestions;
3225
} catch (error) {
33-
console.error('❌ [Glossary] 자동완성 실패:', error);
3426
// 에러 정보 출력
3527
const axiosError = error as {
3628
response?: {
@@ -65,4 +57,43 @@ export const glossaryService = {
6557
throw error;
6658
}
6759
},
60+
61+
/**
62+
* 검색 기록 조회
63+
* @param size 조회할 검색 기록 개수 (기본값 30)
64+
*/
65+
getGlossaryHistory: async (size: number = 30) => {
66+
console.log('🔍 [Glossary] 검색 기록 조회 요청:', { size });
67+
try {
68+
const response = await apiClient.get<SearchHistoryResponseDto>(
69+
'/glossary/history',
70+
{
71+
params: { size },
72+
}
73+
);
74+
console.log('✅ [Glossary] 검색 기록 조회 성공:', response);
75+
return response.data;
76+
} catch (error) {
77+
console.error('❌ [Glossary] 검색 기록 조회 실패:', error);
78+
throw error;
79+
}
80+
},
81+
82+
/**
83+
* 검색 기록 삭제
84+
* @param historyId 삭제할 검색 기록 ID
85+
*/
86+
deleteGlossaryHistory: async (historyId: number) => {
87+
console.log('🗑️ [Glossary] 검색 기록 삭제 요청:', { historyId });
88+
try {
89+
const response = await apiClient.delete<void>(
90+
`/glossary/history/${historyId}`
91+
);
92+
console.log('✅ [Glossary] 검색 기록 삭제 성공:', response);
93+
return response.data;
94+
} catch (error) {
95+
console.error('❌ [Glossary] 검색 기록 삭제 실패:', error);
96+
throw error;
97+
}
98+
},
6899
};

frontend/src/components/common/header/header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default function Header() {
2626
}}
2727
/>
2828
<NavButton
29-
text="호환성 체크"
29+
text="견적 짜기"
3030
onClick={() => {
3131
navigate("/compatibility-check");
3232
}}

frontend/src/types/glossary.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,14 @@ export interface GlossaryDetail {
1212
export interface GlossaryDetailResponse {
1313
name: string;
1414
description: string;
15+
}
16+
17+
// 검색 기록 타입
18+
export interface SearchHistoryDto {
19+
historyId: number;
20+
keyword: string;
21+
}
22+
23+
export interface SearchHistoryResponseDto {
24+
histories: SearchHistoryDto[];
1525
}

0 commit comments

Comments
 (0)