Commit 6da882a6 authored by baesangjune's avatar baesangjune
Browse files

Merge remote-tracking branch 'origin/cherry' into BAE

parents 973b899a 8d491db5
...@@ -3,9 +3,10 @@ import React, { useEffect, useState } from 'react'; ...@@ -3,9 +3,10 @@ import React, { useEffect, useState } from 'react';
import { Modal, Container, Row, Button, } from 'react-bootstrap'; import { Modal, Container, Row, Button, } from 'react-bootstrap';
function Place(props) { function Place(props) {
const [reviews, setReviews] = useState([{ title: "", link: "", summery: "", content: "" }]) const [reviews, setReviews] = useState()
const [db, setDb] = useState(false)
const getReview = () => { const getReview = () => {
axios.get(`/api/review/${props.search.name}`) axios({ url: `/api/review?keyword=${props.place.name}`, method: 'post', data: { db: db } })
.then(res => { .then(res => {
console.log("place res.data", res.data) console.log("place res.data", res.data)
setReviews(res.data) setReviews(res.data)
...@@ -27,12 +28,12 @@ function Place(props) { ...@@ -27,12 +28,12 @@ function Place(props) {
aria-labelledby="example-modal-sizes-title-lg"> aria-labelledby="example-modal-sizes-title-lg">
<Modal.Header closeButton> <Modal.Header closeButton>
<Modal.Title id="contained-modal-title-vcenter" style={{ fontSize: '40px' }}> <Modal.Title id="contained-modal-title-vcenter" style={{ fontSize: '40px' }}>
{props.index + 1}. {props.search.name} {props.index + 1}. {props.place.name}
</Modal.Title> </Modal.Title>
</Modal.Header> </Modal.Header>
<Modal.Body className="show-grid"> <Modal.Body className="show-grid">
<Container style={{ fontSize: '40px' }}> <Container style={{ fontSize: '40px' }}>
{reviews.map((review, index) => { {Array.isArray(reviews) ? reviews.map((review, index) => {
return ( return (
<Row className="mt-4"> <Row className="mt-4">
<a href={review.link}>{review.title}</a> <a href={review.link}>{review.title}</a>
...@@ -40,7 +41,8 @@ function Place(props) { ...@@ -40,7 +41,8 @@ function Place(props) {
<div>{review.content}</div> <div>{review.content}</div>
</Row> </Row>
) )
})} })
: "리뷰가 없습니다."}
</Container> </Container>
</Modal.Body> </Modal.Body>
......
...@@ -8,10 +8,7 @@ function App() { ...@@ -8,10 +8,7 @@ function App() {
const [search, setSearch] = useState(""); const [search, setSearch] = useState("");
if (state !== false) { if (state !== false) {
return <Redirect to={{ return <Redirect to={`/search?keyword=${search}`} />;
pathname: `/search/${search}`,
state: { id: search },
}} />;
} }
const handleChange = (e) => { const handleChange = (e) => {
......
...@@ -5,20 +5,20 @@ import Place from '../Components/Place'; ...@@ -5,20 +5,20 @@ import Place from '../Components/Place';
import { Container, Form, Row, Col, Card, Image, InputGroup, FormControl, Button} from 'react-bootstrap'; import { Container, Form, Row, Col, Card, Image, InputGroup, FormControl, Button} from 'react-bootstrap';
import Paginations from '../Components/Paginations'; import Paginations from '../Components/Paginations';
import axios from 'axios'; import axios from 'axios';
import queryString from 'query-string'
function Search(props) { function Search(props) {
const endPage = 10; const endPage = 10;
const [state, setState] = useState(false); const [state, setState] = useState(false);
const [index, setIndex] = useState(1); const [index, setIndex] = useState(1);
const [showSet, setShowSet] = useState([false, false, false, false]); const [showSet, setShowSet] = useState([false, false, false, false]);
const [search, setSearch] = useState(props.location.state.id); const [search, setSearch] = useState(queryString.parse(props.location.search).keyword);
const [mobile, setMobile] = useState(); const [mobile, setMobile] = useState();
const [place, setPlace] = useState([{ name: "", category: "", address: "" }]) const [place, setPlace] = useState([{ name: "", category: "", address: "" }])
const [imgUrl, setImgUrl] = useState([]) const [imgUrl, setImgUrl] = useState([])
const [association, setAssociation] = useState([]) const [association, setAssociation] = useState([])
const getImg = () => { const getImg = () => {
axios.get(`/api/search/imges/${search}`) axios.get(`/api/search/imges?keyword=${search}`)
.then(res => { .then(res => {
console.log("images=", res.data) console.log("images=", res.data)
setImgUrl(res.data) setImgUrl(res.data)
...@@ -29,7 +29,7 @@ function Search(props) { ...@@ -29,7 +29,7 @@ function Search(props) {
} }
const getPlace = () => { const getPlace = () => {
axios.get(`/api/search/places/${search}`) axios.get(`/api/search/places?keyword=${search}`)
.then(res => { .then(res => {
console.log("places=", res.data) console.log("places=", res.data)
setPlace(res.data) setPlace(res.data)
...@@ -40,7 +40,7 @@ function Search(props) { ...@@ -40,7 +40,7 @@ function Search(props) {
} }
const getAssociation =() => { const getAssociation =() => {
axios.get(`/api/search/association/${search}`) axios.get(`/api/search/association?keyword=${search}`)
.then(res => { .then(res => {
console.log("Associations = ", res.data) console.log("Associations = ", res.data)
setAssociation(res.data) setAssociation(res.data)
...@@ -93,7 +93,7 @@ function Search(props) { ...@@ -93,7 +93,7 @@ function Search(props) {
if (state !== false) { if (state !== false) {
return <Redirect to={{ return <Redirect to={{
pathname: `/search/${search}`, pathname: `/search?keyword=${search}`,
state: { id: search }, state: { id: search },
}} />; }} />;
} }
......
...@@ -13,17 +13,13 @@ import { ...@@ -13,17 +13,13 @@ import {
Redirect, Redirect,
} from "react-router-dom"; } from "react-router-dom";
axios.defaults.validateStatus = function (status) {
return status < 500; // default
}
ReactDOM.render( ReactDOM.render(
<React.StrictMode> <React.StrictMode>
<Router> <Router>
<Switch> <Switch>
<Route exact path="/" component={App} /> <Route exact path="/" component={App} />
<Route path="/search" component={Search} /> <Route path="/search" component={Search} />
<Redirect path="/search/:search" to="/search" /> <Redirect path="/search" to="/search" />
</Switch> </Switch>
</Router> </Router>
</React.StrictMode>, </React.StrictMode>,
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -74,15 +74,19 @@ const searchImg = async (req, res) => { ...@@ -74,15 +74,19 @@ const searchImg = async (req, res) => {
} }
const searchAssociation = async (req, res) => { const searchAssociation = async (req, res) => {
let Place = await Places.findOne({ name: req.params.search }) let Place = await Places.findOne({ name: req.query.keyword })
let address = Place.address.split(' ')[0]
if (!Place) {
res.send([])
}
let addresse = Place.address.split(' ')[0]
// let AssociationsId = [] // let AssociationsId = []
let addressPlaces = new RegExp(`${address}`) let addressPlaces = new RegExp(`${addresse}`)
let responsePlaces = await Places.find({ address: addressPlaces }) let responsePlaces = await Places.find({ address: addressPlaces })
res.send(responsePlaces) res.send(responsePlaces)
// responsePlaces.map(Association => { // responsePlaces.map(Association => {
// AssociationsId.push(Association._id) // AssociationsId.push(Association._id)
// }) // })
......
import Review from '../models/Review.js' import Review from '../models/Review.js'
import cheerio from "cheerio"; import cheerio from "cheerio";
import fs from 'fs'
import axios from 'axios'; import axios from 'axios';
const search = async (req, res, next) => { const search = async (req, res, next) => {
console.log("1")
for (let i = 1; (req.reviews).length > 10; i++) {
try { try {
console.log("2")
let reviews = [] let reviews = []
let content = [] let content = []
// Review.find() const url = "https://www.google.com/search?q=" + encodeURI(req.query.keyword) + "+site%3Atistory.com&page_no=" + i
const url = "https://www.google.com/search?q=" + encodeURI(req.params.search) + "+site%3Atistory.com&page_no=1"
const response1 = await axios.get(url) const response1 = await axios.get(url)
// console.log(response1.data) // console.log(response1.data)
const $1 = cheerio.load(response1.data); const $1 = cheerio.load(response1.data);
$1('.kCrYT').each(async function (i) { $1('.kCrYT').each(async function (i) {
console.log("3")
const title = $1(this).find('h3').text() const title = $1(this).find('h3').text()
const searchParams = new URLSearchParams($1(this).find('a').attr('href')); const searchParams = new URLSearchParams($1(this).find('a').attr('href'));
const link = searchParams.get("/url?q") const link = searchParams.get("/url?q")
const summary = $1(this).find('.s3v9rd').find('.s3v9rd').text() const summary = $1(this).find('.s3v9rd').find('.s3v9rd').text()
Review.find({ link: link }, function (err, review) {
if (!review) {
content.push(getReview(link)) content.push(getReview(link))
if (title) { if (title) {
reviews[i] = { title: title, link: link } reviews[i] = { title: title, link: link }
...@@ -24,18 +28,25 @@ const search = async (req, res, next) => { ...@@ -24,18 +28,25 @@ const search = async (req, res, next) => {
reviews[i - 1] = { ...reviews[i - 1], summary: summary } reviews[i - 1] = { ...reviews[i - 1], summary: summary }
reviews = reviews.filter(e => e) reviews = reviews.filter(e => e)
} }
}
})
}) })
let promiseReview = await Promise.all(content) let promiseReview = await Promise.all(content)
promiseReview = promiseReview.filter(e => typeof (e) === 'string') promiseReview = promiseReview.filter(e => typeof (e) === 'string')
reviews.forEach(async (review, i) => { reviews.forEach(async (review, i) => {
console.log("4")
review["content"] = promiseReview[i] review["content"] = promiseReview[i]
const reviews = new Review(review).save() const reviews = new Review(review).save()
reviews.keyword.push(req.query.keyword)
req.reviews.push(reviews)
}) })
console.log("5")
res.send(reviews) res.send(reviews)
} catch (error) { } catch (error) {
// console.log(error) console.log("6")
// res.send(error) console.log(error)
res.send(error)
}
} }
} }
...@@ -69,4 +80,18 @@ const getReview = async (link) => { ...@@ -69,4 +80,18 @@ const getReview = async (link) => {
} }
} }
export default { search } const find = (req, res, next) => {
\ No newline at end of file console.log("7", req.body)
if (req.body.db) {
next()
}
Review.find({ keyword:{ $elemMatch: res.query.keyword } }, function (err, reviews) {
if (reviews) {
if (reviews.length > 10)
res.send(reviews, { db: true })
req.reviews = reviews
}
next()
})
}
export default { search, find }
...@@ -3,13 +3,13 @@ import place from '../controllers/place.controller.js' ...@@ -3,13 +3,13 @@ import place from '../controllers/place.controller.js'
const router = express.Router() const router = express.Router()
router.route('/api/search/imges/:search') router.route('/api/search/imges')
.get(place.searchImg) .get(place.searchImg)
router.route('/api/search/places/:search') router.route('/api/search/places')
.get(place.searchPlace) .get(place.searchPlace)
router.route('/api/search/association/:search') router.route('/api/search/association')
.get(place.searchAssociation) .get(place.searchAssociation)
export default router export default router
\ No newline at end of file
...@@ -3,7 +3,7 @@ import review from '../controllers/review.controller.js' ...@@ -3,7 +3,7 @@ import review from '../controllers/review.controller.js'
const router = express.Router() const router = express.Router()
router.route('/api/review/:search') router.route('/api/review')
.get(review.search) .post(review.find, review.search)
export default router export default router
\ No newline at end of file
<p style="font-size: 1.12em;"><b>안녕하세요 화갱입니다. ㅎㅅㅎ</b></p>
<p style="font-size: 1.12em;">제주도하면 가장 먼저 떠오르는 관광명소가 있죠, 바로 <span style="color: #009a87;"><b>한라산</b></span>입니다. 성산일출봉, 우도, 월정, 애월 등 많은 관광지가 있지만 제주도의 <b>가장 원조적이고 유명한 관광명소는 한라산</b>입니다. 한라산은 <b>해발 1950m</b>로<b> 대한민국에서 가장 높은산</b>입니다. 1970년 국립공원으로 지정되어 2002년 유네스코 생물권보전지역으로 설정되었으며 <b>2007년에는 유네스코 세계자연유산</b>으로 선정되었습니다. 관리사무소도 어리목, 성판악, 영실, 관음사, 돈내코의 5개가 운영되고 있으며 대피소도 윗세오름, 진달래밭, 삼각봉, 속밭, 평궤의 5개가 운영중에 있습니다. 그리고 모든 코스마다 안내 및 표지만, 응급의약품 등 탐방하기에도 안전한 곳입니다. 오늘은 제가 직접 오른 등반코스와 다른 코스 추천 등 한라산 등산코스에 대해 리뷰해보겠습니다. 그럼 시작합니다.</p>
\ 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