Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
shopping-mall
Commits
cfcaaab5
Commit
cfcaaab5
authored
Feb 01, 2021
by
Kim, Subin
Browse files
1차 수정
parent
d9744453
Changes
3
Show whitespace changes
Inline
Side-by-side
client/src/Pages/Payment.js
View file @
cfcaaab5
...
...
@@ -159,7 +159,6 @@ function Payment({ match, location }) {
<
p
>
주문하기를
눌러
결제를
이어가주세요
.
<
/p
>
<
/div
>
)
// window.location.href = data.redirect_url
// setRedirect(data.redirect_url)
}
...
...
@@ -211,6 +210,7 @@ function Payment({ match, location }) {
})
})
const
data
=
await
response
.
json
()
window
.
location
.
href
=
data
.
redirect_url
}
else
{
console
.
log
(
response
.
data
)
console
.
log
(
response2
.
data
)
...
...
client/src/Pages/ProductsList.js
View file @
cfcaaab5
...
...
@@ -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,95 +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
)
{
if
(
method
===
"
purchase
"
)
{
productlist
.
sort
(
function
(
a
,
b
)
{
if
(
a
.
purchase
>
b
.
purchase
)
{
return
-
1
;
}
if
(
a
.
purchase
<
b
.
purchase
)
{
return
1
;
}
return
0
;
});
setSortingName
(
"
인기상품
"
)
}
else
if
(
method
===
"
newest
"
)
{
productlist
.
sort
(
function
(
a
,
b
)
{
if
(
a
.
createdAt
>
b
.
createdAt
)
{
return
-
1
;
}
if
(
a
.
createdAt
<
b
.
createdAt
)
{
return
1
;
}
return
0
;
});
setSortingName
(
"
신상품
"
)
}
else
if
(
method
===
"
lowest
"
)
{
productlist
.
sort
(
function
(
a
,
b
)
{
if
(
a
.
price
>
b
.
price
)
{
return
1
;
}
if
(
a
.
price
<
b
.
price
)
{
return
-
1
;
}
return
0
;
});
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
)
{
...
...
@@ -178,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 {
...
...
@@ -233,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
"
>
{
sorting
Display
Name
}
<
/Dropdown.Toggle
>
<
Dropdown
.
Menu
>
<
Dropdown
.
Item
as
=
"
button
"
onClick
=
{()
=>
handleSort
(
'
purchase
'
)}
>
인기상품
<
/Dropdown.Item
>
<
Dropdown
.
Item
as
=
"
button
"
onClick
=
{()
=>
handleSort
(
'
newest
'
)}
>
신상품
<
/Dropdown.Item
>
...
...
@@ -258,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
>
))
:
(
...
...
server/controllers/product.controller.js
View file @
cfcaaab5
...
...
@@ -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,33 +63,103 @@ 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
}
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
}).
sort
({
createdAt
:
-
1
}).
skip
((
req
.
query
.
page
-
1
)
*
per
).
limit
(
per
)
req
.
productsPiece
=
productsPiece
}
next
()
...
...
@@ -101,10 +171,41 @@ const categoryId = async (req, res, next, category) => {
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
(
'
상품을 불러오지 못했습니다.
'
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment