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
25eac458
Commit
25eac458
authored
Feb 02, 2021
by
Kim, Subin
Browse files
정렬 알고리즘 완료
parent
071ec763
Changes
2
Show whitespace changes
Inline
Side-by-side
client/src/Pages/ProductsList.js
View file @
25eac458
...
@@ -34,17 +34,9 @@ function ProductsList({ match }) {
...
@@ -34,17 +34,9 @@ function ProductsList({ match }) {
getProductlist
()
getProductlist
()
},
[
mainCategory
])
},
[
mainCategory
])
// useEffect(() => {
useEffect
(()
=>
{
// if (sortingName == '' && search.word == '' && selectSubCategory == '') {
changePage
()
// getProductlist()
},
[
currentPage
])
// } else if (sortingName == '' && search.word == '') {
// changePageforSubname()
// } else if (selectSubCategory == '' && sortingName == '') {
// searchList()
// } else {
// changePageforSorting()
// }
// }, [currentPage])
async
function
getSubsCategories
()
{
async
function
getSubsCategories
()
{
try
{
try
{
...
@@ -58,9 +50,10 @@ function ProductsList({ match }) {
...
@@ -58,9 +50,10 @@ function ProductsList({ match }) {
async
function
getProductlist
()
{
async
function
getProductlist
()
{
try
{
try
{
console
.
log
(
"
getProductlist 실행
"
)
setError
(
''
)
setError
(
''
)
setSelectSubCategory
(
''
)
setSelectSubCategory
(
''
)
setSortingName
(
''
)
setSortingDisplayName
(
'
신상품
'
)
setSearch
({
word
:
''
})
setSearch
({
word
:
''
})
const
response
=
await
axios
.
get
(
`/api/product/getproduct/main/
${
mainCategory
}
?page=
${
currentPage
}
`
)
const
response
=
await
axios
.
get
(
`/api/product/getproduct/main/
${
mainCategory
}
?page=
${
currentPage
}
`
)
setProductlist
(
response
.
data
.
productsPiece
)
setProductlist
(
response
.
data
.
productsPiece
)
...
@@ -70,17 +63,6 @@ function ProductsList({ match }) {
...
@@ -70,17 +63,6 @@ function ProductsList({ match }) {
}
}
}
}
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
)
}
catch
(
error
)
{
catchError
(
error
,
setError
)
}
}
function
handleChange
(
event
)
{
function
handleChange
(
event
)
{
setSearch
({
word
:
event
.
target
.
value
})
setSearch
({
word
:
event
.
target
.
value
})
}
}
...
@@ -88,9 +70,10 @@ function ProductsList({ match }) {
...
@@ -88,9 +70,10 @@ function ProductsList({ match }) {
async
function
handleSearch
(
e
)
{
async
function
handleSearch
(
e
)
{
e
.
preventDefault
()
e
.
preventDefault
()
try
{
try
{
console
.
log
(
"
handleSearch 실행
"
)
setError
(
''
)
setError
(
''
)
setSelectSubCategory
(
''
)
setSelectSubCategory
(
''
)
setSortingName
(
''
)
setSortingDisplayName
(
'
신상품
'
)
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=1`
)
setProductlist
(
response
.
data
.
productsPiece
)
setProductlist
(
response
.
data
.
productsPiece
)
...
@@ -102,50 +85,22 @@ function ProductsList({ match }) {
...
@@ -102,50 +85,22 @@ function ProductsList({ match }) {
}
}
}
}
// 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
handleSort
(
method
)
{
async
function
handleSort
(
method
)
{
try
{
try
{
console
.
log
(
"
handleSort 실행
"
)
setError
(
''
)
setError
(
''
)
setCurrentPage
(
1
)
setCurrentPage
(
1
)
setSortingName
(
method
)
setSortingName
(
method
)
if
(
selectSubCategory
!=
''
)
{
if
(
selectSubCategory
!=
''
)
{
console
.
log
(
"
selectSubCategory != ''
"
)
const
response
=
await
axios
.
get
(
`/api/product/getproduct/sub?subname=
${
selectSubCategory
}
&method=
${
method
}
&page=1`
)
const
response
=
await
axios
.
get
(
`/api/product/getproduct/sub?subname=
${
selectSubCategory
}
&method=
${
method
}
&page=1`
)
setProductlist
(
response
.
data
.
productsPiece
)
setProductlist
(
response
.
data
.
productsPiece
)
setSortingDisplayName
(
response
.
data
.
str
)
setSortingDisplayName
(
response
.
data
.
str
)
}
else
if
(
search
.
word
!=
''
)
{
}
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`
)
const
response
=
await
axios
.
get
(
`/api/product/getproduct/main/
${
mainCategory
}
?product=
${
search
.
word
}
&method=
${
method
}
&page=1`
)
setProductlist
(
response
.
data
.
productsPiece
)
setProductlist
(
response
.
data
.
productsPiece
)
// setLength(response.data.length)
setSortingDisplayName
(
response
.
data
.
str
)
setSortingDisplayName
(
response
.
data
.
str
)
}
else
{
}
else
{
console
.
log
(
"
else
"
)
const
response
=
await
axios
.
get
(
`/api/product/getproduct/main/
${
mainCategory
}
?method=
${
method
}
&page=1`
)
const
response
=
await
axios
.
get
(
`/api/product/getproduct/main/
${
mainCategory
}
?method=
${
method
}
&page=1`
)
setProductlist
(
response
.
data
.
productsPiece
)
setProductlist
(
response
.
data
.
productsPiece
)
// setLength(response.data.length)
setSortingDisplayName
(
response
.
data
.
str
)
setSortingDisplayName
(
response
.
data
.
str
)
}
}
}
catch
(
error
)
{
}
catch
(
error
)
{
...
@@ -153,19 +108,7 @@ function ProductsList({ match }) {
...
@@ -153,19 +108,7 @@ function ProductsList({ match }) {
}
}
}
}
async
function
changePageforSubname
()
{
try
{
console
.
log
(
"
changePageforSubname 실행
"
)
setError
(
''
)
const
response
=
await
axios
.
get
(
`/api/product/getproduct/sub?subname=
${
selectSubCategory
}
&page=
${
currentPage
}
`
)
setProductlist
(
response
.
data
.
productsPiece
)
}
catch
(
error
)
{
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
{
...
@@ -182,6 +125,32 @@ function ProductsList({ match }) {
...
@@ -182,6 +125,32 @@ function ProductsList({ match }) {
}
}
}
}
async
function
changePage
()
{
try
{
setError
(
''
)
if
(
selectSubCategory
==
''
&&
sortingName
==
''
&&
search
.
word
==
''
)
{
getProductlist
()
}
else
if
(
selectSubCategory
==
''
&&
sortingName
==
''
)
{
const
response
=
await
axios
.
get
(
`/api/product/getproduct/main/
${
mainCategory
}
?product=
${
search
.
word
}
&page=
${
currentPage
}
`
)
setProductlist
(
response
.
data
.
productsPiece
)
}
else
if
(
search
.
word
==
''
&&
sortingName
==
''
)
{
const
response
=
await
axios
.
get
(
`/api/product/getproduct/sub?subname=
${
selectSubCategory
}
&page=
${
currentPage
}
`
)
setProductlist
(
response
.
data
.
productsPiece
)
}
else
if
(
search
.
word
==
''
&&
selectSubCategory
==
''
)
{
const
response
=
await
axios
.
get
(
`/api/product/getproduct/main/
${
mainCategory
}
?method=
${
sortingName
}
&page=
${
currentPage
}
`
)
setProductlist
(
response
.
data
.
productsPiece
)
}
else
if
(
selectSubCategory
==
''
)
{
const
response
=
await
axios
.
get
(
`/api/product/getproduct/main/
${
mainCategory
}
?product=
${
search
.
word
}
&method=
${
sortingName
}
&page=
${
currentPage
}
`
)
setProductlist
(
response
.
data
.
productsPiece
)
}
else
if
(
search
.
word
==
''
)
{
const
response
=
await
axios
.
get
(
`/api/product/getproduct/sub?subname=
${
selectSubCategory
}
&method=
${
sortingName
}
&page=
${
currentPage
}
`
)
setProductlist
(
response
.
data
.
productsPiece
)
}
}
catch
(
error
)
{
catchError
(
error
,
setError
)
}
}
if
(
error
)
{
if
(
error
)
{
alert
(
`
${
error
}
`
)
alert
(
`
${
error
}
`
)
setError
(
''
)
setError
(
''
)
...
@@ -190,7 +159,6 @@ function ProductsList({ match }) {
...
@@ -190,7 +159,6 @@ 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 {
...
...
server/controllers/product.controller.js
View file @
25eac458
...
@@ -84,6 +84,7 @@ const getlist = (req, res) => {
...
@@ -84,6 +84,7 @@ const getlist = (req, res) => {
const
categoryId
=
async
(
req
,
res
,
next
,
category
)
=>
{
const
categoryId
=
async
(
req
,
res
,
next
,
category
)
=>
{
const
per
=
9
;
const
per
=
9
;
console
.
log
(
"
query=
"
,
req
.
query
)
try
{
try
{
if
(
req
.
query
.
product
&&
req
.
query
.
method
)
{
if
(
req
.
query
.
product
&&
req
.
query
.
method
)
{
let
method
=
''
let
method
=
''
...
@@ -156,6 +157,7 @@ const categoryId = async (req, res, next, category) => {
...
@@ -156,6 +157,7 @@ const categoryId = async (req, res, next, category) => {
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
)
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
req
.
productsPiece
=
productsPiece
}
else
{
}
else
{
console
.
log
(
"
else
"
)
const
productslist
=
await
Product
.
find
({
main_category
:
category
}).
sort
({
createdAt
:
-
1
})
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
...
...
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