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
53631f4f
Commit
53631f4f
authored
Jan 21, 2021
by
kusang96
Browse files
DSAD
parent
81cf0c68
Changes
9
Show whitespace changes
Inline
Side-by-side
client/src/Components/AdminRoute.js
View file @
53631f4f
...
@@ -10,7 +10,7 @@ function PrivateRoute({path, children}) {
...
@@ -10,7 +10,7 @@ function PrivateRoute({path, children}) {
<
/Route
>
<
/Route
>
)
)
}
else
{
}
else
{
alert
(
'
궈
한이 없습니다. 죄송합니다.
'
);
alert
(
'
권
한이 없습니다. 죄송합니다.
'
);
return
(
return
(
<
Redirect
to
=
'
/
'
/>
<
Redirect
to
=
'
/
'
/>
)
)
...
...
client/src/Components/AllCard.js
0 → 100644
View file @
53631f4f
import
React
,
{
useState
,
useEffect
,
useRef
}
from
'
react
'
;
import
{
Card
,
Button
}
from
'
react-bootstrap
'
;
function
AllCard
({
id
,
name
,
price
,
main_img
})
{
function
handleDelete
(
e
)
{
const
card
=
e
.
target
.
parentNode
.
parentNode
alert
(
'
해당 상품을 성공적으로 삭제하였습니다.
'
)
card
.
remove
()
}
return
(
<
Card
id
=
{
id
}
className
=
"
m-3
"
style
=
{{
width
:
"
18rem
"
}}
>
<
Card
.
Img
variant
=
"
top
"
src
=
{
main_img
&&
`/images/
${
main_img
}
`
}
style
=
{{
objectFit
:
"
contain
"
,
height
:
"
22rem
"
}}
/
>
<
Card
.
Body
>
<
Card
.
Title
style
=
{{
whiteSpace
:
"
nowrap
"
,
overflow
:
"
hidden
"
,
textOverflow
:
"
ellipsis
"
}}
>
{
name
}
<
/Card.Title
>
<
Card
.
Text
>
{
price
}
원
<
/Card.Text
>
<
Button
className
=
"
float-right
"
onClick
=
{
handleDelete
}
>
삭제
<
/Button
>
<
/Card.Body
>
<
/Card
>
)
}
export
default
AllCard
\ No newline at end of file
client/src/Components/ListCard.js
View file @
53631f4f
...
@@ -2,7 +2,6 @@ import React, { useState, useEffect, useRef } from 'react';
...
@@ -2,7 +2,6 @@ import React, { useState, useEffect, useRef } from 'react';
import
{
Card
,
Button
}
from
'
react-bootstrap
'
;
import
{
Card
,
Button
}
from
'
react-bootstrap
'
;
function
ListCard
({
id
,
name
,
price
,
main_img
})
{
function
ListCard
({
id
,
name
,
price
,
main_img
})
{
function
handleDelete
(
e
)
{
function
handleDelete
(
e
)
{
const
card
=
e
.
target
.
parentNode
.
parentNode
const
card
=
e
.
target
.
parentNode
.
parentNode
alert
(
'
해당 상품을 성공적으로 삭제하였습니다.
'
)
alert
(
'
해당 상품을 성공적으로 삭제하였습니다.
'
)
...
@@ -15,7 +14,6 @@ function ListCard({ id, name, price, main_img }) {
...
@@ -15,7 +14,6 @@ function ListCard({ id, name, price, main_img }) {
<
Card
.
Body
>
<
Card
.
Body
>
<
Card
.
Title
style
=
{{
whiteSpace
:
"
nowrap
"
,
overflow
:
"
hidden
"
,
textOverflow
:
"
ellipsis
"
}}
>
{
name
}
<
/Card.Title
>
<
Card
.
Title
style
=
{{
whiteSpace
:
"
nowrap
"
,
overflow
:
"
hidden
"
,
textOverflow
:
"
ellipsis
"
}}
>
{
name
}
<
/Card.Title
>
<
Card
.
Text
>
{
price
}
원
<
/Card.Text
>
<
Card
.
Text
>
{
price
}
원
<
/Card.Text
>
<
Button
className
=
"
float-right
"
onClick
=
{
handleDelete
}
>
삭제
<
/Button
>
<
/Card.Body
>
<
/Card.Body
>
<
/Card
>
<
/Card
>
)
)
...
...
client/src/Components/Pagination.js
View file @
53631f4f
...
@@ -18,3 +18,37 @@ function pagination() {
...
@@ -18,3 +18,37 @@ function pagination() {
}
}
export
default
pagination
export
default
pagination
// import { Pagination } from "react-bootstrap";
// import React from 'react';
// function Paginations(props) {
// return (
// <Pagination>
// <Pagination.First onClick={() => props.handlePage(1)} />
// {props.index === 1 ? <Pagination.Prev onClick={()=>props.handlePage(props.index)} /> : <Pagination.Prev onClick={()=>props.handlePage(props.index - 1)} />}
// {props.index === props.endPage-1 ? <Pagination.Item onClick={()=>props.handlePage(props.index - 3)}>{props.index - 3}</Pagination.Item> : ""}
// {props.index === props.endPage ? <Pagination.Item onClick={()=>props.handlePage(props.index - 4)}>{props.index - 4}</Pagination.Item> : ""}
// {props.index === props.endPage ? <Pagination.Item onClick={()=>props.handlePage(props.index - 3)}>{props.index - 3}</Pagination.Item> : ""}
// {props.index < 3 ? "" : <Pagination.Item onClick={()=>props.handlePage(props.index - 2)}>{props.index - 2}</Pagination.Item>}
// {props.index === 1 ? "" : <Pagination.Item onClick={()=>props.handlePage(props.index - 1)}>{props.index - 1}</Pagination.Item>}
// <Pagination.Item active>{props.index}</Pagination.Item>
// {props.index === props.endPage ? "" : <Pagination.Item onClick={()=>props.handlePage(props.index + 1)}>{props.index + 1}</Pagination.Item>}
// {props.index > props.endPage-2 ? "" : <Pagination.Item onClick={()=>props.handlePage(props.index + 2)}>{props.index + 2}</Pagination.Item>}
// {props.index === 1 ? <Pagination.Item onClick={()=>props.handlePage(props.index + 3)}>{props.index + 3}</Pagination.Item> : ""}
// {props.index === 1 ? <Pagination.Item onClick={()=>props.handlePage(props.index + 4)}>{props.index + 4}</Pagination.Item> : ""}
// {props.index === 2 ? <Pagination.Item onClick={()=>props.handlePage(props.index + 3)}>{props.index + 3}</Pagination.Item> : ""}
// {props.index === props.endPage ? "" : <Pagination.Next onClick={()=>props.handlePage(props.index + 1)} />}
// <Pagination.Last onClick={() =>props.handlePage(props.endPage)} />
// </Pagination>
// )
// }
// export default Paginations
\ No newline at end of file
client/src/Pages/Admin.js
View file @
53631f4f
import
React
,
{
useState
,
useEffect
,
useRef
}
from
'
react
'
;
import
React
,
{
useState
,
useEffect
,
useRef
}
from
'
react
'
;
import
{
Redirect
}
from
'
react-router-dom
'
;
import
{
Redirect
}
from
'
react-router-dom
'
;
import
List
Card
from
'
../Components/
List
Card
'
;
import
All
Card
from
'
../Components/
All
Card
'
;
import
Pagination
from
'
../Components/Pagination
'
;
import
Pagination
from
'
../Components/Pagination
'
;
import
axios
from
'
axios
'
;
import
axios
from
'
axios
'
;
import
{
isAdmin
}
from
"
../utils/auth
"
;
import
catchError
from
'
../utils/catchErrors
'
;
import
catchError
from
'
../utils/catchErrors
'
;
import
{
Row
,
Form
,
FormControl
,
Button
,
Card
,
Container
}
from
'
react-bootstrap
'
;
import
{
Row
,
Form
,
FormControl
,
Button
,
Container
}
from
'
react-bootstrap
'
;
function
Admin
()
{
function
Admin
()
{
const
[
productlist
,
setProductlist
]
=
useState
([])
const
[
productlist
,
setProductlist
]
=
useState
([])
const
[
error
,
setError
]
=
useState
(
''
)
const
[
error
,
setError
]
=
useState
(
''
)
const
role
=
isAdmin
()
useEffect
(()
=>
{
useEffect
(()
=>
{
getProductlist
()
getProductlist
()
...
@@ -34,11 +32,6 @@ function Admin() {
...
@@ -34,11 +32,6 @@ function Admin() {
e
.
preventDefault
()
e
.
preventDefault
()
}
}
if
(
!
role
)
{
alert
(
'
죄송합니다.접근 권한이 없습니다.
'
)
return
<
Redirect
to
=
"
/
"
/>
}
return
(
return
(
<
Container
>
<
Container
>
<
style
type
=
"
text/css
"
>
<
style
type
=
"
text/css
"
>
...
@@ -63,7 +56,7 @@ function Admin() {
...
@@ -63,7 +56,7 @@ function Admin() {
<
/Row
>
<
/Row
>
<
Row
className
=
"
justify-content-center m-5
"
>
<
Row
className
=
"
justify-content-center m-5
"
>
{
productlist
.
map
(
pro
=>
(
{
productlist
.
map
(
pro
=>
(
<
List
Card
id
=
{
pro
.
_id
}
name
=
{
pro
.
pro_name
}
price
=
{
pro
.
price
}
main_img
=
{
pro
.
main_imgUrl
}
/
>
<
All
Card
id
=
{
pro
.
_id
}
name
=
{
pro
.
pro_name
}
price
=
{
pro
.
price
}
main_img
=
{
pro
.
main_imgUrl
}
/
>
))}
))}
<
/Row
>
<
/Row
>
<
Pagination
/>
<
Pagination
/>
...
...
client/src/Pages/Home.js
View file @
53631f4f
...
@@ -21,7 +21,6 @@ function Home() {
...
@@ -21,7 +21,6 @@ function Home() {
async
function
getProductlist
()
{
async
function
getProductlist
()
{
try
{
try
{
const
response
=
await
axios
.
get
(
`/api/product/getproduct`
)
const
response
=
await
axios
.
get
(
`/api/product/getproduct`
)
console
.
log
(
"
res=
"
,
response
.
data
)
setProductlist
({
bestProduct
:
response
.
data
.
bestProduct
,
newProduct
:
response
.
data
.
newProduct
})
setProductlist
({
bestProduct
:
response
.
data
.
bestProduct
,
newProduct
:
response
.
data
.
newProduct
})
}
catch
(
error
)
{
}
catch
(
error
)
{
catchError
(
error
,
setError
)
catchError
(
error
,
setError
)
...
...
client/src/Pages/ProductsList.js
View file @
53631f4f
...
@@ -7,7 +7,7 @@ import { Container, Row, Col, Form, FormControl, Button, Dropdown, ButtonGroup }
...
@@ -7,7 +7,7 @@ import { Container, Row, Col, Form, FormControl, Button, Dropdown, ButtonGroup }
function
ProductsList
({
match
})
{
function
ProductsList
({
match
})
{
const
[
mainCategory
,
setMainCategory
]
=
useState
(
match
.
params
.
main
.
toUpperCase
())
const
[
mainCategory
,
setMainCategory
]
=
useState
(
match
.
params
.
main
.
toUpperCase
())
const
[
sub
c
ategory
,
setSub
c
ategory
]
=
useState
([])
const
[
sub
C
ategory
,
setSub
C
ategory
]
=
useState
([])
const
[
productlist
,
setProductlist
]
=
useState
([])
const
[
productlist
,
setProductlist
]
=
useState
([])
const
[
error
,
setError
]
=
useState
(
''
)
const
[
error
,
setError
]
=
useState
(
''
)
...
@@ -21,18 +21,27 @@ function ProductsList({ match }) {
...
@@ -21,18 +21,27 @@ function ProductsList({ match }) {
getProductlist
()
getProductlist
()
},
[
mainCategory
])
},
[
mainCategory
])
async
function
handleClick
(
sub
)
{
console
.
log
(
"
sub=
"
,
sub
)
try
{
const
response
=
await
axios
.
get
(
`/api/product/getproduct/
${
mainCategory
}
/
${
sub
}
`
)
console
.
log
(
"
response.data=
"
,
response
.
data
)
setProductlist
(
response
.
data
)
}
catch
(
error
)
{
catchError
(
error
,
setError
)
}
}
function
handleSearch
()
{
function
handleSearch
()
{
}
}
async
function
getSubsCategories
(
[]
)
{
async
function
getSubsCategories
()
{
try
{
try
{
const
response
=
await
axios
.
get
(
`/api/categories/sub/
${
mainCategory
}
`
)
const
response
=
await
axios
.
get
(
`/api/categories/sub/
${
mainCategory
}
`
)
setSubcategory
(
Object
.
values
(
response
.
data
)[
0
])
setSubCategory
(
Object
.
values
(
response
.
data
)[
0
])
console
.
log
(
"
response data=
"
,
response
.
data
)
console
.
log
(
"
object value=
"
,
Object
.
values
(
response
.
data
));
console
.
log
(
"
object value=
"
,
Object
.
values
(
response
.
data
));
}
catch
(
error
)
{
}
catch
(
error
)
{
catchError
(
error
,
setError
)
catchError
(
error
,
setError
)
}
}
...
@@ -41,7 +50,6 @@ function ProductsList({ match }) {
...
@@ -41,7 +50,6 @@ function ProductsList({ match }) {
async
function
getProductlist
()
{
async
function
getProductlist
()
{
try
{
try
{
const
response
=
await
axios
.
get
(
`/api/product/getproduct/
${
mainCategory
}
`
)
const
response
=
await
axios
.
get
(
`/api/product/getproduct/
${
mainCategory
}
`
)
console
.
log
(
"
response.data=
"
,
response
.
data
)
setProductlist
(
response
.
data
)
setProductlist
(
response
.
data
)
}
catch
(
error
)
{
}
catch
(
error
)
{
...
@@ -57,14 +65,12 @@ function ProductsList({ match }) {
...
@@ -57,14 +65,12 @@ function ProductsList({ match }) {
color: #000;
color: #000;
text-decoration: none;
text-decoration: none;
}
}
.btn {
.btn {
background-color: #CDC5C2;
background-color: #CDC5C2;
border-color: #CDC5C2;
border-color: #CDC5C2;
}
}
.btn:hover {
.btn:hover, .btn:active, .btn:focus, .show>.btn-primary.dropdown-toggle {
background: #91877F;
background-color: #91877F;
border-color: #91877F;
border-color: #91877F;
}
}
`
}
`
}
...
@@ -74,8 +80,8 @@ function ProductsList({ match }) {
...
@@ -74,8 +80,8 @@ function ProductsList({ match }) {
<
Col
sm
=
{
10
}
xs
=
{
12
}
>
<
Col
sm
=
{
10
}
xs
=
{
12
}
>
<
h1
style
=
{{
fontSize
:
"
3rem
"
}}
className
=
"
text-center
"
>
{
mainCategory
}
<
/h1
>
<
h1
style
=
{{
fontSize
:
"
3rem
"
}}
className
=
"
text-center
"
>
{
mainCategory
}
<
/h1
>
<
div
className
=
"
text-center
"
>
<
div
className
=
"
text-center
"
>
<
ButtonGroup
className
=
"
d-flex flex-wrap
"
variant
=
"
outline-light secondary
"
>
<
ButtonGroup
className
=
"
d-flex flex-wrap
"
>
{
sub
c
ategory
.
map
(
el
=>
(
<
Button
className
=
"
m-1
"
variant
=
"
secondary
"
>
{
el
}
<
/Button>
))
}
{
sub
C
ategory
.
map
(
el
=>
(
<
Button
className
=
"
m-1
"
onClick
=
{()
=>
handleClick
(
el
)}
>
{
el
}
<
/Button>
))
}
<
/ButtonGroup
>
<
/ButtonGroup
>
<
/div
>
<
/div
>
<
/Col
>
<
/Col
>
...
...
server/controllers/category.controller.js
View file @
53631f4f
...
@@ -3,7 +3,6 @@ import Category from "../schemas/Category.js";
...
@@ -3,7 +3,6 @@ import Category from "../schemas/Category.js";
const
getCategory
=
async
(
req
,
res
)
=>
{
const
getCategory
=
async
(
req
,
res
)
=>
{
try
{
try
{
const
category
=
await
Category
.
find
({},
{
_id
:
0
})
const
category
=
await
Category
.
find
({},
{
_id
:
0
})
console
.
log
(
"
main=
"
,
category
);
res
.
json
(
category
)
res
.
json
(
category
)
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
error
)
console
.
log
(
error
)
...
@@ -12,11 +11,9 @@ const getCategory = async (req, res) => {
...
@@ -12,11 +11,9 @@ const getCategory = async (req, res) => {
}
}
const
getSubCategory
=
async
(
req
,
res
)
=>
{
const
getSubCategory
=
async
(
req
,
res
)
=>
{
console
.
log
(
"
req.params=
"
,
req
.
params
);
const
name
=
req
.
params
.
name
const
{
sub
}
=
req
.
params
try
{
try
{
const
subcategory
=
await
Category
.
findOne
({},
{
_id
:
0
}).
select
(
`
${
sub
}
`
)
const
subcategory
=
await
Category
.
findOne
({},
{
_id
:
0
}).
select
(
`
${
name
}
`
)
console
.
log
(
"
sub=
"
,
subcategory
);
res
.
json
(
subcategory
);
res
.
json
(
subcategory
);
}
catch
(
error
)
{
}
catch
(
error
)
{
res
.
status
(
500
).
send
(
'
카테고리를 불러오지 못했습니다.
'
)
res
.
status
(
500
).
send
(
'
카테고리를 불러오지 못했습니다.
'
)
...
...
server/routes/category.routes.js
View file @
53631f4f
...
@@ -6,9 +6,7 @@ const router = express.Router()
...
@@ -6,9 +6,7 @@ const router = express.Router()
router
.
route
(
'
/main
'
)
router
.
route
(
'
/main
'
)
.
get
(
categoryCtrl
.
getCategory
)
.
get
(
categoryCtrl
.
getCategory
)
router
.
route
(
'
/sub/:
sub
'
)
router
.
route
(
'
/sub/:
name
'
)
.
get
(
categoryCtrl
.
getSubCategory
)
.
get
(
categoryCtrl
.
getSubCategory
)
// router.param('sub',categoryCtrl.getsubId)
export
default
router
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