-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
216 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// 검색 관련 공공 데이터 API | ||
|
||
import { AreaCodeItem, PlaceBasedAreaItem } from '@/types/main'; | ||
import { Response } from '@/types/public'; | ||
|
||
import { publicDataClient } from '..'; | ||
|
||
interface placeBasedAreaParams { | ||
region: string; | ||
} | ||
|
||
export const getAreaCode = async () => { | ||
const params = `MobileApp=UNITRIP&_type=json&numOfRows=20&MobileOS=ETC&serviceKey=${import.meta.env.VITE_PUBLIC_DATA_SERVICE_KEY}`; | ||
|
||
const { | ||
data: { | ||
response: { | ||
body: { items }, | ||
}, | ||
}, | ||
} = await publicDataClient.get<Response<AreaCodeItem[]>>( | ||
`/areaCode1?${params}`, | ||
); | ||
return items; | ||
}; | ||
|
||
export const getPlaceBasedArea = async (paramsInfo: placeBasedAreaParams) => { | ||
const areaItem = await getAreaCode(); | ||
|
||
const areaCode = | ||
areaItem === '' | ||
? '1' | ||
: areaItem.item.find(({ name }) => paramsInfo.region.startsWith(name)) | ||
?.code; | ||
|
||
const params = `MobileApp=UNITRIP&_type=json&arrange=Q&contentTypeId=12&areaCode=${areaCode || '1'}&MobileOS=ETC&serviceKey=${import.meta.env.VITE_PUBLIC_DATA_SERVICE_KEY}`; | ||
|
||
const { | ||
data: { | ||
response: { | ||
body: { items }, | ||
}, | ||
}, | ||
} = await publicDataClient.get<Response<PlaceBasedAreaItem[]>>( | ||
`/areaBasedList1?${params}`, | ||
); | ||
return items; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
export interface PlaceBasedAreaItem { | ||
mapy: string; | ||
mlevel: string; | ||
cpyrhtDivCd: string; | ||
firstimage: string; | ||
firstimage2: string; | ||
mapx: string; | ||
booktour: string; | ||
contentid: string; | ||
cat3: string; | ||
cat2: string; | ||
modifiedtime: string; | ||
sigungucode: string; | ||
tel: string; | ||
title: string; | ||
zipcode: string; | ||
addr1: string; | ||
addr2: string; | ||
areacode: string; | ||
cat1: string; | ||
contenttypeid: string; | ||
createdtime: string; | ||
} | ||
|
||
export interface AreaCodeItem { | ||
rnum: string; | ||
code: string; | ||
name: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,18 @@ | ||
export interface Response<T> { | ||
response: T; | ||
response: { | ||
header: { | ||
resultCode: string; | ||
resultMsg: string; | ||
}; | ||
body: { | ||
numOfRows: number; | ||
pageNo: number; | ||
totalCount: number; | ||
items: | ||
| { | ||
item: T; | ||
} | ||
| ''; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.