Commit b6553221 authored by baesangjune's avatar baesangjune
Browse files

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

parents ba331eac 88f3c62b
[{"C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\Pages\\Bookmark.js":"1","C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\Pages\\Place.js":"2","C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\Pages\\Search.js":"3","C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\Pages\\App.js":"4","C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\Components\\Signup.js":"5","C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\Components\\Paginations.js":"6","C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\index.js":"7","C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\Components\\PrivateRoute.js":"8","C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\utils\\auth.js":"9","C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\utils\\catchErrors.js":"10","C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\Components\\Login.js":"11"},{"size":5982,"mtime":1612290009949,"results":"12","hashOfConfig":"13"},{"size":6513,"mtime":1612273971390,"results":"14","hashOfConfig":"13"},{"size":6651,"mtime":1612290039098,"results":"15","hashOfConfig":"13"},{"size":7387,"mtime":1612290029578,"results":"16","hashOfConfig":"13"},{"size":2959,"mtime":1612275114296,"results":"17","hashOfConfig":"13"},{"size":4208,"mtime":1612282364720,"results":"18","hashOfConfig":"13"},{"size":1345,"mtime":1612156521448,"results":"19","hashOfConfig":"13"},{"size":438,"mtime":1612133560394,"results":"20","hashOfConfig":"13"},{"size":766,"mtime":1612140214129,"results":"21","hashOfConfig":"13"},{"size":405,"mtime":1612133560400,"results":"22","hashOfConfig":"13"},{"size":3150,"mtime":1612140232971,"results":"23","hashOfConfig":"13"},{"filePath":"24","messages":"25","errorCount":0,"warningCount":2,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},"13y9yvi",{"filePath":"26","messages":"27","errorCount":1,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"28","messages":"29","errorCount":0,"warningCount":3,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"30","messages":"31","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"32","messages":"33","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"34"},{"filePath":"35","messages":"36","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"37","messages":"38","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"39","messages":"40","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"41","messages":"42","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"43","messages":"44","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"45","messages":"46","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\Pages\\Bookmark.js",["47","48"],"C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\Pages\\Place.js",["49"],"C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\Pages\\Search.js",["50","51","52"],"C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\Pages\\App.js",[],"C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\Components\\Signup.js",[],["53","54"],"C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\Components\\Paginations.js",[],"C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\index.js",[],"C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\Components\\PrivateRoute.js",[],"C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\utils\\auth.js",[],"C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\utils\\catchErrors.js",[],"C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\Components\\Login.js",[],{"ruleId":"55","severity":1,"message":"56","line":26,"column":19,"nodeType":"57","messageId":"58","endLine":26,"endColumn":30},{"ruleId":"59","severity":1,"message":"60","line":77,"column":8,"nodeType":"61","endLine":77,"endColumn":10,"suggestions":"62"},{"ruleId":null,"fatal":true,"severity":2,"message":"63","line":4,"column":2},{"ruleId":"55","severity":1,"message":"64","line":23,"column":12,"nodeType":"57","messageId":"58","endLine":23,"endColumn":17},{"ruleId":"59","severity":1,"message":"65","line":58,"column":8,"nodeType":"61","endLine":58,"endColumn":15,"suggestions":"66"},{"ruleId":"67","severity":1,"message":"68","line":107,"column":35,"nodeType":"69","endLine":107,"endColumn":76},{"ruleId":"70","replacedBy":"71"},{"ruleId":"72","replacedBy":"73"},"no-unused-vars","'bookmarkArr' is assigned a value but never used.","Identifier","unusedVar","react-hooks/exhaustive-deps","React Hook useEffect has a missing dependency: 'getBookmark'. Either include it or remove the dependency array.","ArrayExpression",["74"],"Parsing error: Unexpected token\n\n 2 | import axios from 'axios';\n 3 | import React, { useEffect, useState } from 'react';\n> 4 | <<<<<<< HEAD\n | ^\n 5 | import { Container, Image } from 'react-bootstrap';\n 6 | import queryString from 'query-string'\n 7 | import ohuh from '../ohuh-sm.PNG';","'error' is assigned a value but never used.","React Hook useEffect has missing dependencies: 'getAssociation', 'getBookmark', 'props.history', and 'search'. Either include them or remove the dependency array.",["75"],"react/jsx-no-duplicate-props","No duplicate props allowed","JSXAttribute","no-native-reassign",["76"],"no-negated-in-lhs",["77"],{"desc":"78","fix":"79"},{"desc":"80","fix":"81"},"no-global-assign","no-unsafe-negation","Update the dependencies array to be: [getBookmark]",{"range":"82","text":"83"},"Update the dependencies array to be: [getAssociation, getBookmark, props.history, search, state]",{"range":"84","text":"85"},[2593,2595],"[getBookmark]",[2100,2107],"[getAssociation, getBookmark, props.history, search, state]"] [{"C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\Pages\\Search.js":"1"},{"size":6738,"mtime":1612290129913,"results":"2","hashOfConfig":"3"},{"filePath":"4","messages":"5","errorCount":1,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},"13y9yvi","C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\Pages\\Search.js",["6"],{"ruleId":null,"fatal":true,"severity":2,"message":"7","line":86,"column":2},"Parsing error: Unexpected token\n\n 84 | const include = bookmark.findIndex(i => i.name === place.name) !== -1\n 85 | if (!include) {\n> 86 | <<<<<<< HEAD\n | ^\n 87 | =======\n 88 | console.log(pagePlace[index])\n 89 | >>>>>>> origin/cherry"]
\ No newline at end of file \ No newline at end of file
/*global kakao*/ /*global kakao*/
import axios from 'axios'; import axios from 'axios';
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { Container, Row, Image } from 'react-bootstrap'; import { Container, Row, Image, Col } from 'react-bootstrap';
import queryString from 'query-string' import queryString from 'query-string'
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import ohuh from '../ohuh-sm.PNG'; import ohuh from '../ohuh-sm.PNG';
import catchErrors from '../utils/catchErrors';
function Place(props) { function Place(props) {
console.log(props) const [error, setError] = useState('')
const [db, setDb] = useState(false) const [review, setReviews] = useState({ reviews: [], db: false, index: 0 })
const [index, setIndex] = useState(0) const { name, src, address } = queryString.parse(props.location.search)
const [reviews, setReviews] = useState([]) console.log(review)
const place = queryString.parse(props.location.search).place
const getReview = async () => {
const getReview = (index) => { try {
console.log(index, "dlseprtm") setError('')
axios({ url: `/api/review?keyword=${place}&index=${index}`, method: 'post', data: { db: db } }) const res = await axios({ url: `/api/review?keyword=${name}&index=${review.index}`, method: 'post', data: { db: review.db } })
.then(res => { console.log("place res.data", res.data)
console.log("place res.data", res.data) setReviews({ reviews: [...review.reviews, ...res.data.review], db: res.data.db, index: res.data.index })
setReviews([...reviews, ...res.data.review]) } catch (error) {
setDb(res.data.db) catchErrors(error, setError)
setIndex(res.data.index) }
})
.then(() => {
console.log(index, "인텍스", db)
})
.catch(err => {
console.log(err)
})
} }
useEffect(() => {
// const script = document.createElement("script");
// script.async = true;
// script.src =
// "https://dapi.kakao.com/v2/maps/sdk.js?appkey=908d6cabedae3bbac126305e53137d0d&autoload=false";
// document.head.appendChild(script);
// script.onload = () => {
// kakao.maps.load(() => {
// let container = document.getElementById("Mymap");
// let options = {
// center: new kakao.maps.LatLng(37.506502, 127.053617),
// level: 7
// };
// const map = new window.kakao.maps.Map(container, options);
// }); useEffect(() => {
// }
getReview(); getReview();
window.addEventListener("scroll", infiniteScroll);
return () => { window.removeEventListener("scroll", infiniteScroll); }
}, []); }, []);
// useEffect(() => {
// getReview();
// }, [index])
const infiniteScroll = () => {
const { documentElement, body } = document;
const scrollHeight = Math.max(documentElement.scrollHeight, body.scrollHeight);
const scrollTop = Math.max(documentElement.scrollTop, body.scrollTop);
const clientHeight = documentElement.clientHeight;
if (scrollTop + clientHeight >= scrollHeight) {
// setIndex(index + 1)
getReview(index + 1);
console.log("더불러", index + 1)
}
console.log(scrollHeight, scrollTop, clientHeight)
}
return ( return (
<Container> <Container>
<Link to="/" >
<Image style={{ margin: "1%" }} src={ohuh} /> <Link to="/"><Image style={{ margin: "1%" }} src={ohuh} /></Link>
</Link>
<div class="d-flex align-items-center p-3 my-3 text-white bg-info rounded shadow-sm"> <div class="d-flex align-items-center p-3 my-3 text-white bg-info rounded shadow-sm">
<h1 class="h6 mb-0 text-white">{place}</h1> <h1 class="h6 mb-0 text-white">{name}</h1>
</div> </div>
<div class="my-3 p-3 bg-white rounded shadow-sm"> <div class="my-3 p-3 bg-white rounded shadow-sm">
<h6 class="border-bottom pb-2 mb-0">관광지 정보</h6> <h6 class="border-bottom pb-2 mb-0">관광지 정보</h6>
{/* <MapContents id="Mymap"></MapContents> */} <Row>
{/* <div class="d-flex text-muted pt-3"> <Col>
<Image variant="top" style={{ padding: "5%", width: "100%", height: "340px" }} src={src} />
<p class="pb-3 mb-0 small lh-sm border-bottom"> </Col>
<strong class="d-block text-gray-dark">@username</strong> <Col>
Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. <div class="d-flex text-muted pt-3">
</p> <p class="pb-3 mb-0 lh-sm border-bottom">
</div> <strong class="d-block text-gray-dark">관광지 이름</strong>
<div class="d-flex text-muted pt-3"> {name}
<svg class="bd-placeholder-img flex-shrink-0 me-2 rounded" width="32" height="32" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Placeholder: 32x32" preserveAspectRatio="xMidYMid slice" focusable="false"><title>Placeholder</title><rect width="100%" height="100%" fill="#e83e8c" /><text x="50%" y="50%" fill="#e83e8c" dy=".3em">32x32</text></svg> </p>
</div>
<div class="d-flex text-muted pt-3">
<p class="pb-3 mb-0 small lh-sm border-bottom"> <p class="pb-3 mb-0 lh-sm border-bottom">
<strong class="d-block text-gray-dark">@username</strong> <strong class="d-block text-gray-dark">관광지 주소</strong>
Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. {address}
</p> </p>
</div> </div>
<div class="d-flex text-muted pt-3"> </Col>
<svg class="bd-placeholder-img flex-shrink-0 me-2 rounded" width="32" height="32" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Placeholder: 32x32" preserveAspectRatio="xMidYMid slice" focusable="false"><title>Placeholder</title><rect width="100%" height="100%" fill="#6f42c1" /><text x="50%" y="50%" fill="#6f42c1" dy=".3em">32x32</text></svg> </Row>
<p class="pb-3 mb-0 small lh-sm border-bottom">
<strong class="d-block text-gray-dark">@username</strong>
Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.
</p>
</div> */}
<small class="d-block text-end mt-3"> <small class="d-block text-end mt-3">
<a href={`https://www.google.com/search?q=${place}&tbm=isch`}>사진 더보러가기</a> <a href={`https://www.google.com/search?q=${name}&tbm=isch`}>사진 더보러가기</a>
</small> </small>
</div> </div>
<div class="my-3 p-3 bg-white rounded shadow-sm"> <div class="my-3 p-3 bg-white rounded shadow-sm">
<h6 class="border-bottom pb-2 mb-0">관광지 후기</h6> <h6 class="border-bottom pb-2 mb-0">관광지 후기</h6>
{Array.isArray(reviews) ? reviews.map((review, index) => { {Array.isArray(review.reviews) ? review.reviews.map((review) => {
return ( return (
<div class="d-flex text-muted pt-3"> <div class="d-flex text-muted pt-3">
<div class="pb-3 mb-0 small lh-sm border-bottom w-100"> <div class="pb-3 mb-0 small lh-sm border-bottom w-100">
...@@ -130,25 +84,12 @@ function Place(props) { ...@@ -130,25 +84,12 @@ function Place(props) {
: "리뷰가 없습니다."} : "리뷰가 없습니다."}
<small class="d-block text-end mt-3"> <small class="d-block text-end mt-3">
<a href="#">리뷰 더보기</a> <a href="#" onClick={getReview} >리뷰 더보기</a>
</small> </small>
</div> </div>
</Container> </Container>
// <Container {...props}>
// {place}
// {Array.isArray(reviews) ? reviews.map((review, index) => {
// return (
// <Row className="mt-4">
// <a href={review.link}>{review.title}</a>
// <div>{review.summary}</div>
// <div>{review.content}</div>
// </Row>
// )
// })
// : "리뷰가 없습니다."}
// </Container>
); );
} }
......
...@@ -12,7 +12,6 @@ import _ from 'lodash'; ...@@ -12,7 +12,6 @@ import _ from 'lodash';
function Search(props) { function Search(props) {
const [state, setState] = useState(false); const [state, setState] = useState(false);
const [index, setIndex] = useState(1); const [index, setIndex] = useState(1);
const [search, setSearch] = useState(queryString.parse(props.location.search).keyword); const [search, setSearch] = useState(queryString.parse(props.location.search).keyword);
......
...@@ -2,66 +2,53 @@ import Review from '../models/Review.js' ...@@ -2,66 +2,53 @@ import Review from '../models/Review.js'
import cheerio from "cheerio"; import cheerio from "cheerio";
import axios from 'axios'; import axios from 'axios';
const search = async (req, res) => { const search = async (req, res, next) => {
try { let DuplicateCheckReview = []
let reviews = [] if (!req.body.db) { DuplicateCheckReview = await Review.find({ keyword: req.query.keyword }) }
console.log(req.reviews, "제발") if (!req.body.db && DuplicateCheckReview !== []) {
req.review = DuplicateCheckReview
} else {
let url = "https://www.google.com/search?q=" + encodeURI(req.query.keyword) + `+site%3Atistory.com&start=${Number(req.query.index) * 10}` try {
console.log(url) let reviews = []
let response1 = await axios.get(url) let url = "https://www.google.com/search?q=" + encodeURI(req.query.keyword) + `+site%3Atistory.com&start=${Number(req.query.index) * 10}`
let $1 = cheerio.load(response1.data); console.log(url)
$1('.kCrYT').each(async function (i) { let response1 = await axios.get(url)
console.log("3") let $1 = cheerio.load(response1.data);
let title = $1(this).find('h3').text() $1('.kCrYT').each(async function (i) {
let searchParams = new URLSearchParams($1(this).find('a').attr('href')); let title = $1(this).find('h3').text()
let link = searchParams.get("/url?q") let searchParams = new URLSearchParams($1(this).find('a').attr('href'));
let summary = $1(this).find('.s3v9rd').find('.s3v9rd').text() let link = searchParams.get("/url?q")
if (title) { let summary = $1(this).find('.s3v9rd').find('.s3v9rd').text()
reviews[i] = { title: title, link: link } if (title) {
} else if (summary) { reviews[i] = { title: title, link: link, keyword: [req.query.keyword] }
reviews[i - 1] = { ...reviews[i - 1], summary: summary } } else if (summary) {
reviews = reviews.filter(e => e) reviews[i - 1] = { ...reviews[i - 1], summary: summary }
} reviews = reviews.filter(e => e)
}) }
// reviews.forEach(async (review, i) => { })
// await Review.updateOne({ link: review.link }, { $push: { bookmark: req.query.keyword } }) req.review = reviews
// const reviewss = await Review.findOne({ link: review.link }) } catch (error) {
// if (!reviewss) { console.log("6")
// // reviews["keyword"] = [req.query.keyword] console.log(error)
let newReviews = [] }
newReviews = [...newReviews, ...reviews]
// await new Review(review).save()
// }
// })
// console.log(req.reviews, "걸러낸 리뷰즈입니다")
// const a = await Promise.all(newReviews)
// console.log(a, "2")
console.log(req.query.index, "인덱스ㅡㅡ")
res.status(200).send({ review: newReviews, db: true, index: Number(req.query.index) + 1 })
} catch (error) {
console.log("6")
console.log(error)
} }
next()
} }
const save = async (req, res) => {
const find = async(req, res, next) => { req.review.forEach(async (reviews, i) => {
console.log("7", req.query) const review = await Review.findOne({ link: reviews.link })
const keyword = req.query.keyword if (review) {
if (req.body.db) { await Review.updateOne({ link: reviews.link }, { $push: { bookmark: req.query.keyword } })
next() req.review[i] = ""
} }
await Review.find({ keyword: keyword }, function (err, reviews) { else {
req.reviews = [] await new Review(reviews).save()
if (reviews) {
if (reviews.length > 5) {
res.status(200).send({ review: reviews, db: true, message: "제발용" })
}
req.reviews = reviews
} }
next()
}) })
console.log(req.review.length)
req.review = req.review.filter(e => e)
console.log(req.review.length)
res.status(200).send({ review: req.review, db: true, index: Number(req.query.index) + 1 })
} }
export default { search, find } export default { search, save }
...@@ -48,7 +48,6 @@ const userById = async (req, res, next, id) => { ...@@ -48,7 +48,6 @@ const userById = async (req, res, next, id) => {
const getBookmark = async (req, res) => { const getBookmark = async (req, res) => {
await User.findOne({ _id: req.query.ID }).populate('bookmark').exec((err, bookmark) => { await User.findOne({ _id: req.query.ID }).populate('bookmark').exec((err, bookmark) => {
console.log(bookmark, "dkssud")
res.send(bookmark) res.send(bookmark)
}) })
} }
......
...@@ -4,6 +4,6 @@ import review from '../controllers/review.controller.js' ...@@ -4,6 +4,6 @@ import review from '../controllers/review.controller.js'
const router = express.Router() const router = express.Router()
router.route('/api/review') router.route('/api/review')
.post(review.find, review.search) .post(review.search, review.save)
export default router 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