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 }) {
getProductlist
()
},
[
mainCategory
])
// useEffect(() => {
// if (sortingName == '' && search.word == '' && selectSubCategory == '') {
// getProductlist()
// } else if (sortingName == '' && search.word == '') {
// changePageforSubname()
// } else if (selectSubCategory == '' && sortingName == '') {
// searchList()
// } else {
// changePageforSorting()
// }
// }, [currentPage])
useEffect
(()
=>
{
changePage
()
},
[
currentPage
])
async
function
getSubsCategories
()
{
try
{
...
...
@@ -58,9 +50,10 @@ function ProductsList({ match }) {
async
function
getProductlist
()
{
try
{
console
.
log
(
"
getProductlist 실행
"
)
setError
(
''
)
setSelectSubCategory
(
''
)
setSortingName
(
''
)
setSortingDisplayName
(
'
신상품
'
)
setSearch
({
word
:
''
})
const
response
=
await
axios
.
get
(
`/api/product/getproduct/main/
${
mainCategory
}
?page=
${
currentPage
}
`
)
setProductlist
(
response
.
data
.
productsPiece
)
...
...
@@ -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
)
{
setSearch
({
word
:
event
.
target
.
value
})
}
...
...
@@ -88,9 +70,10 @@ function ProductsList({ match }) {
async
function
handleSearch
(
e
)
{
e
.
preventDefault
()
try
{
console
.
log
(
"
handleSearch 실행
"
)
setError
(
''
)
setSelectSubCategory
(
''
)
setSortingName
(
''
)
setSortingDisplayName
(
'
신상품
'
)
setCurrentPage
(
1
)
const
response
=
await
axios
.
get
(
`/api/product/getproduct/main/
${
mainCategory
}
?product=
${
search
.
word
}
&page=1`
)
setProductlist
(
response
.
data
.
productsPiece
)
...
...
@@ -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
)
{
try
{
console
.
log
(
"
handleSort 실행
"
)
setError
(
''
)
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
)
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
)
{
...
...
@@ -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
)
{
console
.
log
(
"
handleSubname 실행
"
)
const
subname
=
e
.
target
.
name
setSelectSubCategory
(
e
.
target
.
name
)
try
{
...
...
@@ -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
)
{
alert
(
`
${
error
}
`
)
setError
(
''
)
...
...
@@ -190,7 +159,6 @@ function ProductsList({ match }) {
return
(
<
Container
>
{
console
.
log
(
"
subCategory=
"
,
selectSubCategory
,
"
sortingName=
"
,
sortingName
,
"
search=
"
,
search
.
word
,
"
page=
"
,
currentPage
)}
<
style
type
=
"
text/css
"
>
{
`
@font-face {
...
...
server/controllers/product.controller.js
View file @
25eac458
...
...
@@ -84,6 +84,7 @@ const getlist = (req, res) => {
const
categoryId
=
async
(
req
,
res
,
next
,
category
)
=>
{
const
per
=
9
;
console
.
log
(
"
query=
"
,
req
.
query
)
try
{
if
(
req
.
query
.
product
&&
req
.
query
.
method
)
{
let
method
=
''
...
...
@@ -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
)
req
.
productsPiece
=
productsPiece
}
else
{
console
.
log
(
"
else
"
)
const
productslist
=
await
Product
.
find
({
main_category
:
category
}).
sort
({
createdAt
:
-
1
})
const
length
=
productslist
.
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