diff --git a/hooks/useSearchSingleVehicle.ts b/hooks/useSearchSingleVehicle.ts index af41c60..d8522fa 100644 --- a/hooks/useSearchSingleVehicle.ts +++ b/hooks/useSearchSingleVehicle.ts @@ -25,17 +25,16 @@ export const useSearchSingleVehicle = () => { return } - const response = await vehicleAPI.getVehicleInfo(searchTerm) + const result = await vehicleAPI.getVehicleInfo(searchTerm) - console.log(response) - - // TODO: 등록되지 않은 차량의 경우 어떤 에러코드가 오는지 확인 후 처리 - if (!response.isValid) { - showMessage(response.value) + if (!result.isValid) { + showMessage(result.value as string) return } - const vehicleInfo = response.value + if (typeof result.value === 'string') return + + const vehicleInfo = result.value updateMapLocation( { diff --git a/lib/apis/vehicle.ts b/lib/apis/vehicle.ts index 0e9227f..21a9acd 100644 --- a/lib/apis/vehicle.ts +++ b/lib/apis/vehicle.ts @@ -1,5 +1,6 @@ import { API_URL } from '@/constants/api' import { apiClient } from '@/lib/apis/client' +import { normalizeVehicleResponse } from '@/lib/utils/normalize' // import { DateTime } from '@/app/route/types/date' // import { formatToISODate } from '@/lib/utils/date' import mockRoutesData from '@/mock/vehicle_route_data.json' @@ -8,7 +9,11 @@ import { VehicleDetailsModel, VehicleStatusType } from '@/types/vehicle' // 예시 API 구조 export const vehicleAPI = { getVehicleInfo: async (vehicleNumber: string) => { - const response = await apiClient.get(`${API_URL}/api/v1/vehicles/search?vehicle-number=${vehicleNumber}`) + const response = await apiClient.get(`${API_URL}/api/v1/vehicles/search`, { + params: { + 'vehicle-number': vehicleNumber, + }, + }) if (!response.data.isSuccess) { if (response.data.errorCode === 1003) { @@ -16,7 +21,8 @@ export const vehicleAPI = { } } - return { isValid: true, value: response.data.result } + const normalizeResult = normalizeVehicleResponse(response.data.result) + return { isValid: true, value: normalizeResult } }, // fetchVehicleDetails: async (vehicleId: string) => { fetchVehicleDetails: async (): Promise => { diff --git a/lib/utils/normalize.ts b/lib/utils/normalize.ts new file mode 100644 index 0000000..86b5313 --- /dev/null +++ b/lib/utils/normalize.ts @@ -0,0 +1,15 @@ +import { VehicleInfoModel } from '@/types/vehicle' + +export const normalizeCoordinate = (coordinateValue: number): number => coordinateValue / 1000000 +export const denormalizeCoordinate = (coordinateValue: number): number => coordinateValue * 1000000 + +export const normalizeVehicleResponse = (data: VehicleInfoModel) => { + return { + ...data, + recentCycleInfo: { + ...data.recentCycleInfo, + lat: normalizeCoordinate(data.recentCycleInfo.lat), + lng: normalizeCoordinate(data.recentCycleInfo.lng), + }, + } +}