From 3b1cee1e5cb91751cdd57c7ebf1334f3c9c26095 Mon Sep 17 00:00:00 2001 From: "bggiri@naver.comgit config --global user.name sangjunegit config --global user.name bggiri@naver.com" Date: Wed, 27 Jan 2021 14:16:44 +0900 Subject: [PATCH] =?UTF-8?q?app=EC=9D=B4=EB=9E=91=20=EC=84=9C=EB=B2=84?= =?UTF-8?q?=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/.eslintcache | 2 +- client/src/Components/Place.js | 4 +- client/src/Pages/App.js | 118 +++++++++++++++++++++------ client/src/Pages/Search.js | 2 - server/controllers/app.controller.js | 21 +++++ server/routes/app.router.js | 14 ++++ server/server.js | 2 + 7 files changed, 133 insertions(+), 30 deletions(-) create mode 100644 server/controllers/app.controller.js create mode 100644 server/routes/app.router.js diff --git a/client/.eslintcache b/client/.eslintcache index e7894ae..206866d 100644 --- a/client/.eslintcache +++ b/client/.eslintcache @@ -1 +1 @@ -[{"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":3724,"mtime":1611712847775,"results":"11","hashOfConfig":"8"},{"size":7984,"mtime":1611712273897,"results":"12","hashOfConfig":"8"},{"size":1474,"mtime":1611712360811,"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":8,"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 \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n ,\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 \r\n \r\n \r\n {props.index + 1}. {props.place.name}\r\n \r\n \r\n \r\n \r\n {Array.isArray(reviews) ? reviews.map((review, index) => {\r\n return (\r\n \r\n {review.title}\r\n
{review.summary}
\r\n
{review.content}
\r\n
\r\n )\r\n })\r\n : \"리뷰가 없습니다.\"}\r\n
\r\n\r\n
\r\n \r\n \r\n \r\n
\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","38"],"C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\Pages\\App.js",[],{"ruleId":"39","severity":1,"message":"40","line":7,"column":8,"nodeType":"41","messageId":"42","endLine":7,"endColumn":13},{"ruleId":"39","severity":1,"message":"43","line":7,"column":14,"nodeType":"41","messageId":"42","endLine":7,"endColumn":19},{"ruleId":"44","severity":1,"message":"45","line":21,"column":6,"nodeType":"46","endLine":21,"endColumn":8,"suggestions":"47"},{"ruleId":"39","severity":1,"message":"48","line":2,"column":16,"nodeType":"41","messageId":"42","endLine":2,"endColumn":24},{"ruleId":"39","severity":1,"message":"49","line":16,"column":12,"nodeType":"41","messageId":"42","endLine":16,"endColumn":18},{"ruleId":"44","severity":1,"message":"50","line":44,"column":8,"nodeType":"46","endLine":44,"endColumn":10,"suggestions":"51"},{"ruleId":"44","severity":1,"message":"52","line":57,"column":8,"nodeType":"46","endLine":57,"endColumn":28,"suggestions":"53"},{"ruleId":"44","severity":1,"message":"54","line":67,"column":8,"nodeType":"46","endLine":67,"endColumn":15,"suggestions":"55"},{"ruleId":"39","severity":1,"message":"56","line":70,"column":11,"nodeType":"41","messageId":"42","endLine":70,"endColumn":17},{"ruleId":"39","severity":1,"message":"57","line":135,"column":9,"nodeType":"41","messageId":"42","endLine":135,"endColumn":13},{"ruleId":"58","severity":1,"message":"59","line":140,"column":35,"nodeType":"60","endLine":140,"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",["61"],"'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.",["62"],"React Hook useEffect has missing dependencies: 'endPage' and 'pagePlace'. Either include them or remove the dependency array.",["63"],"React Hook useEffect has missing dependencies: 'getAssociation', 'props.history', and 'search'. Either include them or remove the dependency array.",["64"],"'places' is assigned a value but never used.","'time' is assigned a value but never used.","react/jsx-no-duplicate-props","No duplicate props allowed","JSXAttribute",{"desc":"65","fix":"66"},{"desc":"67","fix":"68"},{"desc":"69","fix":"70"},{"desc":"71","fix":"72"},"Update the dependencies array to be: [getReview]",{"range":"73","text":"74"},"Update the dependencies array to be: [getAssociation]",{"range":"75","text":"76"},"Update the dependencies array to be: [association, endPage, index, pagePlace]",{"range":"77","text":"78"},"Update the dependencies array to be: [getAssociation, props.history, search, state]",{"range":"79","text":"80"},[605,607],"[getReview]",[1573,1575],"[getAssociation]",[1973,1993],"[association, endPage, index, pagePlace]",[2223,2230],"[getAssociation, props.history, search, state]"] \ 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":1624,"mtime":1611724576486,"results":"10","hashOfConfig":"8"},{"size":3724,"mtime":1611712847775,"results":"11","hashOfConfig":"8"},{"size":7890,"mtime":1611722257117,"results":"12","hashOfConfig":"8"},{"size":4169,"mtime":1611724518616,"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":0,"warningCount":7,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"25","messages":"26","errorCount":1,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},"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 \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n ,\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","31","32","33","34","35","36"],"C:\\Users\\노트북펜\\Desktop\\2021YDK\\search-page\\client\\src\\Pages\\App.js",["37"],{"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":44,"column":8,"nodeType":"45","endLine":44,"endColumn":10,"suggestions":"50"},{"ruleId":"43","severity":1,"message":"51","line":65,"column":8,"nodeType":"45","endLine":65,"endColumn":15,"suggestions":"52"},{"ruleId":"38","severity":1,"message":"53","line":68,"column":11,"nodeType":"40","messageId":"41","endLine":68,"endColumn":17},{"ruleId":"38","severity":1,"message":"54","line":133,"column":9,"nodeType":"40","messageId":"41","endLine":133,"endColumn":13},{"ruleId":"55","severity":1,"message":"56","line":138,"column":35,"nodeType":"57","endLine":138,"endColumn":76},{"ruleId":"58","severity":2,"message":"59","line":49,"column":5,"nodeType":"40","endLine":49,"endColumn":14},"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",["60"],"'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.",["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.","'time' is assigned a value but never used.","react/jsx-no-duplicate-props","No duplicate props allowed","JSXAttribute","react-hooks/rules-of-hooks","React Hook \"useEffect\" is called conditionally. React Hooks must be called in the exact same order in every component render. Did you accidentally call a React Hook after an early return?",{"desc":"63","fix":"64"},{"desc":"65","fix":"66"},{"desc":"67","fix":"68"},"Update the dependencies array to be: [getReview]",{"range":"69","text":"70"},"Update the dependencies array to be: [getAssociation]",{"range":"71","text":"72"},"Update the dependencies array to be: [getAssociation, props.history, search, state]",{"range":"73","text":"74"},[605,607],"[getReview]",[1573,1575],"[getAssociation]",[2133,2140],"[getAssociation, props.history, search, state]"] \ No newline at end of file diff --git a/client/src/Components/Place.js b/client/src/Components/Place.js index f5c5b10..86c7f6e 100644 --- a/client/src/Components/Place.js +++ b/client/src/Components/Place.js @@ -28,12 +28,12 @@ function Place(props) { aria-labelledby="example-modal-sizes-title-lg"> - {props.index + 1}. {props.place.name} + {props.place.name} - {Array.isArray(reviews) ? reviews.map((review, index) => { + {Array.isArray(reviews) ? reviews.map((review) => { return ( {review.title} diff --git a/client/src/Pages/App.js b/client/src/Pages/App.js index c60d32d..7a70ebc 100644 --- a/client/src/Pages/App.js +++ b/client/src/Pages/App.js @@ -1,16 +1,22 @@ -import React, { useState } from 'react'; +import React, { useState, useEffect } from 'react'; import { Redirect } from 'react-router-dom'; import ohuh from '../ohuh.PNG'; -import { Container, Row, Form, Image, InputGroup, Button, Col } from 'react-bootstrap'; +import { Container, Row, Form, Image, InputGroup, Button, Col, Card } from 'react-bootstrap'; +import axios from 'axios'; +import Place from '../Components/Place'; function App() { const [state, setState] = useState(false); const [search, setSearch] = useState(""); + const [show, setShow] = useState(false); + const [recommend, setRecommend] = useState([{ name: " ", address: " ", img: " " }]); + const [latest, setLatest] = useState([{ name: " ", address: " ", img: " " }]); if (state !== false) { return ; } + const handleChange = (e) => { setSearch(e.target.value); } @@ -19,30 +25,92 @@ function App() { setState(true); } + const getRecommend = () => { + axios.get(`/api/app/recommend`) + .then(res => { + setRecommend(res.data) + }) + .catch(err => { + console.log("APP RECOMMEND ERROR", err) + }) + } + + const getLatest = () => { + axios.get(`/api/app/lastest`) + .then(res => { + setLatest(res.data) + }) + .catch(err => { + console.log("APP LATEST ERROR", err) + }) + } + + + useEffect(() => { + getRecommend() + getLatest() + }, []); + return ( - - - - - - -
- - - - - - -
-
- -
+ <> + + + + + + +
+ + + + + + +
+
+ + +

인기관광지

+ + {recommend.name} + + + + {recommend.address} + + setShow(false)} /> + + + + + +

최근 검색관광지

+ + {latest.name} + + + + {latest.address} + + setShow(false)} /> + + + +
+ +
+ + ); } diff --git a/client/src/Pages/Search.js b/client/src/Pages/Search.js index de527f9..b1a59d9 100644 --- a/client/src/Pages/Search.js +++ b/client/src/Pages/Search.js @@ -50,9 +50,7 @@ function Search(props) { else { setPagePlace(paginate(association, index, 4)) } - console.log("뿌릴 data1", pagePlace) setEndPage(Math.floor((association.length / 4))) - console.log("7489309484839",endPage) }, [association, index]) diff --git a/server/controllers/app.controller.js b/server/controllers/app.controller.js new file mode 100644 index 0000000..562a535 --- /dev/null +++ b/server/controllers/app.controller.js @@ -0,0 +1,21 @@ +import Places from '../models/Place.js' +import cheerio from 'cheerio' +import axios from 'axios'; + +const searchRecommend = async (req, res, next,) => { +let responseRecommend = await Places.find({}).sort({updatedAt:-1}) +res.send(responseRecommend[0]) + + +} + +const searchLatest = async (req, res, next) => { + + let responseLatest = await Places.find({}) + + res.send(responseLatest[0]) + + +} + +export default { searchRecommend, searchLatest } diff --git a/server/routes/app.router.js b/server/routes/app.router.js new file mode 100644 index 0000000..72cd9fc --- /dev/null +++ b/server/routes/app.router.js @@ -0,0 +1,14 @@ +import express from 'express' +import app from '../controllers/app.controller.js' + +const router = express.Router() + + + +router.route('/api/app/recommend') + .get(app.searchRecommend) + +router.route('/api/app/latest') + .get(app.searchLatest) + +export default router \ No newline at end of file diff --git a/server/server.js b/server/server.js index caa72cf..b77d40d 100644 --- a/server/server.js +++ b/server/server.js @@ -2,6 +2,7 @@ import express from 'express' import connectDb from './utils/connectDb.js' import placeRouter from './routes/place.routes.js' import reviewRouter from './routes/review.routes.js' +import appRouter from './routes/app.router.js' connectDb() @@ -11,6 +12,7 @@ app.use(express.json()) app.use(placeRouter) app.use(reviewRouter) +app.use(appRouter) app.get('/', (req, res) => { console.log("/ req.body", req.body) -- GitLab