11import { client as apiClient } from '@/api/core' ;
2- import type { GlossaryAutoCompleteResponse , GlossaryDetail } from '@/types' ;
2+ import type { GlossaryAutoCompleteResponse , GlossaryDetail , SearchHistoryResponseDto } from '@/types' ;
33
44export 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} ;
0 commit comments