From 19e9d7db04948c92e4752c0d784c14e10529cc08 Mon Sep 17 00:00:00 2001 From: swcho Date: Mon, 14 Jul 2025 15:26:13 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20map=20store=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wr/app/store/map/index.tsx | 185 -------------------------------- 1 file changed, 185 deletions(-) delete mode 100644 apps/wr/app/store/map/index.tsx diff --git a/apps/wr/app/store/map/index.tsx b/apps/wr/app/store/map/index.tsx deleted file mode 100644 index 6a1e76c9b..000000000 --- a/apps/wr/app/store/map/index.tsx +++ /dev/null @@ -1,185 +0,0 @@ -import { getFetch } from "@/components/lib/api"; - -export type wrMapType = wrMapState & wrMapActions; - -export type wrMapState = { - wrMap: { - buildingSearchRes: any[] - } // 건물 검색 결과 데이터 -}; - -type wrMapActions = { - buildingNmSearch: ( - flg: string, - sigunCode: string, - searchNm: string | undefined - ) => void; - buildingNmSearchMultiple: ( - checkedLayers: string[], - sigunCode: string, - searchNm: string | undefined - ) => void; // 여러 레이어 동시 검색 함수 추가 -}; - -export const wrMapStateExport: wrMapState = { - wrMap: { - buildingSearchRes: [] - } -}; - -// 레이어 타입과 플래그 매핑 -const LAYER_FLAG_MAP: { [key: string]: string } = { - // '46': '???', // 하수처리시설 - // '47': '???', // 하수재이용시설 - '48': 'RNB', // 빗물이용시설 - '49': 'RST', // 중수도시설 - '50': 'HTB', // 온배수시설 -}; - -const findBdst = async (flg: string, sggCd: string, searchTxt: string | undefined) => { - return await getFetch('wr', `/reuseFc/building/${flg}/${sggCd}` + (searchTxt ? `/${searchTxt}` : '')) -} - -export const wrMapActionsExport: (set: any) => wrMapActions = ( - set: any -) => { - return { - buildingNmSearch: async ( - flg: string, - sigunCode: string, - searchNm: string | undefined - ) => { - try { - // if (!searchNm || searchNm.length < 2) { - // set((state: wrMapState) => ({ - // ...state, - // buildingSearchData: [] - // })); - // return; - // } - console.log("건축물 코드, 시군구 코드, 검색어: ", flg, sigunCode, searchNm); - - const response = await findBdst(flg, sigunCode, searchNm); - console.log("response: ", response); - - // API 응답을 SearchInputText 형식으로 변환 - const searchListFormatted = (response || []).map((building: any) => ({ - searchNm: building.bdstNm, - searchPk: String(building.bdstInfoPk), - dmdCoNm: building.bdstNm, - layerType: flg, - ...building - })); - - // findBdst와 유사한 API 호출 - // findBdst(flg, sigunCode || "", searchNm).then(() => { - // console.log("건물 검색 API 호출: ", sigunCode, searchNm, flg); - // // bdst.bdstBase를 SearchInputText 형식으로 변환 - // const searchListFormatted = (state.bdst.bdstBase || []).map((building: any) => ({ - // searchNm: building.bdstNm, - // searchPk: String(building.bdstInfoPk), - // dmdCoNm: building.bdstNm, - // layerType: flg, - // ...building - // })); - - // set((state: any) => ({ - // ...state, - // wrMap: { - // ...state.wrMap, - // buildingSearchData: searchListFormatted - // } - // })); - // }); - set((state: wrMapState) => ({ - ...state, - wrMap: { - ...state.wrMap, - buildingSearchRes: searchListFormatted - } - })); - } catch (error) { - console.error("건물 검색 중 오류:", error); - } - }, - - buildingNmSearchMultiple: async ( - checkedLayers: string[], - sigunCode: string, - searchNm: string | undefined - ) => { - try { - if (!searchNm || searchNm.length < 2) { - set((state: any) => ({ - ...state.wrMap, - buildingSearchData: [] - })); - return; - } - - // 체크된 레이어들에 대해 병렬로 API 호출 - const searchPromises = checkedLayers - .filter(layer => LAYER_FLAG_MAP[layer]) // 매핑된 레이어만 필터링 - .map(layer => { - const flg = LAYER_FLAG_MAP[layer]; - - return findBdst(flg, sigunCode, searchNm) - .then(response => { - console.log(`레이어 ${layer}(${flg}) API 응답:`, response); - - const searchListFormatted = (state.bdst.bdstBase || []).map((building: any) => ({ - searchNm: building.bdstNm, - searchPk: String(building.bdstInfoPk), - dmdCoNm: building.bdstNm, - layerType: flg, - ...building - })); - - return { - layerType: layer, - flg: flg, - data: bdstNames - }; - }) - .catch(error => { - console.error(`레이어 ${layer}(${flg}) 검색 중 오류:`, error); - return { layerType: layer, flg: flg, data: [] }; - }); - }); - - const results = await Promise.all(searchPromises); - console.log("다중 레이어 검색 결과:", results); - - // 모든 결과를 하나의 배열로 합치기 - const allSearchResults = results.reduce((acc, result) => { - const formatted = result.data.map((building: any) => ({ - searchNm: building.bdstNm, - searchPk: String(building.bdstInfoPk), - dmdCoNm: building.bdstNm, - layerType: result.layerType, - flg: result.flg, - ...building.originalData - })); - return [...acc, ...formatted]; - }, [] as any[]); - - console.log("최종 합쳐진 검색 결과:", { - totalCount: allSearchResults.length, - sampleData: allSearchResults.slice(0, 3) - }); - - set((state: any) => ({ - ...state.wrMap, - buildingSearchData: allSearchResults - })); - - } catch (error) { - console.error("다중 레이어 검색 중 오류:", error); - set((state: any) => ({ - ...state, - buildingSearchData: [] - })); - } - } - }; -}; \ No newline at end of file