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';
import { Modal, Container, Row, Button, } from 'react-bootstrap';
function Place(props) {
const [reviews, setReviews] = useState([{ title: "", link: "", summery: "", content: "" }])
const [reviews, setReviews] = useState()
const [db, setDb] = useState(false)
const getReview = () => {
axios.get(`/api/review/${props.search.name}`)
axios({ url: `/api/review?keyword=${props.place.name}`, method: 'post', data: { db: db } })
.then(res => {
console.log("place res.data", res.data)
setReviews(res.data)
......@@ -27,12 +28,12 @@ function Place(props) {
aria-labelledby="example-modal-sizes-title-lg">
<Modal.Header closeButton>
<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.Header>
<Modal.Body className="show-grid">
<Container style={{ fontSize: '40px' }}>
{reviews.map((review, index) => {
{Array.isArray(reviews) ? reviews.map((review, index) => {
return (
<Row className="mt-4">
<a href={review.link}>{review.title}</a>
......@@ -40,7 +41,8 @@ function Place(props) {
<div>{review.content}</div>
</Row>
)
})}
})
: "리뷰가 없습니다."}
</Container>
</Modal.Body>
......
......@@ -8,10 +8,7 @@ function App() {
const [search, setSearch] = useState("");
if (state !== false) {
return <Redirect to={{
pathname: `/search/${search}`,
state: { id: search },
}} />;
return <Redirect to={`/search?keyword=${search}`} />;
}
const handleChange = (e) => {
......
......@@ -5,20 +5,20 @@ import Place from '../Components/Place';
import { Container, Form, Row, Col, Card, Image, InputGroup, FormControl, Button} from 'react-bootstrap';
import Paginations from '../Components/Paginations';
import axios from 'axios';
import queryString from 'query-string'
function Search(props) {
const endPage = 10;
const [state, setState] = useState(false);
const [index, setIndex] = useState(1);
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 [place, setPlace] = useState([{ name: "", category: "", address: "" }])
const [imgUrl, setImgUrl] = useState([])
const [association, setAssociation] = useState([])
const getImg = () => {
axios.get(`/api/search/imges/${search}`)
axios.get(`/api/search/imges?keyword=${search}`)
.then(res => {
console.log("images=", res.data)
setImgUrl(res.data)
......@@ -29,7 +29,7 @@ function Search(props) {
}
const getPlace = () => {
axios.get(`/api/search/places/${search}`)
axios.get(`/api/search/places?keyword=${search}`)
.then(res => {
console.log("places=", res.data)
setPlace(res.data)
......@@ -40,7 +40,7 @@ function Search(props) {
}
const getAssociation =() => {
axios.get(`/api/search/association/${search}`)
axios.get(`/api/search/association?keyword=${search}`)
.then(res => {
console.log("Associations = ", res.data)
setAssociation(res.data)
......@@ -93,7 +93,7 @@ function Search(props) {
if (state !== false) {
return <Redirect to={{
pathname: `/search/${search}`,
pathname: `/search?keyword=${search}`,
state: { id: search },
}} />;
}
......
......@@ -13,17 +13,13 @@ import {
Redirect,
} from "react-router-dom";
axios.defaults.validateStatus = function (status) {
return status < 500; // default
}
ReactDOM.render(
<React.StrictMode>
<Router>
<Switch>
<Route exact path="/" component={App} />
<Route path="/search" component={Search} />
<Redirect path="/search/:search" to="/search" />
<Redirect path="/search" to="/search" />
</Switch>
</Router>
</React.StrictMode>,
......
This diff is collapsed.
......@@ -74,15 +74,19 @@ const searchImg = async (req, res) => {
}
const searchAssociation = async (req, res) => {
let Place = await Places.findOne({ name: req.params.search })
let address = Place.address.split(' ')[0]
let Place = await Places.findOne({ name: req.query.keyword })
if (!Place) {
res.send([])
}
let addresse = Place.address.split(' ')[0]
// let AssociationsId = []
let addressPlaces = new RegExp(`${address}`)
let addressPlaces = new RegExp(`${addresse}`)
let responsePlaces = await Places.find({ address: addressPlaces })
res.send(responsePlaces)
// responsePlaces.map(Association => {
// AssociationsId.push(Association._id)
// })
......
import Review from '../models/Review.js'
import cheerio from "cheerio";
import fs from 'fs'
import axios from 'axios';
const search = async (req, res, next) => {
console.log("1")
for (let i = 1; (req.reviews).length > 10; i++) {
try {
console.log("2")
let reviews = []
let content = []
// Review.find()
const url = "https://www.google.com/search?q=" + encodeURI(req.params.search) + "+site%3Atistory.com&page_no=1"
const url = "https://www.google.com/search?q=" + encodeURI(req.query.keyword) + "+site%3Atistory.com&page_no=" + i
const response1 = await axios.get(url)
// console.log(response1.data)
const $1 = cheerio.load(response1.data);
$1('.kCrYT').each(async function (i) {
console.log("3")
const title = $1(this).find('h3').text()
const searchParams = new URLSearchParams($1(this).find('a').attr('href'));
const link = searchParams.get("/url?q")
const summary = $1(this).find('.s3v9rd').find('.s3v9rd').text()
Review.find({ link: link }, function (err, review) {
if (!review) {
content.push(getReview(link))
if (title) {
reviews[i] = { title: title, link: link }
......@@ -24,18 +28,25 @@ const search = async (req, res, next) => {
reviews[i - 1] = { ...reviews[i - 1], summary: summary }
reviews = reviews.filter(e => e)
}
}
})
})
let promiseReview = await Promise.all(content)
promiseReview = promiseReview.filter(e => typeof (e) === 'string')
reviews.forEach(async (review, i) => {
console.log("4")
review["content"] = promiseReview[i]
const reviews = new Review(review).save()
reviews.keyword.push(req.query.keyword)
req.reviews.push(reviews)
})
console.log("5")
res.send(reviews)
} catch (error) {
// console.log(error)
// res.send(error)
console.log("6")
console.log(error)
res.send(error)
}
}
}
......@@ -69,4 +80,18 @@ const getReview = async (link) => {
}
}
export default { search }
\ No newline at end of file
const find = (req, res, next) => {
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'
const router = express.Router()
router.route('/api/search/imges/:search')
router.route('/api/search/imges')
.get(place.searchImg)
router.route('/api/search/places/:search')
router.route('/api/search/places')
.get(place.searchPlace)
router.route('/api/search/association/:search')
router.route('/api/search/association')
.get(place.searchAssociation)
export default router
\ No newline at end of file
......@@ -3,7 +3,7 @@ import review from '../controllers/review.controller.js'
const router = express.Router()
router.route('/api/review/:search')
.get(review.search)
router.route('/api/review')
.post(review.find, review.search)
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