Commit 52aff595 authored by Lee SeoYeon's avatar Lee SeoYeon
Browse files

..

parent f81deda0
import Places from '../models/Place.js'
import cheerio from 'cheerio'
import fs from 'fs'
// import fs from 'fs'
import axios from 'axios';
const searchPlace = async (req, res) => {
......@@ -37,20 +37,14 @@ const searchImg = async (req, res) => {
let DuplicateCheckImg = await Places.findOne({ name: req.query.keyword })
if (DuplicateCheckImg.img !== "https://t1.daumcdn.net/thumb/R600x0/?fname=http%3A%2F%2Ft1.daumcdn.net%2Fqna%2Fimage%2F4b035cdf8372d67108f7e8d339660479dfb41bbd") {
res.send(DuplicateCheckImg)
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")
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);
if (DuplicateCheckImg) {
if (DuplicateCheckImg.img !== "https://t1.daumcdn.net/thumb/R600x0/?fname=http%3A%2F%2Ft1.daumcdn.net%2Fqna%2Fimage%2F4b035cdf8372d67108f7e8d339660479dfb41bbd") {
res.send(DuplicateCheckImg)
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")
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) => {
......@@ -58,15 +52,19 @@ const searchImg = async (req, res) => {
let name = req.query.keyword
let $1 = cheerio.load(html);
//사진만 업데이트
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 })
res.send(images)
})
let images = $1('.RAyV4b').find('img').attr('src')
} else {
console.log("IMG에러")
//사진만 업데이트
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 })
res.send(images)
})
} else {
console.log("IMG에러")
}
}
......@@ -79,12 +77,11 @@ const searchAssociation = async (req, res) => {
// if (!Place) {
// res.send([])
// }
let addresse = Place.address.split(' ')[0]
let AssociationsId = []
let addressPlaces = new RegExp(`${addresse}`)
let responsePlaces = await Places.find({ address: addressPlaces })
res.send(responsePlaces)
if (!Place) {
res.status(404).send({ error: "Place.address is null" })
}
else {
let addresse = Place.address.split(' ')[0]
let AssociationsId = []
let addressPlaces = new RegExp(`${addresse}`)
......
......@@ -46,6 +46,24 @@ const userById = async (req, res, next, id) => {
}
}
const getBookmark = async (req, res) => {
const {page, userId} = req.body
req.body = page
console.log('page:', page)
req.user = userId
console.log('userId:',userId)
await User.updateOne({'userId': userId}, {'bookmark': page})
const updatedUser = await user.save()
res.json(updatedUser)
}
// const putBookmark = async (req, res) => {
// const newBookmark = new Bookmark ({
// bookmark,
// }).save()
// console.log(newBookmark)
// res.json(newBookmark)
// }
// const bookMark = async (req, res) => {
// const {title, url} = req.body
// console.log(title, url)
......@@ -60,4 +78,4 @@ const userById = async (req, res, next, id) => {
// }
// }
export default { signup, userById}
\ No newline at end of file
export default { signup, userById, getBookmark}
\ No newline at end of file
import express from 'express'
import review from '. ./controllers/review.controller.js'
import review from '../controllers/review.controller.js'
const router = express.Router()
......
import express from "express"
import userCtrl from "../controllers/user.controller.js"
import userCtrl from '../controllers/user.controller.js'
const router = express.Router()
router.route('/api/users/signup')
.post(userCtrl.signup)
router.route('/api/users/bookmark')
.post(userCtrl.getBookmark)
// .get(userCtrl.putBookmark)
router.param('userId', userCtrl.userById)
// router.route('/api/users/bookmark')
......
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