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