Commit c28d80ec authored by baesangjune's avatar baesangjune
Browse files

검색 안정화

parent 85e9f098
[{"C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\index.js":"1","C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\reportWebVitals.js":"2","C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\Components\\Place.js":"3","C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\Components\\Paginations.js":"4","C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\Pages\\Search.js":"5","C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\Pages\\App.js":"6"},{"size":939,"mtime":1611497444385,"results":"7","hashOfConfig":"8"},{"size":375,"mtime":1611254909401,"results":"9","hashOfConfig":"8"},{"size":1650,"mtime":1611504929008,"results":"10","hashOfConfig":"8"},{"size":2199,"mtime":1611254909395,"results":"11","hashOfConfig":"8"},{"size":8492,"mtime":1611514455100,"results":"12","hashOfConfig":"8"},{"size":1474,"mtime":1611504101870,"results":"13","hashOfConfig":"8"},{"filePath":"14","messages":"15","errorCount":0,"warningCount":1,"fixableErrorCount":0,"fixableWarningCount":0,"source":"16"},"13y9yvi",{"filePath":"17","messages":"18","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"19","messages":"20","errorCount":0,"warningCount":2,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"21","messages":"22","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"23","messages":"24","errorCount":1,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"25","messages":"26","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\index.js",["27"],"import React from 'react';\r\nimport ReactDOM from 'react-dom';\r\nimport './index.css';\r\nimport 'bootstrap/dist/css/bootstrap.min.css';\r\nimport App from './Pages/App';\r\nimport Search from './Pages/Search';\r\nimport axios from 'axios';\r\nimport reportWebVitals from './reportWebVitals';\r\nimport {\r\n BrowserRouter as Router,\r\n Switch,\r\n Route,\r\n Redirect,\r\n} from \"react-router-dom\";\r\n\r\nReactDOM.render(\r\n <React.StrictMode>\r\n <Router>\r\n <Switch>\r\n <Route exact path=\"/\" component={App} />\r\n <Route path=\"/search\" component={Search} />\r\n <Redirect path=\"/search\" to=\"/search\" />\r\n </Switch>\r\n </Router>\r\n </React.StrictMode>,\r\n document.getElementById('root')\r\n);\r\n\r\n// If you want to start measuring performance in your app, pass a function\r\n// to log results (for example: reportWebVitals(console.log))\r\n// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals\r\nreportWebVitals();\r\n","C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\reportWebVitals.js",[],"C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\Components\\Place.js",["28","29"],"C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\Components\\Paginations.js",[],"C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\Pages\\Search.js",["30"],"C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\Pages\\App.js",[],{"ruleId":"31","severity":1,"message":"32","line":7,"column":8,"nodeType":"33","messageId":"34","endLine":7,"endColumn":13},{"ruleId":"31","severity":1,"message":"35","line":7,"column":14,"nodeType":"33","messageId":"34","endLine":7,"endColumn":19},{"ruleId":"36","severity":1,"message":"37","line":21,"column":6,"nodeType":"38","endLine":21,"endColumn":8,"suggestions":"39"},{"ruleId":null,"fatal":true,"severity":2,"message":"40","line":21,"column":4},"no-unused-vars","'axios' is defined but never used.","Identifier","unusedVar","'setDb' is assigned a value but never used.","react-hooks/exhaustive-deps","React Hook useEffect has a missing dependency: 'getReview'. Either include it or remove the dependency array.","ArrayExpression",["41"],"Parsing error: Unexpected token\n\n 19 | const [association, setAssociation] = useState([])\n 20 | \n> 21 | <<<<<<< HEAD\n | ^\n 22 | // console.log(\"search###############\", search)\n 23 | const getPlace = () => {\n 24 | axios.get(`/api/search/places?keyword=${search}`)",{"desc":"42","fix":"43"},"Update the dependencies array to be: [getReview]",{"range":"44","text":"45"},[605,607],"[getReview]"]
\ No newline at end of file
[{"C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\index.js":"1","C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\reportWebVitals.js":"2","C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\Components\\Place.js":"3","C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\Components\\Paginations.js":"4","C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\Pages\\Search.js":"5","C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\Pages\\App.js":"6"},{"size":939,"mtime":1611497444385,"results":"7","hashOfConfig":"8"},{"size":375,"mtime":1611254909401,"results":"9","hashOfConfig":"8"},{"size":1650,"mtime":1611504929008,"results":"10","hashOfConfig":"8"},{"size":2199,"mtime":1611254909395,"results":"11","hashOfConfig":"8"},{"size":8320,"mtime":1611549647705,"results":"12","hashOfConfig":"8"},{"size":1474,"mtime":1611504101870,"results":"13","hashOfConfig":"8"},{"filePath":"14","messages":"15","errorCount":0,"warningCount":1,"fixableErrorCount":0,"fixableWarningCount":0,"source":"16"},"13y9yvi",{"filePath":"17","messages":"18","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"19","messages":"20","errorCount":0,"warningCount":2,"fixableErrorCount":0,"fixableWarningCount":0,"source":"21"},{"filePath":"22","messages":"23","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"24","messages":"25","errorCount":0,"warningCount":7,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"26","messages":"27","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\index.js",["28"],"import React from 'react';\r\nimport ReactDOM from 'react-dom';\r\nimport './index.css';\r\nimport 'bootstrap/dist/css/bootstrap.min.css';\r\nimport App from './Pages/App';\r\nimport Search from './Pages/Search';\r\nimport axios from 'axios';\r\nimport reportWebVitals from './reportWebVitals';\r\nimport {\r\n BrowserRouter as Router,\r\n Switch,\r\n Route,\r\n Redirect,\r\n} from \"react-router-dom\";\r\n\r\nReactDOM.render(\r\n <React.StrictMode>\r\n <Router>\r\n <Switch>\r\n <Route exact path=\"/\" component={App} />\r\n <Route path=\"/search\" component={Search} />\r\n <Redirect path=\"/search\" to=\"/search\" />\r\n </Switch>\r\n </Router>\r\n </React.StrictMode>,\r\n document.getElementById('root')\r\n);\r\n\r\n// If you want to start measuring performance in your app, pass a function\r\n// to log results (for example: reportWebVitals(console.log))\r\n// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals\r\nreportWebVitals();\r\n","C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\reportWebVitals.js",[],"C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\Components\\Place.js",["29","30"],"import axios from 'axios';\r\nimport React, { useEffect, useState } from 'react';\r\nimport { Modal, Container, Row, Button, } from 'react-bootstrap';\r\n\r\nfunction Place(props) {\r\n const [reviews, setReviews] = useState()\r\n const [db, setDb] = useState(false)\r\n const getReview = () => {\r\n axios({ url: `/api/review?keyword=${props.place.name}`, method: 'post', data: { db: db } })\r\n .then(res => {\r\n console.log(\"place res.data\", res.data)\r\n setReviews(res.data)\r\n })\r\n .catch(err => {\r\n console.log(err)\r\n })\r\n }\r\n\r\n useEffect(() => {\r\n getReview();\r\n }, [])\r\n\r\n return (\r\n <Modal {...props}\r\n size=\"xl\"\r\n keyboard=\"true\"\r\n variant=\"backdrop.in\"\r\n aria-labelledby=\"example-modal-sizes-title-lg\">\r\n <Modal.Header closeButton>\r\n <Modal.Title id=\"contained-modal-title-vcenter\" style={{ fontSize: '40px' }}>\r\n {props.index + 1}. {props.place.name}\r\n </Modal.Title>\r\n </Modal.Header>\r\n <Modal.Body className=\"show-grid\">\r\n <Container style={{ fontSize: '40px' }}>\r\n {Array.isArray(reviews) ? reviews.map((review, index) => {\r\n return (\r\n <Row className=\"mt-4\">\r\n <a href={review.link}>{review.title}</a>\r\n <div>{review.summary}</div>\r\n <div>{review.content}</div>\r\n </Row>\r\n )\r\n })\r\n : \"리뷰가 없습니다.\"}\r\n </Container>\r\n\r\n </Modal.Body>\r\n <Modal.Footer>\r\n <Button block onClick={props.onHide}>Close</Button>\r\n </Modal.Footer>\r\n </Modal>\r\n );\r\n}\r\n\r\nexport default Place;\r\n","C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\Components\\Paginations.js",[],"C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\Pages\\Search.js",["31","32","33","34","35","36","37"],"C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\Pages\\App.js",[],{"ruleId":"38","severity":1,"message":"39","line":7,"column":8,"nodeType":"40","messageId":"41","endLine":7,"endColumn":13},{"ruleId":"38","severity":1,"message":"42","line":7,"column":14,"nodeType":"40","messageId":"41","endLine":7,"endColumn":19},{"ruleId":"43","severity":1,"message":"44","line":21,"column":6,"nodeType":"45","endLine":21,"endColumn":8,"suggestions":"46"},{"ruleId":"38","severity":1,"message":"47","line":2,"column":16,"nodeType":"40","messageId":"41","endLine":2,"endColumn":24},{"ruleId":"38","severity":1,"message":"48","line":16,"column":12,"nodeType":"40","messageId":"41","endLine":16,"endColumn":18},{"ruleId":"43","severity":1,"message":"49","line":70,"column":8,"nodeType":"45","endLine":70,"endColumn":10,"suggestions":"50"},{"ruleId":"43","severity":1,"message":"51","line":76,"column":8,"nodeType":"45","endLine":76,"endColumn":21,"suggestions":"52"},{"ruleId":"43","severity":1,"message":"53","line":88,"column":8,"nodeType":"45","endLine":88,"endColumn":15,"suggestions":"54"},{"ruleId":"38","severity":1,"message":"55","line":91,"column":11,"nodeType":"40","messageId":"41","endLine":91,"endColumn":17},{"ruleId":"56","severity":1,"message":"57","line":155,"column":35,"nodeType":"58","endLine":155,"endColumn":76},"no-unused-vars","'axios' is defined but never used.","Identifier","unusedVar","'setDb' is assigned a value but never used.","react-hooks/exhaustive-deps","React Hook useEffect has a missing dependency: 'getReview'. Either include it or remove the dependency array.","ArrayExpression",["59"],"'Redirect' is defined but never used.","'mobile' is assigned a value but never used.","React Hook useEffect has a missing dependency: 'getAssociation'. Either include it or remove the dependency array.",["60"],"React Hook useEffect has a missing dependency: 'index'. Either include it or remove the dependency array. You can also replace multiple useState variables with useReducer if 'setPagePlace' needs the current value of 'index'.",["61"],"React Hook useEffect has missing dependencies: 'getAssociation', 'props.history', and 'search'. Either include them or remove the dependency array.",["62"],"'places' is assigned a value but never used.","react/jsx-no-duplicate-props","No duplicate props allowed","JSXAttribute",{"desc":"63","fix":"64"},{"desc":"65","fix":"66"},{"desc":"67","fix":"68"},{"desc":"69","fix":"70"},"Update the dependencies array to be: [getReview]",{"range":"71","text":"72"},"Update the dependencies array to be: [getAssociation]",{"range":"73","text":"74"},"Update the dependencies array to be: [association, index]",{"range":"75","text":"76"},"Update the dependencies array to be: [getAssociation, props.history, search, state]",{"range":"77","text":"78"},[605,607],"[getReview]",[2392,2394],"[getAssociation]",[2552,2565],"[association, index]",[2839,2846],"[getAssociation, props.history, search, state]"]
\ No newline at end of file
[0122/091810.668:ERROR:directory_reader_win.cc(43)] FindFirstFile: 지정된 경로를 찾을 수 없습니다. (0x3)
[0125/001732.960:ERROR:directory_reader_win.cc(43)] FindFirstFile: 지정된 경로를 찾을 수 없습니다. (0x3)
[0125/093515.306:ERROR:directory_reader_win.cc(43)] FindFirstFile: 지정된 경로를 찾을 수 없습니다. (0x3)
......@@ -14,32 +14,33 @@ function Search(props) {
const [showSet, setShowSet] = useState([false, false, false, false]);
const [search, setSearch] = useState(queryString.parse(props.location.search).keyword);
const [mobile, setMobile] = useState();
const [place, setPlace] = useState([{ name: "", category: "", address: "" }])
const [imgUrl, setImgUrl] = useState([])
// const [place, setPlace] = useState([{ name: "", category: "", address: "" }])
// const [imgUrl, setImgUrl] = useState([])
const [association, setAssociation] = useState([])
const [pagePlace, setPagePlace] = useState([])
// console.log("search###############", search)
const getPlace = () => {
axios.get(`/api/search/places?keyword=${search}`)
.then(res => {
console.log("places=", res.data)
setPlace(res.data)
})
.catch(err => {
console.log('search.places 에러 발생', err)
})
}
const getImg = () => {
axios.get(`/api/search/imges?keyword=${search}`)
.then(res => {
console.log("images=", res.data)
setImgUrl(res.data)
})
.catch(err => {
console.log('search.images 에러 발생', err)
})
}
// const getPlace = () => {
// axios.get(`/api/search/places?keyword=${search}`)
// .then(res => {
// console.log("places=", res.data)
// // setPlace(res.data)
// })
// .catch(err => {
// console.log('search.places 에러 발생', err)
// })
// }
// const getImg = () => {
// axios.get(`/api/search/imges?keyword=${search}`)
// .then(res => {
// console.log("images=", res.data)
// // setImgUrl(res.data)
// })
// .catch(err => {
// console.log('search.images 에러 발생', err)
// })
// }
......@@ -57,8 +58,8 @@ function Search(props) {
useEffect(() => {
getPlace()
getImg()
// getPlace()
// getImg()
getAssociation()
if (window.innerWidth < 960) {
setMobile(true)
......@@ -66,12 +67,25 @@ function Search(props) {
setMobile(false)
}
}, []);
useEffect(() => {
// getImg()
// getAssociation()
setPagePlace(paginate(association, index, association.length))
}, [association])
useEffect(() => {
// getPlace()
// getImg()
getAssociation()
if (state) {
props.history.push('/search?keyword=' + search)
setState(false)
console.log("search야", search)
}
}, [search]);
}, [state])
const places = [{
......@@ -117,7 +131,7 @@ function Search(props) {
}
const handleSubmit = (e) => {
// e.preventDefault()
e.preventDefault()
setState(true);
}
......@@ -130,7 +144,8 @@ function Search(props) {
return page
}
const pagePlace = paginate(association, index, association.length)
let time = new Date()
......
This diff is collapsed.
This diff is collapsed.
......@@ -2,13 +2,13 @@ import Places from '../models/Place.js'
import cheerio from 'cheerio'
import fs from 'fs'
import axios from 'axios';
import { nextTick } from 'process';
const searchPlace = async (req, res) => {
const searchPlace = async (req, res, next,) => {
let DuplicateCheckPlace = await Places.findOne({ name: req.query.keyword })
req.places = DuplicateCheckPlace
if (DuplicateCheckPlace) {
res.send(DuplicateCheckPlace)
console.log("11111111111111111111111Place################ 기존플레이스줄력중")
}
else {
......@@ -23,70 +23,115 @@ const searchPlace = async (req, res) => {
let places = {}
$1('.ct_box_area').each(function (i) {
places[i] = { name: $1('.biz_name').text(), category: $1('.category').text(), address: $1('.addr').text() }
places={
name: $1('.biz_name').text(), category: $1('.category').text(), address: $1('.addr').text()
}
})
// 값이 비어있거나 에러가 생겼을 때를 대비해 try catch를 해야함
const newPlaces = await new Places(places[0]
).save()
res.send(places)
// const newPlaces = await new Places(places[0]
// ).save()
// res.send(places)
req.places = places[0]
console.log("62168748172", req.places)
})
}
next()
}
const searchImg = async (req, res) => {
const searchImg = async (req, res, next) => {
let DuplicateCheckImg = await Places.findOne({ name: req.query.keyword })
console.log("d213532513212osfnlagm2214124", req.places)
if (DuplicateCheckImg) {
if (DuplicateCheckImg.img !== "https://t1.daumcdn.net/thumb/R600x0/?fname=http%3A%2F%2Ft1.daumcdn.net%2Fqna%2Fimage%2F4b035cdf8372d67108f7e8d339660479dfb41bbd") {
res.send(DuplicateCheckImg)
if (req.places.img) {
console.log("333333333333333333333333333IMG@@@@@@@@@@@@@@@@@@@ 기존이미지줄력중")
}
else if (DuplicateCheckImg.img === "https://t1.daumcdn.net/thumb/R600x0/?fname=http%3A%2F%2Ft1.daumcdn.net%2Fqna%2Fimage%2F4b035cdf8372d67108f7e8d339660479dfb41bbd") {
console.log("4444444444444444444444444444444444444444444444444")
req.places.times.push(new Date().toLocaleString())
console.log("세이브 전 111111111111111111", req.places)
const newPlaces = await new Places(req.places).save()
next()
} else {
const imgUrl = "https://www.google.com/search?q=" + encodeURI(req.query.keyword) + "+site:tistory.com/&sxsrf=ALeKk023Dv08KQDodRmpB5222lQuzw2Vaw:1610612821100&source=lnms&tbm=isch"
axios.get(imgUrl)
.then(async (response) => {
console.log("4444444444444444444444444444444444444444444444444새로운 이미지 출력중")
const html = response.data
let name = req.query.keyword
let $1 = cheerio.load(html);
let images = $1('.RAyV4b').find('img').attr('src')
req.places.img = images
//사진만 업데이트
let Place = await Places.findOne({ name: req.query.keyword })
Place.times.push(new Date().toLocaleString())
await Places.updateOne({ name: req.query.keyword }, { img: images, times: Place.times })
// let Place2 = await Places.findOne({ name: req.query.keyword })
req.places.times.push(new Date().toLocaleString())
// await Places.updateOne({ name: req.query.keyword }, { img: images, times: Place2.times })
// res.send(images)
console.log("세이브 전 222222222222222", req.places)
const newPlaces = await new Places(req.places).save()
next()
res.send(images)
})
} else {
console.log("IMG에러")
}
}
}
// if (DuplicateCheckImg !== "https://t1.daumcdn.net/thumb/R600x0/?fname=http%3A%2F%2Ft1.daumcdn.net%2Fqna%2Fimage%2F4b035cdf8372d67108f7e8d339660479dfb41bbd") {
// console.log("333333333333333333333333333IMG@@@@@@@@@@@@@@@@@@@ 기존이미지줄력중")
// }
// else if (DuplicateCheckImg === "https://t1.daumcdn.net/thumb/R600x0/?fname=http%3A%2F%2Ft1.daumcdn.net%2Fqna%2Fimage%2F4b035cdf8372d67108f7e8d339660479dfb41bbd") {
// console.log("4444444444444444444444444444444444444444444444444")
// const imgUrl = "https://www.google.com/search?q=" + encodeURI(req.query.keyword) + "+site:tistory.com/&sxsrf=ALeKk023Dv08KQDodRmpB5222lQuzw2Vaw:1610612821100&source=lnms&tbm=isch"
// axios.get(imgUrl)
// .then(async (response) => {
// const html = response.data
// let name = req.query.keyword
// let $1 = cheerio.load(html);
// let images = $1('.RAyV4b').find('img').attr('src')
// req.places.img = images
// //사진만 업데이트
// // let Place2 = await Places.findOne({ name: req.query.keyword })
// req.places.times.push(new Date().toLocaleString())
// // await Places.updateOne({ name: req.query.keyword }, { img: images, times: Place2.times })
// // res.send(images)
// console.log("세이브 전 111111111111111111", req.places)
// const newPlaces = await new Places(req.places).save()
// next()
// })
// } else {
// console.log("IMG에러")
// }
// req.places.times.push(new Date().toLocaleString())
// console.log("세이브 전222222222222222222222")
// next()
// }
//맨 처음 검색하는 지역의 관광지의 경우 association을 받아올 수 없다.
const searchAssociation = async (req, res) => {
let Place = await Places.findOne({ name: req.query.keyword })
// let Place3 = await Places.findOne({ name: req.query.keyword })
let Place3 = req.places.address
// if (!Place) {
// res.send([])
// }
if (!Place) {
res.status(404).send({ error: "Place.address is null" })
if (!Place3) {
console.log("asdfasdfasdf222222222222222222dsaf2222222222214123q5", Place3)
res.send({ error: "Place.address is null" })
}
else {
let addresse = Place.address.split(' ')[0]
let addresse = Place3.split(' ')[0]
let AssociationsId = []
let addressPlaces = new RegExp(`${addresse}`)
console.log("여기보세요", addressPlaces)
let responsePlaces = await Places.find({ address: addressPlaces })
// const newPlaces = await new Places(places[0]).save()
res.send(responsePlaces)
}
// responsePlaces.map(Association => {
......
......@@ -3,13 +3,14 @@ import place from '../controllers/place.controller.js'
const router = express.Router()
router.route('/api/search/imges')
.get(place.searchImg)
// router.route('/api/search/places')
// .get(place.searchPlace, place.searchImg, place.searchAssociation)
// router.route('/api/search/imges')
// .get(place.searchImg)
router.route('/api/search/places')
.get(place.searchPlace)
router.route('/api/search/association')
.get(place.searchAssociation)
.get(place.searchPlace, place.searchImg, place.searchAssociation)
export default router
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment