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
cdfec30f
Commit
cdfec30f
authored
Jan 20, 2021
by
kusang96
Browse files
Merge remote-tracking branch 'origin/sangho' into ourMaster
parents
74f2c338
97417b55
Changes
6
Show whitespace changes
Inline
Side-by-side
client/src/App.js
View file @
cdfec30f
...
...
@@ -24,6 +24,7 @@ function App() {
<
Route
path
=
"
/login
"
component
=
{
Login
}
/
>
<
Route
path
=
"
/signup
"
component
=
{
Signup
}
/
>
<
Route
path
=
"
/product/:productId
"
component
=
{
Product
}
/
>
<
Route
path
=
"
/categories/:main/:sub
"
component
=
{
ProductsList
}
/
>
<
Route
path
=
"
/categories/:main
"
component
=
{
ProductsList
}
/
>
<
Route
path
=
"
/admin
"
component
=
{
Admin
}
/
>
<
Route
path
=
"
/regist
"
component
=
{
ProductRegist
}
/
>
...
...
client/src/Components/SubNav.js
View file @
cdfec30f
...
...
@@ -16,6 +16,7 @@ function SubNav() {
const
url
=
ele
.
toLowerCase
()
list
.
push
(
<
Nav
.
Link
as
=
{
Link
}
to
=
{
`/categories/
${
url
}
`
}
>
{
ele
}
<
/Nav.Link
>
//categories/${SubNav.url}/&{url}
)
})
setCategoriesDiv
(
list
)
...
...
client/src/Pages/ProductsList.js
View file @
cdfec30f
import
React
,
{
useState
,
useEffect
,
useRef
}
from
'
react
'
;
import
{
Link
}
from
'
react-router-dom
'
;
import
ListCard
from
'
../Components/ListCard
'
;
import
Pagination
from
'
../Components/Pagination
'
;
import
axios
from
'
axios
'
;
import
catchError
from
'
../utils/catchErrors
'
;
import
{
isAuthenticated
}
from
'
../utils/auth
'
;
import
{
Container
,
Row
,
Col
,
Form
,
FormControl
,
Button
,
Dropdown
}
from
'
react-bootstrap
'
;
import
{
Container
,
Row
,
Col
,
Form
,
FormControl
,
Button
,
Dropdown
,
ButtonGroup
}
from
'
react-bootstrap
'
;
function
ProductsList
({
match
})
{
const
[
mainCategory
,
setMainCategory
]
=
useState
(
match
.
params
.
main
.
toUpperCase
())
const
[
subcategory
,
setSubcategory
]
=
useState
([])
const
[
productlist
,
setProductlist
]
=
useState
([])
const
[
sub
,
setSub
]
=
useState
([])
const
[
error
,
setError
]
=
useState
(
''
)
// const user=isAuthenticated()
useEffect
(()
=>
{
setMainCategory
(
match
.
params
.
main
.
toUpperCase
())
},
[
match
.
params
.
main
])
useEffect
(()
=>
{
getSubsCategories
()
getSubsCategories
(
[]
)
getProductlist
()
},
[
mainCategory
])
useEffect
(()
=>
{
setMainCategory
(
match
.
params
.
main
.
toUpperCase
())
},
[
match
.
params
.
main
])
function
handleSearch
()
{
}
// async function handleClick(subCategory) {
// try {
// const response = await axios.get(`/api/product/getproduct/${subCategory}`)
// console.log("response.data=", response.data)
// setProductlist(response.data)
// } catch (error) {
// catchErrors(error, setError)
// }
// }
// function handleSubmit(e) {
// e.preventDefault()
// }
async
function
getSubsCategories
()
{
async
function
getSubsCategories
([])
{
try
{
const
response
=
await
axios
.
get
(
`/api/categories/sub/
${
mainCategory
}
`
)
console
.
log
(
"
sub
"
,
response
.
data
)
setSubcategory
(
response
.
data
)
setSubcategory
(
Object
.
values
(
response
.
data
)[
0
])
console
.
log
(
"
response data=
"
,
response
.
data
)
console
.
log
(
"
object value=
"
,
Object
.
values
(
response
.
data
));
}
catch
(
error
)
{
catchError
(
error
,
setError
)
}
...
...
@@ -58,21 +43,7 @@ function ProductsList({ match }) {
const
response
=
await
axios
.
get
(
`/api/product/getproduct/
${
mainCategory
}
`
)
console
.
log
(
"
response.data=
"
,
response
.
data
)
setProductlist
(
response
.
data
)
}
catch
(
error
)
{
catchError
(
error
,
setError
)
}
}
function
handleClick
(
e
)
{
e
.
preventDefault
()
return
getsubproductlist
()
}
async
function
getsubproductlist
()
{
try
{
const
response
=
await
axios
.
get
(
`/api/product/getproduct/
${
subcategory
}
`
)
console
.
log
(
"
response.data sub=
"
,
response
.
data
)
setProductlist
(
response
.
data
)
}
catch
(
error
)
{
catchError
(
error
,
setError
)
}
...
...
@@ -80,7 +51,6 @@ function ProductsList({ match }) {
return
(
<
div
>
{
console
.
log
(
"
main=
"
,
mainCategory
)}
<
style
type
=
"
text/css
"
>
{
`
a, a:hover, a:active {
...
...
@@ -100,19 +70,17 @@ function ProductsList({ match }) {
`
}
<
/style
>
<
Container
>
<
Row
className
=
"
justify-content-center
"
>
<
Row
className
=
"
justify-content-center
"
>
<
Col
sm
=
{
10
}
xs
=
{
12
}
>
<
h1
style
=
{{
fontSize
:
"
3rem
"
}}
className
=
"
text-center
"
>
{
mainCategory
}
<
/h1
>
<
div
className
=
"
text-center
"
>
<
Button
className
=
"
m-1
"
onClick
=
{
getProductlist
}
>
ALL
<
/Button
>
{
subcategory
.
map
((
ele
)
=>
(
<
Button
className
=
"
m-1
"
onClick
=
{(
ele
)
=>
handleClick
(
ele
)}
>
{
ele
}
<
/Button
>
))}
<
ButtonGroup
className
=
"
d-flex flex-wrap
"
variant
=
"
outline-light secondary
"
>
{
subcategory
.
map
(
el
=>
<
Button
className
=
"
m-1
"
variant
=
"
secondary
"
>
{
el
}
<
/Button>
)
}
<
/ButtonGroup
>
<
/div
>
<
/Col
>
<
/Row
>
<
Row
className
=
"
justify-content-end mx-0 my-5
"
>
{
/* <Form as={Row} onSubmit={handleSubmit} className="justify-content-end mx-0"> */
}
<
Dropdown
>
<
Dropdown
.
Toggle
className
=
"
mx-2
"
>
정렬
<
/Dropdown.Toggle
>
<
Dropdown
.
Menu
>
...
...
@@ -128,7 +96,6 @@ function ProductsList({ match }) {
<
img
src
=
"
/icon/search.svg
"
width
=
"
20
"
height
=
"
20
"
/>
<
/Button
>
<
/Form
>
{
/* </Form> */
}
<
/Row
>
<
Row
md
=
{
8
}
sm
=
{
12
}
className
=
"
justify-content-center m-2
"
>
{
productlist
.
map
(
pro
=>
(
...
...
@@ -148,7 +115,6 @@ function ProductsList({ match }) {
))}
<
/Row
>
<
/Container
>
{
/* <Pagination postsPerPage={postsPerPage} totalPosts={posts.length} paginate={paginate} /> */
}
<
/div
>
)
}
...
...
server/controllers/category.controller.js
View file @
cdfec30f
import
Category
from
"
../schemas/Category.js
"
;
const
getCategory
=
async
(
req
,
res
)
=>
{
console
.
log
(
"
dsadd=
"
)
try
{
const
category
=
await
Category
.
find
({},
{
_id
:
0
})
const
category
=
await
Category
.
find
({},
{
_id
:
0
})
console
.
log
(
"
main=
"
,
category
);
res
.
json
(
category
)
}
catch
(
error
)
{
console
.
log
(
error
)
...
...
@@ -11,16 +11,60 @@ const getCategory = async (req, res) => {
}
}
const
getSubCategory
=
(
req
,
res
)
=>
{
const
getSubCategory
=
async
(
req
,
res
)
=>
{
console
.
log
(
"
req.params=
"
,
req
.
params
);
const
{
sub
}
=
req
.
params
try
{
const
subcategory
=
await
Category
.
findOne
({},
{
_id
:
0
}).
select
(
`
${
sub
}
`
)
console
.
log
(
"
sub=
"
,
subcategory
);
res
.
json
(
subcategory
);
}
catch
(
error
)
{
res
.
status
(
500
).
send
(
'
카테고리를 불러오지 못했습니다.
'
)
}
}
const
getsubId
=
(
req
,
res
,
next
,
sub
)
=>
{
// const subcategory = await category.find({})
console
.
log
(
'
sub=
'
,
sub
)
const
getToHome
=
async
(
res
,
req
)
=>
{
try
{
const
bestProduct
=
await
Product
.
find
({}).
sort
({
purchase
:
1
}).
limit
(
6
)
const
newProduct
=
await
Product
.
find
({}).
sort
({
createdAt
:
-
1
}).
limit
(
6
)
console
.
log
(
"
best=
"
,
bestProduct
)
console
.
log
(
"
new=
"
,
newProduct
)
res
.
json
(
bestProduct
,
newProduct
)
}
catch
{
res
.
status
(
500
).
send
(
'
상품을 불러오지 못했습니다.
'
)
}
}
const
getsubId
=
async
(
req
,
res
,
next
,
ele
)
=>
{
try
{
const
sub
=
await
Category
.
find
({
ele
})
if
(
!
sub
)
{
res
.
status
(
404
).
send
(
'
카테고리가 존재하지 않습니다.
'
)
}
req
.
category
=
sub
req
.
subcategory
=
sub
next
()
}
catch
(
error
)
{
console
.
log
(
error
);
res
.
status
(
500
).
send
(
'
카테고리를 불러오지 못했습니다.
'
)
}
next
()
}
// const userById = async (req, res, next, id) => {
// try {
// const user = await User.findById(id)
// if (!user) {
// res.status(404).send('사용자를 찾을 수 없습니다')
// }
// req.account = user
// next()
// } catch (error) {
// console.log(error);
// res.status(500).send('사용자 아이디 검색 실패')
// }
// }
export
default
{
getCategory
,
getsubId
,
getSubCategory
}
\ No newline at end of file
export
default
{
getCategory
,
getsubId
,
getSubCategory
,
getToHome
}
\ No newline at end of file
server/controllers/product.controller.js
View file @
cdfec30f
server/routes/category.routes.js
View file @
cdfec30f
...
...
@@ -9,6 +9,6 @@ router.route('/main')
router
.
route
(
'
/sub/:sub
'
)
.
get
(
categoryCtrl
.
getSubCategory
)
router
.
param
(
'
sub
'
,
categoryCtrl
.
getsubId
)
//
router.param('sub',categoryCtrl.getsubId)
export
default
router
\ No newline at end of file
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