-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Update기능, 폐업한 가게 DB에서 삭제 기능 추가 #75
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
f5cdd2f
feat: 업종에 대한 가게 전체 DB에 insert기능 추가
sphy1597 db96ab7
feat: 전체 데이터 넣는 기능 분리 및 url 변경
sphy1597 4204c5a
feat: 폐업 가게 추가 x
sphy1597 953d22a
feat: 엽엉 상태가 폐업인 가게 제외
sphy1597 0c340ae
feat: 전체 데이터 저장, 업데이트 2가지 케이스로 분리
sphy1597 e9dec82
docs: Readmd.md에 apikey 얻는 법 추가
sphy1597 67bd146
docs: Readme.md 링크 수정
sphy1597 48190cd
Merge branch 'main' into pipeline
scarf005 474d6f8
test: test commit
sphy1597 d8a33d9
Merge branch 'pipeline' of https://github.com/sphy1597/hotplace into …
sphy1597 d028d2d
Merge: #63까지
sphy1597 16e39c1
Merge branch 'main' of https://github.com/sphy1597/hotplace into pipe…
sphy1597 471727f
Merge branch 'wanted-7h:main' into pipeline
sphy1597 f2a94b5
test commit
sphy1597 e3718d6
test: test commit
sphy1597 da80198
feat: update기능, 폐업한 가게 삭제기능 추가
sphy1597 30dd66e
style: prettier
scarf005 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -3,7 +3,7 @@ import morgan from "morgan"; | |||||||||
import testRouter from "./test/test.router.ts"; | ||||||||||
import dotenv from "dotenv"; | ||||||||||
import { userContract, userRouter } from "./user/user_router"; | ||||||||||
import { dbScheduler } from "./scheduler/scheduler"; | ||||||||||
import { dbScheduler } from "./scheduler/scheduler.ts"; | ||||||||||
import db from "./db/models"; | ||||||||||
import schedule from "node-schedule"; | ||||||||||
import { createExpressEndpoints, initServer } from "@ts-rest/express"; | ||||||||||
|
@@ -14,6 +14,7 @@ import { reviewRouter, reviewContract } from "./review/mod.ts"; | |||||||||
import { restaurantsContract, restaurantsRouter } from "./restaurants"; | ||||||||||
import { initContract } from "@ts-rest/core"; | ||||||||||
import { regionsContract, regionsRouter } from "./regions"; | ||||||||||
import {} from "node:fs"; | ||||||||||
|
||||||||||
dotenv.config(); | ||||||||||
|
||||||||||
|
@@ -29,7 +30,7 @@ app.use("/openapi", swaggerUi.serve, swaggerUi.setup(openApiDocument)); | |||||||||
|
||||||||||
db.sequelize | ||||||||||
.sync({ | ||||||||||
force: true, //임시 | ||||||||||
force: false, //임시 | ||||||||||
}) | ||||||||||
.then(() => { | ||||||||||
console.log("connected"); | ||||||||||
|
@@ -73,9 +74,9 @@ createExpressEndpoints(reviewContract, reviewRouter, app, jwtMiddleware); | |||||||||
|
||||||||||
app.listen(3000, () => { | ||||||||||
console.log("Server On"); | ||||||||||
// schedule.scheduleJob("0 * * * * *", function () { | ||||||||||
// dbScheduler(); | ||||||||||
// }); | ||||||||||
schedule.scheduleJob("0 * * * * *", function () { | ||||||||||
dbScheduler(); | ||||||||||
}); | ||||||||||
Comment on lines
+77
to
+79
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
함수를 인자 없이 그대로 실행한다면, 함수를 그대로 전달하면 가독성을 올릴 수 있어요! |
||||||||||
}); | ||||||||||
|
||||||||||
/* | ||||||||||
|
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,30 @@ | ||
{ | ||
"0": { | ||
"data1": "Genrestrtcate", | ||
"data2": "Genrestrtsash" | ||
}, | ||
"1": { | ||
"data1": "Genrestrtfastfood", | ||
"data2": "Genrestrtstandpub" | ||
}, | ||
"2": { | ||
"data1": "Genrestrtlunch", | ||
"data2": "Genrestrtjpnfood" | ||
}, | ||
"3": { | ||
"data1": "Genrestrtbsrpcook", | ||
"data2": "Genrestrtchifood'" | ||
}, | ||
"4": { | ||
"data1": "Genrestrttratearm", | ||
"data2": "Genrestrtbuff" | ||
}, | ||
"5": { | ||
"data1": "Genrestrtsoup", | ||
"data2": "Genrestrtfugu" | ||
}, | ||
"6": { | ||
"data1": "Genrestrtmovmntcook", | ||
"data2": "Kidscafe" | ||
} | ||
} |
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,6 +1,97 @@ | ||
import axios from "axios"; | ||
import db from "../db/models/index"; | ||
import { readFileSync } from "node:fs"; | ||
import { join, dirname } from "node:path"; | ||
import { fileURLToPath } from "node:url"; | ||
import { restaurantsRouter } from "../restaurants"; | ||
|
||
export const updateRestData = async () => { | ||
console.log("업데이트 "); | ||
const today = new Date(2023, 11, 10).getDay(); | ||
// 하루에 2개의 업종별로 업데이트 | ||
const path = join(dirname(fileURLToPath(import.meta.url)), "sectors.json"); | ||
const raw = readFileSync(path, { encoding: "utf8" }); | ||
const secotrs = JSON.parse(raw); | ||
|
||
await updateDB(secotrs[today].data1); | ||
}; | ||
|
||
const updateDB = async (_sectors: string) => { | ||
const key = process.env.api_key; | ||
|
||
try { | ||
//업종명 | ||
|
||
const getHeadUrl = | ||
"https://openapi.gg.go.kr/" + | ||
_sectors + | ||
"?key=" + | ||
key + | ||
"&type=json&pSize=5&pindex=1"; | ||
|
||
const getHead = await axios.get(getHeadUrl); | ||
const headData = getHead.data; | ||
|
||
// 데이터 총 개수 | ||
// const total = headData.GENRESTRT[0].head[0].list_total_count; | ||
const total = 5; | ||
// 한번에 가져올 데이터 수 | ||
const chunkSize = 2; | ||
var cnt = 0; | ||
for (let idx = 1; idx < total; idx += chunkSize) { | ||
const url = | ||
"https://openapi.gg.go.kr/" + | ||
_sectors + | ||
"?key=" + | ||
key + | ||
"&type=json&pSize=" + | ||
chunkSize + | ||
"&pindex=" + | ||
Math.floor(idx / chunkSize + 1); | ||
|
||
// 전체 데이터 가져오기 | ||
const response = await axios.get(url); | ||
const responseData = response.data; | ||
const restaurants = responseData[_sectors][1].row; | ||
|
||
for (let i in restaurants) { | ||
// 폐업한 가게 중에서 DB에 데이터가 있다면 삭제 | ||
if (restaurants[i].BSN_STATE_NM == "폐업") { | ||
const closed = await db.Restaurant.findOne({ | ||
where: { | ||
restaurant_name: restaurants[i].BIZPLC_NM, | ||
adress: restaurants[i].REFINE_LOTNO_ADDR, | ||
}, | ||
}); | ||
// 삭제 로직 | ||
if (closed !== null) { | ||
db.Restaurant.destroy({ | ||
where: { | ||
restaurant_name: restaurants[i].BIZPLC_NM, | ||
adress: restaurants[i].REFINE_LOTNO_ADDR, | ||
}, | ||
}); | ||
} | ||
} else { | ||
// 영업 중인 가게 정보 업데이트 | ||
db.Restaurant.update( | ||
{ | ||
restaurant_name: restaurants[i].BIZPLC_NM, | ||
restaurant_type: restaurants[i].SANITTN_BIZCOND_NM, | ||
adress: restaurants[i].REFINE_LOTNO_ADDR, // 도로명 주소가 없는 식당이 존재 함 | ||
lat: Number(restaurants[i].REFINE_WGS84_LAT), | ||
lon: Number(restaurants[i].REFINE_WGS84_LOGT), | ||
}, | ||
{ | ||
where: { | ||
restaurant_name: restaurants[i].BIZPLC_NM, | ||
adress: restaurants[i].REFINE_LOTNO_ADDR, | ||
}, | ||
}, | ||
); | ||
} | ||
Comment on lines
+56
to
+91
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for...of 문법을 사용해 가독성을 올리고 실수를 줄일 수 있을 것 같아요! |
||
} | ||
} | ||
} catch (error) { | ||
console.log("api 호출 중 오류 발생 : ", error); | ||
} | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 설정은 다른 운영체제에서 경로로 인한 오류가 발생할 수 있을 것 같아요. 어떤 용도인지 알려주실수 있을까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
어제 실행 오류를 해결하려고 하다보니 생긴 부분인것 같습니다