Commit 4a644a64 authored by 박상호's avatar 박상호 🎼
Browse files

Merge remote-tracking branch 'origin/ourMaster' into sangho

parents 332ee410 764c352c
...@@ -159,7 +159,6 @@ function Payment({ match, location }) { ...@@ -159,7 +159,6 @@ function Payment({ match, location }) {
<p>주문하기를 눌러 결제를 이어가주세요.</p> <p>주문하기를 눌러 결제를 이어가주세요.</p>
</div> </div>
) )
// window.location.href = data.redirect_url
// setRedirect(data.redirect_url) // setRedirect(data.redirect_url)
} }
......
...@@ -8,7 +8,8 @@ import { Container, Row, Col, Form, FormControl, Button, Dropdown, ButtonGroup, ...@@ -8,7 +8,8 @@ import { Container, Row, Col, Form, FormControl, Button, Dropdown, ButtonGroup,
function ProductsList({ match }) { function ProductsList({ match }) {
const [search, setSearch] = useState({ word: '' }) const [search, setSearch] = useState({ word: '' })
const [sortingName, setSortingName] = useState('정렬') const [sortingName, setSortingName] = useState('')
const [sortingDisplayName, setSortingDisplayName] = useState('신상품')
const [mainCategory, setMainCategory] = useState(match.params.main.toUpperCase()) const [mainCategory, setMainCategory] = useState(match.params.main.toUpperCase())
const [subCategory, setSubCategory] = useState([]) const [subCategory, setSubCategory] = useState([])
const [selectSubCategory, setSelectSubCategory] = useState('') const [selectSubCategory, setSelectSubCategory] = useState('')
...@@ -23,6 +24,8 @@ function ProductsList({ match }) { ...@@ -23,6 +24,8 @@ function ProductsList({ match }) {
setMainCategory(match.params.main.toUpperCase()) setMainCategory(match.params.main.toUpperCase())
setSelectSubCategory('') setSelectSubCategory('')
setCurrentPage(1) setCurrentPage(1)
setSortingName('')
setSortingDisplayName('신상품')
}, [match.params.main]) }, [match.params.main])
...@@ -31,23 +34,48 @@ function ProductsList({ match }) { ...@@ -31,23 +34,48 @@ function ProductsList({ match }) {
getProductlist() getProductlist()
}, [mainCategory]) }, [mainCategory])
useEffect(() => { // useEffect(() => {
if (search.word == '') { // if (sortingName == '' && search.word == '' && selectSubCategory == '') {
getProductlist() // getProductlist()
} else if (selectSubCategory != '') { // } else if (sortingName == '' && search.word == '') {
changePageforSubname() // changePageforSubname()
} else { // } else if (selectSubCategory == '' && sortingName == '') {
// searchList()
// } else {
// changePageforSorting()
// }
// }, [currentPage])
async function getSubsCategories() {
try {
setError('')
const response = await axios.get(`/api/categories/sub/${mainCategory}`)
setSubCategory(Object.values(response.data)[0])
} catch (error) {
catchError(error, setError)
}
}
async function getProductlist() {
try {
console.log("getProductlist 실행")
setError('')
setSelectSubCategory('') setSelectSubCategory('')
searchList() setSearch({ word: '' })
const response = await axios.get(`/api/product/getproduct/main/${mainCategory}?page=${currentPage}`)
setProductlist(response.data.productsPiece)
setLength(response.data.length)
} catch (error) {
catchError(error, setError)
} }
}, [currentPage]) }
async function searchList() { async function searchList() {
try { try {
console.log("seacrchList 실행")
setError('') setError('')
const response = await axios.get(`/api/product/getproduct/main/${mainCategory}?product=${search.word}&page=${currentPage}`) const response = await axios.get(`/api/product/getproduct/main/${mainCategory}?product=${search.word}&page=${currentPage}`)
setProductlist(response.data.productsPiece) setProductlist(response.data.productsPiece)
setLength(response.data.length)
} catch (error) { } catch (error) {
catchError(error, setError) catchError(error, setError)
} }
...@@ -60,11 +88,11 @@ function ProductsList({ match }) { ...@@ -60,11 +88,11 @@ function ProductsList({ match }) {
async function handleSearch(e) { async function handleSearch(e) {
e.preventDefault() e.preventDefault()
try { try {
console.log("handleSearch 실행")
setError('') setError('')
if (currentPage != 1) { setSelectSubCategory('')
setCurrentPage(1) setCurrentPage(1)
} const response = await axios.get(`/api/product/getproduct/main/${mainCategory}?product=${search.word}&page=1`)
const response = await axios.get(`/api/product/getproduct/main/${mainCategory}?product=${search.word}&page=${currentPage}`)
setProductlist(response.data.productsPiece) setProductlist(response.data.productsPiece)
setLength(response.data.length) setLength(response.data.length)
} catch (error) { } catch (error) {
...@@ -74,70 +102,79 @@ function ProductsList({ match }) { ...@@ -74,70 +102,79 @@ function ProductsList({ match }) {
} }
} }
async function getSubsCategories() { // async function changePageforSorting() {
try { // try {
setError('') // console.log("changePageforSorting 실행")
const response = await axios.get(`/api/categories/sub/${mainCategory}`) // setError('')
setSubCategory(Object.values(response.data)[0]) // if (selectSubCategory != '') {
} catch (error) { // const response = await axios.get(`/api/product/getproduct/sub?subname=${selectSubCategory}&method=${sortingName}&page=${currentPage}`)
catchError(error, setError) // setProductlist(response.data.productsPiece)
} // setLength(response.data.length)
} // setSortingDisplayName()
// } else if (search.word != '') {
// const response = await axios.get(`/api/product/getproduct/main/${mainCategory}?product=${search.word}&method=${sortingName}&page=${currentPage}`)
// setProductlist(response.data.productsPiece)
// } else {
// console.log("else")
// const response = await axios.get(`/api/product/getproduct/main/${mainCategory}?method=${sortingName}&page=${currentPage}`)
// setProductlist(response.data.productsPiece)
// }
// } catch (error) {
// catchError(error, setError)
// }
// }
async function getProductlist() { async function handleSort(method) {
try { try {
console.log("handleSort 실행")
setError('') setError('')
setSearch({ word: '' }) setCurrentPage(1)
const response = await axios.get(`/api/product/getproduct/main/${mainCategory}?page=${currentPage}`) setSortingName(method)
setProductlist(response.data.productsPiece) if (selectSubCategory != '') {
setLength(response.data.length) console.log("selectSubCategory != ''")
const response = await axios.get(`/api/product/getproduct/sub?subname=${selectSubCategory}&method=${method}&page=1`)
setProductlist(response.data.productsPiece)
setSortingDisplayName(response.data.str)
} else if (search.word != '') {
console.log("search.word != ''")
const response = await axios.get(`/api/product/getproduct/main/${mainCategory}?product=${search.word}&method=${method}&page=1`)
setProductlist(response.data.productsPiece)
// setLength(response.data.length)
setSortingDisplayName(response.data.str)
} else {
console.log("else")
const response = await axios.get(`/api/product/getproduct/main/${mainCategory}?method=${method}&page=1`)
setProductlist(response.data.productsPiece)
// setLength(response.data.length)
setSortingDisplayName(response.data.str)
}
} catch (error) { } catch (error) {
catchError(error, setError) catchError(error, setError)
} }
} }
async function handleSort(method) {
// const response = await axios.get(`/api/product/sortingproduct/sub?subname=${}&page=${currentPage}&sorting=${method}`)
if (method === "purchase") {
setSortingName("인기상품")
} else if (method === "newest") {
setSortingName("신상품")
} else if (method === "lowest") {
setSortingName("낮은가격")
} else {
productlist.sort(function (a, b) {
if (a.price > b.price) {
return -1;
}
if (a.price < b.price) {
return 1;
}
return 0;
});
setSortingName("높은가격")
}
}
async function changePageforSubname() { async function changePageforSubname() {
try { try {
console.log("changePageforSubname 실행")
setError('') setError('')
setSearch({ word: '' })
const response = await axios.get(`/api/product/getproduct/sub?subname=${selectSubCategory}&page=${currentPage}`) const response = await axios.get(`/api/product/getproduct/sub?subname=${selectSubCategory}&page=${currentPage}`)
setProductlist(response.data.productsPiece) setProductlist(response.data.productsPiece)
setLength(response.data.length)
} catch (error) { } catch (error) {
catchError(error, setError) catchError(error, setError)
} }
} }
async function handleSubname(e) { async function handleSubname(e) {
console.log("handleSubname 실행")
const subname = e.target.name const subname = e.target.name
setSelectSubCategory(e.target.name) setSelectSubCategory(e.target.name)
try { try {
setError('') setError('')
setSearch({ word: '' }) setSearch({ word: '' })
const response = await axios.get(`/api/product/getproduct/sub?subname=${subname}&page=${currentPage}`) setSortingDisplayName('신상품')
setSortingName('')
setCurrentPage(1)
const response = await axios.get(`/api/product/getproduct/sub?subname=${subname}&page=1`)
setProductlist(response.data.productsPiece) setProductlist(response.data.productsPiece)
setLength(response.data.length) setLength(response.data.length)
} catch (error) { } catch (error) {
...@@ -153,6 +190,7 @@ function ProductsList({ match }) { ...@@ -153,6 +190,7 @@ function ProductsList({ match }) {
return ( return (
<Container> <Container>
{console.log("subCategory=",selectSubCategory,"sortingName=",sortingName,"search=",search.word,"page=",currentPage)}
<style type="text/css"> <style type="text/css">
{` {`
@font-face { @font-face {
...@@ -208,7 +246,7 @@ function ProductsList({ match }) { ...@@ -208,7 +246,7 @@ function ProductsList({ match }) {
</Button> </Button>
</Form> </Form>
<Dropdown className="my-2"> <Dropdown className="my-2">
<Dropdown.Toggle className="mx-1">{sortingName}</Dropdown.Toggle> <Dropdown.Toggle className="mx-1">{sortingDisplayName}</Dropdown.Toggle>
<Dropdown.Menu> <Dropdown.Menu>
<Dropdown.Item as="button" onClick={() => handleSort('purchase')}>인기상품</Dropdown.Item> <Dropdown.Item as="button" onClick={() => handleSort('purchase')}>인기상품</Dropdown.Item>
<Dropdown.Item as="button" onClick={() => handleSort('newest')}>신상품</Dropdown.Item> <Dropdown.Item as="button" onClick={() => handleSort('newest')}>신상품</Dropdown.Item>
...@@ -233,7 +271,7 @@ function ProductsList({ match }) { ...@@ -233,7 +271,7 @@ function ProductsList({ match }) {
detail_imgs: pro.detail_imgUrls detail_imgs: pro.detail_imgUrls
} }
}}> }}>
<ListCard id={pro._id} name={pro.pro_name} price={pro.price} main_img={pro.main_imgUrl} status={'list'}/> <ListCard id={pro._id} name={pro.pro_name} price={pro.price} main_img={pro.main_imgUrl} status={'list'} />
</Link> </Link>
)) ))
: ( : (
......
...@@ -6,13 +6,6 @@ const config = { ...@@ -6,13 +6,6 @@ const config = {
kakaoAdminKey: 'b2dda7685c5b2990684d813e362cff07', kakaoAdminKey: 'b2dda7685c5b2990684d813e362cff07',
cookieMaxAge: 60 * 60 * 24 * 7 * 1000 cookieMaxAge: 60 * 60 * 24 * 7 * 1000
} }
// const config = {
// port: 3001,
// kakaoAdminKey: 'b2dda7685c5b2990684d813e362cff07',
// }
export default config export default config
\ No newline at end of file
// export default config
\ No newline at end of file
...@@ -47,14 +47,14 @@ const getAll = async (req, res) => { ...@@ -47,14 +47,14 @@ const getAll = async (req, res) => {
if (productslist.length == 0) { if (productslist.length == 0) {
res.status(404).send('상품을 찾을 수 없습니다.') res.status(404).send('상품을 찾을 수 없습니다.')
} else { } else {
res.json({productPiece, length}) res.json({ productPiece, length })
} }
} else { } else {
const productslist = await Product.find({}).sort({ createdAt: -1 }) const productslist = await Product.find({}).sort({ createdAt: -1 })
const length = productslist.length const length = productslist.length
const productPiece = await Product.find({}).sort({ createdAt: -1 }).skip((req.query.page - 1) * per).limit(per) const productPiece = await Product.find({}).sort({ createdAt: -1 }).skip((req.query.page - 1) * per).limit(per)
console.log("products=",productPiece) console.log("products=", productPiece)
res.json({productPiece, length}) res.json({ productPiece, length })
} }
} catch (error) { } catch (error) {
res.status(500).send('상품을 불러오지 못했습니다.') res.status(500).send('상품을 불러오지 못했습니다.')
...@@ -63,33 +63,103 @@ const getAll = async (req, res) => { ...@@ -63,33 +63,103 @@ const getAll = async (req, res) => {
const getlist = (req, res) => { const getlist = (req, res) => {
try { try {
const productsPiece = req.productsPiece if (req.str && req.length) {
const length = req.length const str = req.str
res.json({ productsPiece, length }) const productsPiece = req.productsPiece
const length = req.length
res.json({ productsPiece, length, str })
} else if (req.str) {
const str = req.str
const productsPiece = req.productsPiece
res.json({ productsPiece, str })
} else {
const productsPiece = req.productsPiece
const length = req.length
res.json({ productsPiece, length })
}
} catch (error) { } catch (error) {
res.status(500).send('상품을 불러오지 못했습니다.') res.status(500).send('상품을 불러오지 못했습니다.')
} }
} }
const categoryId = async (req, res, next, category) => { const categoryId = async (req, res, next, category) => {
const per = 9; const per = 9;
try { try {
if (req.query.product) { if (req.query.product && req.query.method) {
const productslist = await Product.find({ main_category: category, pro_name: { $regex: new RegExp(req.query.product) } }) let method = ''
const length = productslist.length let methodStr = ''
const productsPiece = await Product.find({ main_category: category, pro_name: { $regex: new RegExp(req.query.product) } }).skip((req.query.page - 1) * per).limit(per) switch (req.query.method) {
if (productslist.length == 0) { case "purchase":
res.status(404).send('상품을 찾을 수 없습니다.') method = "purchase"
methodStr = '인기상품'
break;
case "newest":
method = "createdAt"
methodStr = '신상품'
break;
case "lowest":
method = "price"
methodStr = '낮은가격'
break;
case "highest":
method = "price"
methodStr = '높은가격'
break;
}
req.str = methodStr
if (req.query.method == 'lowest') {
let productslist = await Product.find({ main_category: category, pro_name: { $regex: new RegExp(req.query.product) } }).sort({ [method]: 1 })
let length = productslist.length
req.length = length
let productsPiece = await Product.find({ main_category: category, pro_name: { $regex: new RegExp(req.query.product) } }).sort({ [method]: 1 }).skip((req.query.page - 1) * per).limit(per)
req.productsPiece = productsPiece
} else { } else {
let productslist = await Product.find({ main_category: category, pro_name: { $regex: new RegExp(req.query.product) } }).sort({ [method]: -1 })
let length = productslist.length
req.length = length req.length = length
let productsPiece = await Product.find({ main_category: category, pro_name: { $regex: new RegExp(req.query.product) } }).sort({ [method]: -1 }).skip((req.query.page - 1) * per).limit(per)
req.productsPiece = productsPiece
}
} else if (req.query.method) {
let method = ''
let methodStr = ''
switch (req.query.method) {
case "purchase":
method = "purchase"
methodStr = '인기상품'
break;
case "newest":
method = "createdAt"
methodStr = '신상품'
break;
case "lowest":
method = "price"
methodStr = '낮은가격'
break;
case "highest":
method = "price"
methodStr = '높은가격'
break;
}
req.str = methodStr
if (req.query.method == 'lowest') {
let productsPiece = await Product.find({ main_category: category }).sort({ [method]: 1 }).skip((req.query.page - 1) * per).limit(per)
req.productsPiece = productsPiece
} else {
let productsPiece = await Product.find({ main_category: category }).sort({ [method]: -1 }).skip((req.query.page - 1) * per).limit(per)
req.productsPiece = productsPiece req.productsPiece = productsPiece
} }
} else if (req.query.product) {
const productslist = await Product.find({ main_category: category, pro_name: { $regex: new RegExp(req.query.product) } }).sort({ createdAt: -1 })
const length = productslist.length
req.length = length
const productsPiece = await Product.find({ main_category: category, pro_name: { $regex: new RegExp(req.query.product) } }).sort({ createdAt: -1 }).skip((req.query.page - 1) * per).limit(per)
req.productsPiece = productsPiece
} else { } else {
const productslist = await Product.find({ main_category: category }) const productslist = await Product.find({ main_category: category }).sort({ createdAt: -1 })
const length = productslist.length const length = productslist.length
req.length = length req.length = length
const productsPiece = await Product.find({ main_category: category }).skip((req.query.page - 1) * per).limit(per) const productsPiece = await Product.find({ main_category: category }).sort({ createdAt: -1 }).skip((req.query.page - 1) * per).limit(per)
req.productsPiece = productsPiece req.productsPiece = productsPiece
} }
next() next()
...@@ -98,26 +168,44 @@ const categoryId = async (req, res, next, category) => { ...@@ -98,26 +168,44 @@ const categoryId = async (req, res, next, category) => {
} }
} }
const sortingProduct = async (req,res) =>{
try {
const productslist = await Product.find({ main_category: category })
const length = productslist.length
req.length = length
const productsPiece = await Product.find({ main_category: category }).skip((req.query.page - 1) * per).limit(per)
req.productsPiece = productsPiece
} catch (error) {
}
}
const subname = async (req, res) => { const subname = async (req, res) => {
const per = 9; const per = 9;
try { try {
const productslist = await Product.find({ sub_category: req.query.subname }) if (req.query.method) {
const length = productslist.length let method = ''
const productsPiece = await Product.find({ sub_category: req.query.subname }).skip((req.query.page - 1) * per).limit(per) let methodStr = ''
res.send({ productsPiece, length }) switch (req.query.method) {
case "purchase":
method = "purchase"
methodStr = '인기상품'
break;
case "newest":
method = "createdAt"
methodStr = '신상품'
break;
case "lowest":
method = "price"
methodStr = '낮은가격'
break;
case "highest":
method = "price"
methodStr = '높은가격'
break;
}
let str = methodStr
if (req.query.method == 'lowest') {
let productsPiece = await Product.find({ sub_category: req.query.subname }).sort({ [method]: 1 }).skip((req.query.page - 1) * per).limit(per)
res.send({ productsPiece, str })
} else {
let productsPiece = await Product.find({ sub_category: req.query.subname }).sort({ [method]: -1 }).skip((req.query.page - 1) * per).limit(per)
res.send({ productsPiece, str })
}
} else {
const productslist = await Product.find({ sub_category: req.query.subname }).sort({ createdAt: -1 })
const length = productslist.length
const productsPiece = await Product.find({ sub_category: req.query.subname }).sort({ createdAt: -1 }).skip((req.query.page - 1) * per).limit(per)
res.send({ productsPiece, length })
}
} catch (error) { } catch (error) {
res.status(500).send('상품을 불러오지 못했습니다.') res.status(500).send('상품을 불러오지 못했습니다.')
} }
......
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