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
32e08aba
Commit
32e08aba
authored
Jan 24, 2021
by
박상호
🎼
Browse files
Merge remote-tracking branch 'origin/ourMaster' into sangho
parents
fe776813
81cf0c68
Changes
12
Show whitespace changes
Inline
Side-by-side
client/src/App.js
View file @
32e08aba
import
'
./App.css
'
;
import
{
BrowserRouter
as
Router
,
Route
,
Redirect
,
Switch
}
from
'
react-router-dom
'
;
import
{
BrowserRouter
as
Router
,
Route
,
Redirect
,
Switch
}
from
'
react-router-dom
'
;
import
PrivateRoute
from
"
./Components/PrivateRoute
"
;
import
AdminRoute
from
"
./Components/AdminRoute
"
;
import
Home
from
'
./Pages/Home
'
;
import
Home
from
'
./Pages/Home
'
;
import
Login
from
'
./Pages/Login
'
;
import
Login
from
'
./Pages/Login
'
;
import
Signup
from
'
./Pages/Signup
'
;
import
Signup
from
'
./Pages/Signup
'
;
...
@@ -26,12 +27,25 @@ function App() {
...
@@ -26,12 +27,25 @@ function App() {
<
Route
path
=
"
/product/:productId
"
component
=
{
Product
}
/
>
<
Route
path
=
"
/product/:productId
"
component
=
{
Product
}
/
>
<
Route
path
=
"
/categories/:main/:sub
"
component
=
{
ProductsList
}
/
>
<
Route
path
=
"
/categories/:main/:sub
"
component
=
{
ProductsList
}
/
>
<
Route
path
=
"
/categories/:main
"
component
=
{
ProductsList
}
/
>
<
Route
path
=
"
/categories/:main
"
component
=
{
ProductsList
}
/
>
<
Route
path
=
"
/admin
"
component
=
{
Admin
}
/
>
<
AdminRoute
path
=
"
/admin
"
>
<
Route
path
=
"
/regist
"
component
=
{
ProductRegist
}
/
>
<
Admin
/>
<
Route
path
=
"
/shoppingcart
"
component
=
{
ShoppingCart
}
/
>
<
/AdminRoute
>
<
Route
path
=
"
/payment
"
component
=
{
Payment
}
/
>
<
AdminRoute
path
=
"
/regist
"
>
<
Route
path
=
"
/account
"
component
=
{
Account
}
/
>
<
ProductRegist
/>
<
Route
path
=
'
/kakao
'
component
=
{()
=>
{
window
.
location
.
href
=
'
https://compmath.korea.ac.kr
'
;
return
null
;
}}
/
>
<
/AdminRoute
>
<
PrivateRoute
path
=
"
/shoppingcart
"
>
<
ShoppingCart
/>
<
/PrivateRoute
>
<
PrivateRoute
path
=
"
/payment
"
>
<
Payment
/>
<
/PrivateRoute
>
<
PrivateRoute
path
=
"
/account
"
>
<
Account
/>
<
/PrivateRoute
>
{
/* <PrivateRoute path='/kakao'>
</PrivateRoute>
<Route component={() => { window.location.href = 'https://compmath.korea.ac.kr'; return null; }} /> */
}
<
Redirect
path
=
"
/
"
to
=
"
/
"
/>
<
Redirect
path
=
"
/
"
to
=
"
/
"
/>
<
/Switch
>
<
/Switch
>
<
/Router
>
<
/Router
>
...
...
client/src/Components/AdminRoute.js
0 → 100644
View file @
32e08aba
import
React
from
'
react
'
;
import
{
Redirect
,
Route
}
from
'
react-router-dom
'
;
import
{
isAdmin
}
from
'
../utils/auth
'
;
function
PrivateRoute
({
path
,
children
})
{
if
(
isAdmin
())
{
return
(
<
Route
path
=
{
path
}
>
{
children
}
<
/Route
>
)
}
else
{
alert
(
'
궈한이 없습니다. 죄송합니다.
'
);
return
(
<
Redirect
to
=
'
/
'
/>
)
}
}
export
default
PrivateRoute
\ No newline at end of file
client/src/Components/MainNav.js
View file @
32e08aba
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
{
Navbar
,
Nav
}
from
'
react-bootstrap
'
;
import
{
Navbar
,
Nav
}
from
'
react-bootstrap
'
;
import
{
handleLogout
,
isAuthenticated
}
from
'
../utils/auth
'
;
import
{
handleLogout
,
isAuthenticated
,
isAdmin
}
from
'
../utils/auth
'
;
function
MainNav
()
{
function
MainNav
()
{
const
user
=
isAuthenticated
()
const
user
=
isAuthenticated
()
const
admin
=
isAdmin
()
return
(
return
(
<
Navbar
sticky
=
"
top
"
style
=
{{
background
:
"
#CDC5C2
"
}}
>
<
Navbar
sticky
=
"
top
"
style
=
{{
background
:
"
#CDC5C2
"
}}
>
...
@@ -15,6 +15,9 @@ function MainNav() {
...
@@ -15,6 +15,9 @@ function MainNav() {
<
Nav
className
=
"
ml-auto
"
>
<
Nav
className
=
"
ml-auto
"
>
{
user
?
<>
<
Nav
.
Link
className
=
"
text-light
"
onClick
=
{()
=>
handleLogout
()}
>
Logout
<
/Nav.Link
>
{
user
?
<>
<
Nav
.
Link
className
=
"
text-light
"
onClick
=
{()
=>
handleLogout
()}
>
Logout
<
/Nav.Link
>
<
Nav
.
Link
className
=
"
text-light
"
href
=
"
/account
"
>
Mypage
<
/Nav.Link
>
<
Nav
.
Link
className
=
"
text-light
"
href
=
"
/account
"
>
Mypage
<
/Nav.Link
>
<
Nav
.
Link
href
=
"
/shoppingcart
"
>
<
img
alt
=
"
카트
"
src
=
"
/icon/cart.svg
"
width
=
"
30
"
height
=
"
30
"
/>
<
/Nav.Link
>
<
/
>
<
/
>
:
(
:
(
<>
<>
...
@@ -22,12 +25,9 @@ function MainNav() {
...
@@ -22,12 +25,9 @@ function MainNav() {
<
Nav
.
Link
className
=
"
text-light
"
href
=
'
/signup
'
>
Sign
Up
<
/Nav.Link
>
<
Nav
.
Link
className
=
"
text-light
"
href
=
'
/signup
'
>
Sign
Up
<
/Nav.Link
>
<
/
>
<
/
>
)}
)}
<
Nav
.
Link
href
=
"
/shoppingcart
"
>
{
admin
?
<
Nav
.
Link
href
=
"
/admin
"
>
<
img
alt
=
"
카트
"
src
=
"
/icon/cart.svg
"
width
=
"
30
"
height
=
"
30
"
/>
<
/Nav.Link
>
<
Nav
.
Link
href
=
"
/admin
"
>
<
img
alt
=
"
관리자
"
src
=
"
/icon/option.svg
"
width
=
"
30
"
height
=
"
30
"
/>
<
img
alt
=
"
관리자
"
src
=
"
/icon/option.svg
"
width
=
"
30
"
height
=
"
30
"
/>
<
/Nav.Link
>
<
/Nav.Link>
: ''
}
<
/Nav
>
<
/Nav
>
<
/Navbar
>
<
/Navbar
>
)
)
...
...
client/src/Components/PrivateRoute.js
0 → 100644
View file @
32e08aba
import
React
from
'
react
'
;
import
{
Redirect
,
Route
}
from
'
react-router-dom
'
;
import
{
isAuthenticated
}
from
'
../utils/auth
'
;
function
PrivateRoute
({
path
,
children
})
{
if
(
isAuthenticated
())
{
return
(
<
Route
path
=
{
path
}
>
{
children
}
<
/Route
>
)
}
else
{
alert
(
'
회원이 아닙니다. 로그인 및 회원가입을 진행해 주세요.
'
);
return
(
<
Redirect
to
=
'
/
'
/>
)
}
}
export
default
PrivateRoute
\ No newline at end of file
client/src/Components/SubNav.js
View file @
32e08aba
...
@@ -26,7 +26,7 @@ function SubNav() {
...
@@ -26,7 +26,7 @@ function SubNav() {
},
[])
},
[])
return
(
return
(
<
Navbar
sticky
=
"
top
"
className
=
"
flex-nowrap
"
style
=
{{
top
:
"
6
2
px
"
,
paddingTop
:
"
0
"
,
paddingBottom
:
"
0
"
,
backgroundColor
:
"
#fff
"
}}
>
<
Navbar
sticky
=
"
top
"
className
=
"
flex-nowrap
"
style
=
{{
top
:
"
5
6px
"
,
paddingTop
:
"
0
"
,
paddingBottom
:
"
0
"
,
backgroundColor
:
"
#fff
"
}}
>
<
style
type
=
"
text/css
"
>
<
style
type
=
"
text/css
"
>
{
`
{
`
.nav-link, .nav-link:hover, .nav-link:active {
.nav-link, .nav-link:hover, .nav-link:active {
...
...
client/src/Pages/Account.js
View file @
32e08aba
...
@@ -16,6 +16,7 @@ function Account() {
...
@@ -16,6 +16,7 @@ function Account() {
const
[
proshow
,
setProshow
]
=
useState
(
false
)
const
[
proshow
,
setProshow
]
=
useState
(
false
)
const
[
error
,
setError
]
=
useState
(
""
)
const
[
error
,
setError
]
=
useState
(
""
)
const
userId
=
isAuthenticated
()
const
userId
=
isAuthenticated
()
const
[
ordered
,
setOrdered
]
=
useState
(
''
)
async
function
getUsername
(
user
)
{
async
function
getUsername
(
user
)
{
// console.log("tlg")
// console.log("tlg")
...
@@ -31,6 +32,7 @@ function Account() {
...
@@ -31,6 +32,7 @@ function Account() {
useEffect
(()
=>
{
useEffect
(()
=>
{
getUsername
(
userId
)
getUsername
(
userId
)
getOrdered
(
userId
)
},
[
userId
])
},
[
userId
])
const
handleChange
=
(
event
)
=>
{
const
handleChange
=
(
event
)
=>
{
...
@@ -81,6 +83,17 @@ function Account() {
...
@@ -81,6 +83,17 @@ function Account() {
}
}
}
}
async
function
getOrdered
({})
{
console
.
log
(
"
object
"
)
try
{
const
response
=
await
axios
.
get
(
`/api/users/addorder`
)
setOrdered
(
response
.
data
)
console
.
log
(
'
@@@@
'
,
response
.
data
);
}
catch
(
error
)
{
catchError
(
error
,
setError
)
}
}
return
(
return
(
<
Container
className
=
"
px-3
"
>
<
Container
className
=
"
px-3
"
>
<
style
type
=
"
text/css
"
>
<
style
type
=
"
text/css
"
>
...
@@ -105,7 +118,7 @@ function Account() {
...
@@ -105,7 +118,7 @@ function Account() {
)}
)}
<
/Button
>
<
/Button
>
<
Modal
show
=
{
show
}
onHide
=
{()
=>
setShow
(
false
)}
>
<
Modal
show
=
{
show
}
onHide
=
{()
=>
setShow
(
false
)}
>
<
Modal
.
Header
closeButton
style
=
{{
background
:
"
#F7F3F3
"
}}
>
<
Modal
.
Header
closeButton
style
=
{{
background
:
"
#F7F3F3
"
}}
>
<
Modal
.
Title
>
이미지를
변경하시겠습니까
?
<
/Modal.Title
>
<
Modal
.
Title
>
이미지를
변경하시겠습니까
?
<
/Modal.Title
>
<
/Modal.Header
>
<
/Modal.Header
>
<
Form
onSubmit
=
{
handleSubmit
}
>
<
Form
onSubmit
=
{
handleSubmit
}
>
...
@@ -136,7 +149,7 @@ function Account() {
...
@@ -136,7 +149,7 @@ function Account() {
size
=
"
sm
"
size
=
"
sm
"
show
=
{
proshow
}
show
=
{
proshow
}
onHide
=
{()
=>
setProshow
(
false
)}
>
onHide
=
{()
=>
setProshow
(
false
)}
>
<
Modal
.
Header
closeButton
style
=
{{
background
:
"
#F7F3F3
"
}}
>
<
Modal
.
Header
closeButton
style
=
{{
background
:
"
#F7F3F3
"
}}
>
<
Modal
.
Title
>
회원정보
<
/Modal.Title
>
<
Modal
.
Title
>
회원정보
<
/Modal.Title
>
<
/Modal.Header
>
<
/Modal.Header
>
<
Modal
.
Body
>
<
Modal
.
Body
>
...
...
client/src/Pages/Payment.js
View file @
32e08aba
...
@@ -8,9 +8,8 @@ import { isAuthenticated } from '../utils/auth';
...
@@ -8,9 +8,8 @@ import { isAuthenticated } from '../utils/auth';
import
catchErrors
from
'
../utils/catchErrors
'
;
import
catchErrors
from
'
../utils/catchErrors
'
;
function
Payment
({
match
,
location
})
{
function
Payment
({
match
,
location
})
{
const
[
cart
,
setCart
]
=
useState
([])
const
[
cart
,
setCart
]
=
useState
([])
const
[
order
,
setOrder
]
=
useState
({
products
:
[]
})
const
[
order
,
setOrder
]
=
useState
({
products
:
[]})
const
[
userData
,
setUserData
]
=
useState
({})
const
[
userData
,
setUserData
]
=
useState
({})
const
[
error
,
setError
]
=
useState
()
const
[
error
,
setError
]
=
useState
()
const
[
paymentWay
,
setPaymentWay
]
=
useState
([])
const
[
paymentWay
,
setPaymentWay
]
=
useState
([])
...
@@ -202,6 +201,8 @@ function Payment({ match, location }) {
...
@@ -202,6 +201,8 @@ function Payment({ match, location }) {
return
<
Redirect
to
=
{
'
/kakao
'
}
/
>
return
<
Redirect
to
=
{
'
/kakao
'
}
/
>
}
}
return
(
return
(
<
div
>
<
div
>
{
/* {console.log(order)} */
}
{
/* {console.log(order)} */
}
...
...
client/src/Pages/ShoppingCart.js
View file @
32e08aba
import
React
,
{
useState
,
useEffect
,
useRef
}
from
'
react
'
;
import
React
,
{
useState
,
useEffect
,
useRef
}
from
'
react
'
;
import
{
Link
,
Redirect
}
from
'
react-router-dom
'
;
import
{
Link
,
Redirect
}
from
'
react-router-dom
'
;
import
{
Card
,
Button
,
Container
,
Row
,
Col
}
from
'
react-bootstrap
'
;
import
{
Button
,
Container
,
Row
,
Col
}
from
'
react-bootstrap
'
;
import
axios
from
'
axios
'
;
import
axios
from
'
axios
'
;
import
catchErrors
from
'
../utils/catchErrors
'
;
import
catchErrors
from
'
../utils/catchErrors
'
;
import
{
isAuthenticated
}
from
'
../utils/auth
'
import
{
isAuthenticated
}
from
'
../utils/auth
'
;
import
CartCard
from
'
../Components/CartCard
'
;
import
CartCard
from
'
../Components/CartCard
'
;
function
ShoppingCart
()
{
function
ShoppingCart
()
{
...
@@ -134,7 +134,6 @@ function ShoppingCart() {
...
@@ -134,7 +134,6 @@ function ShoppingCart() {
}}
className
=
"
px-5
"
style
=
{{
background
:
"
#91877F
"
,
borderColor
:
'
#91877F
'
}}
onClick
=
{
putCheckedCart
}
block
>
결제하기
<
/Button
>
}}
className
=
"
px-5
"
style
=
{{
background
:
"
#91877F
"
,
borderColor
:
'
#91877F
'
}}
onClick
=
{
putCheckedCart
}
block
>
결제하기
<
/Button
>
<
/div
>
<
/div
>
<
/Container
>
<
/Container
>
<
/div
>
<
/div
>
)
)
}
}
...
...
client/src/Pages/Signup.js
View file @
32e08aba
...
@@ -118,9 +118,7 @@ function Signup() {
...
@@ -118,9 +118,7 @@ function Signup() {
onChange
=
{
handleChange
}
>
onChange
=
{
handleChange
}
>
<
/Form.Control
>
<
/Form.Control
>
<
/Col
>
<
/Col
>
<
Col
xs
=
{
2
}
>
<
div
className
=
'
font-weight-bold d-flex align-items-center
'
>*
*
*
*
*
*
<
/div
>
<
div
className
=
'
font-weight-bold d-flex align-items-center
'
>*
*
*
*
*
*
<
/div
>
<
/Col
>
<
Form
.
Control
.
Feedback
type
=
"
invalid
"
>
주민등록번호를
입력하세요
.
<
/Form.Control.Feedback
>
<
Form
.
Control
.
Feedback
type
=
"
invalid
"
>
주민등록번호를
입력하세요
.
<
/Form.Control.Feedback
>
<
/Form.Row
>
<
/Form.Row
>
<
/Form.Group
>
<
/Form.Group
>
...
...
server/controllers/cart.controller.js
View file @
32e08aba
...
@@ -32,12 +32,15 @@ const changeCart = async (req, res) => {
...
@@ -32,12 +32,15 @@ const changeCart = async (req, res) => {
const
showCart
=
async
(
req
,
res
)
=>
{
const
showCart
=
async
(
req
,
res
)
=>
{
try
{
try
{
console
.
log
(
"
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
"
)
const
cart
=
await
Cart
.
findOne
({
userId
:
req
.
id
}).
populate
({
const
cart
=
await
Cart
.
findOne
({
userId
:
req
.
id
}).
populate
({
path
:
'
products.productId
'
,
path
:
'
products.productId
'
,
model
:
'
Product
'
model
:
'
Product
'
})
})
res
.
status
(
200
).
json
(
cart
.
products
)
res
.
status
(
200
).
json
(
cart
.
products
)
console
.
log
(
"
cart-products :
"
,
cart
.
products
);
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
"
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
"
)
console
.
log
(
error
)
console
.
log
(
error
)
res
.
status
(
500
).
send
(
'
쇼핑카트를 불러오지 못했습니다.
'
)
res
.
status
(
500
).
send
(
'
쇼핑카트를 불러오지 못했습니다.
'
)
}
}
...
...
server/controllers/category.controller.js
View file @
32e08aba
...
@@ -12,7 +12,7 @@ const getCategory = async (req, res) => {
...
@@ -12,7 +12,7 @@ const getCategory = async (req, res) => {
}
}
const
getSubCategory
=
async
(
req
,
res
)
=>
{
const
getSubCategory
=
async
(
req
,
res
)
=>
{
//
console.log("req.params=", req.params);
console
.
log
(
"
req.params=
"
,
req
.
params
);
const
{
sub
}
=
req
.
params
const
{
sub
}
=
req
.
params
try
{
try
{
const
subcategory
=
await
Category
.
findOne
({},
{
_id
:
0
}).
select
(
`
${
sub
}
`
)
const
subcategory
=
await
Category
.
findOne
({},
{
_id
:
0
}).
select
(
`
${
sub
}
`
)
...
...
server/controllers/order.controller.js
View file @
32e08aba
...
@@ -13,6 +13,17 @@ const addorder = async (req, res) => {
...
@@ -13,6 +13,17 @@ const addorder = async (req, res) => {
}
}
}
}
const
Ordered
=
async
(
req
,
res
)
=>
{
const
{
db
}
=
req
.
body
try
{
const
ordered
=
await
req
.
body
.
findOne
({},
{
_id
:
0
}).
select
(
`
${
db
}
`
)
console
.
log
(
"
sub=
"
,
ordered
);
res
.
json
(
ordered
);
}
catch
(
error
)
{
res
.
status
(
500
).
send
(
'
카테고리를 불러오지 못했습니다.
'
)
}
}
const
showorder
=
async
(
req
,
res
)
=>
{
const
showorder
=
async
(
req
,
res
)
=>
{
try
{
try
{
const
order
=
await
Order
.
findOne
({
userId
:
req
.
id
}).
populate
({
const
order
=
await
Order
.
findOne
({
userId
:
req
.
id
}).
populate
({
...
@@ -30,4 +41,4 @@ const showorder = async (req, res) => {
...
@@ -30,4 +41,4 @@ const showorder = async (req, res) => {
export
default
{
addorder
,
showorder
}
export
default
{
addorder
,
showorder
,
Ordered
}
\ No newline at end of file
\ 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