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
PrivateRoute
from
"
./Components/PrivateRoute
"
;
import
AdminRoute
from
"
./Components/AdminRoute
"
;
import
Home
from
'
./Pages/Home
'
;
import
Login
from
'
./Pages/Login
'
;
import
Signup
from
'
./Pages/Signup
'
;
...
...
@@ -26,12 +27,25 @@ function App() {
<
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
}
/
>
<
Route
path
=
"
/shoppingcart
"
component
=
{
ShoppingCart
}
/
>
<
Route
path
=
"
/payment
"
component
=
{
Payment
}
/
>
<
Route
path
=
"
/account
"
component
=
{
Account
}
/
>
<
Route
path
=
'
/kakao
'
component
=
{()
=>
{
window
.
location
.
href
=
'
https://compmath.korea.ac.kr
'
;
return
null
;
}}
/
>
<
AdminRoute
path
=
"
/admin
"
>
<
Admin
/>
<
/AdminRoute
>
<
AdminRoute
path
=
"
/regist
"
>
<
ProductRegist
/>
<
/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
=
"
/
"
/>
<
/Switch
>
<
/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
{
Navbar
,
Nav
}
from
'
react-bootstrap
'
;
import
{
handleLogout
,
isAuthenticated
}
from
'
../utils/auth
'
;
import
{
handleLogout
,
isAuthenticated
,
isAdmin
}
from
'
../utils/auth
'
;
function
MainNav
()
{
const
user
=
isAuthenticated
()
const
admin
=
isAdmin
()
return
(
<
Navbar
sticky
=
"
top
"
style
=
{{
background
:
"
#CDC5C2
"
}}
>
...
...
@@ -15,6 +15,9 @@ function MainNav() {
<
Nav
className
=
"
ml-auto
"
>
{
user
?
<>
<
Nav
.
Link
className
=
"
text-light
"
onClick
=
{()
=>
handleLogout
()}
>
Logout
<
/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() {
<
Nav
.
Link
className
=
"
text-light
"
href
=
'
/signup
'
>
Sign
Up
<
/Nav.Link
>
<
/
>
)}
<
Nav
.
Link
href
=
"
/shoppingcart
"
>
<
img
alt
=
"
카트
"
src
=
"
/icon/cart.svg
"
width
=
"
30
"
height
=
"
30
"
/>
<
/Nav.Link
>
<
Nav
.
Link
href
=
"
/admin
"
>
{
admin
?
<
Nav
.
Link
href
=
"
/admin
"
>
<
img
alt
=
"
관리자
"
src
=
"
/icon/option.svg
"
width
=
"
30
"
height
=
"
30
"
/>
<
/Nav.Link
>
<
/Nav.Link>
: ''
}
<
/Nav
>
<
/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() {
},
[])
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
"
>
{
`
.nav-link, .nav-link:hover, .nav-link:active {
...
...
client/src/Pages/Account.js
View file @
32e08aba
...
...
@@ -16,6 +16,7 @@ function Account() {
const
[
proshow
,
setProshow
]
=
useState
(
false
)
const
[
error
,
setError
]
=
useState
(
""
)
const
userId
=
isAuthenticated
()
const
[
ordered
,
setOrdered
]
=
useState
(
''
)
async
function
getUsername
(
user
)
{
// console.log("tlg")
...
...
@@ -31,6 +32,7 @@ function Account() {
useEffect
(()
=>
{
getUsername
(
userId
)
getOrdered
(
userId
)
},
[
userId
])
const
handleChange
=
(
event
)
=>
{
...
...
@@ -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
(
<
Container
className
=
"
px-3
"
>
<
style
type
=
"
text/css
"
>
...
...
@@ -105,7 +118,7 @@ function Account() {
)}
<
/Button
>
<
Modal
show
=
{
show
}
onHide
=
{()
=>
setShow
(
false
)}
>
<
Modal
.
Header
closeButton
style
=
{{
background
:
"
#F7F3F3
"
}}
>
<
Modal
.
Header
closeButton
style
=
{{
background
:
"
#F7F3F3
"
}}
>
<
Modal
.
Title
>
이미지를
변경하시겠습니까
?
<
/Modal.Title
>
<
/Modal.Header
>
<
Form
onSubmit
=
{
handleSubmit
}
>
...
...
@@ -136,7 +149,7 @@ function Account() {
size
=
"
sm
"
show
=
{
proshow
}
onHide
=
{()
=>
setProshow
(
false
)}
>
<
Modal
.
Header
closeButton
style
=
{{
background
:
"
#F7F3F3
"
}}
>
<
Modal
.
Header
closeButton
style
=
{{
background
:
"
#F7F3F3
"
}}
>
<
Modal
.
Title
>
회원정보
<
/Modal.Title
>
<
/Modal.Header
>
<
Modal
.
Body
>
...
...
client/src/Pages/Payment.js
View file @
32e08aba
...
...
@@ -8,9 +8,8 @@ import { isAuthenticated } from '../utils/auth';
import
catchErrors
from
'
../utils/catchErrors
'
;
function
Payment
({
match
,
location
})
{
const
[
cart
,
setCart
]
=
useState
([])
const
[
order
,
setOrder
]
=
useState
({
products
:
[]
})
const
[
order
,
setOrder
]
=
useState
({
products
:
[]})
const
[
userData
,
setUserData
]
=
useState
({})
const
[
error
,
setError
]
=
useState
()
const
[
paymentWay
,
setPaymentWay
]
=
useState
([])
...
...
@@ -202,6 +201,8 @@ function Payment({ match, location }) {
return
<
Redirect
to
=
{
'
/kakao
'
}
/
>
}
return
(
<
div
>
{
/* {console.log(order)} */
}
...
...
client/src/Pages/ShoppingCart.js
View file @
32e08aba
import
React
,
{
useState
,
useEffect
,
useRef
}
from
'
react
'
;
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
catchErrors
from
'
../utils/catchErrors
'
;
import
{
isAuthenticated
}
from
'
../utils/auth
'
import
{
isAuthenticated
}
from
'
../utils/auth
'
;
import
CartCard
from
'
../Components/CartCard
'
;
function
ShoppingCart
()
{
...
...
@@ -134,7 +134,6 @@ function ShoppingCart() {
}}
className
=
"
px-5
"
style
=
{{
background
:
"
#91877F
"
,
borderColor
:
'
#91877F
'
}}
onClick
=
{
putCheckedCart
}
block
>
결제하기
<
/Button
>
<
/div
>
<
/Container
>
<
/div
>
)
}
...
...
client/src/Pages/Signup.js
View file @
32e08aba
...
...
@@ -118,9 +118,7 @@ function Signup() {
onChange
=
{
handleChange
}
>
<
/Form.Control
>
<
/Col
>
<
Col
xs
=
{
2
}
>
<
div
className
=
'
font-weight-bold d-flex align-items-center
'
>*
*
*
*
*
*
<
/div
>
<
/Col
>
<
Form
.
Control
.
Feedback
type
=
"
invalid
"
>
주민등록번호를
입력하세요
.
<
/Form.Control.Feedback
>
<
/Form.Row
>
<
/Form.Group
>
...
...
server/controllers/cart.controller.js
View file @
32e08aba
...
...
@@ -32,12 +32,15 @@ const changeCart = async (req, res) => {
const
showCart
=
async
(
req
,
res
)
=>
{
try
{
console
.
log
(
"
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
"
)
const
cart
=
await
Cart
.
findOne
({
userId
:
req
.
id
}).
populate
({
path
:
'
products.productId
'
,
model
:
'
Product
'
})
res
.
status
(
200
).
json
(
cart
.
products
)
console
.
log
(
"
cart-products :
"
,
cart
.
products
);
}
catch
(
error
)
{
console
.
log
(
"
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
"
)
console
.
log
(
error
)
res
.
status
(
500
).
send
(
'
쇼핑카트를 불러오지 못했습니다.
'
)
}
...
...
server/controllers/category.controller.js
View file @
32e08aba
...
...
@@ -12,7 +12,7 @@ const getCategory = async (req, res) => {
}
const
getSubCategory
=
async
(
req
,
res
)
=>
{
//
console.log("req.params=", req.params);
console
.
log
(
"
req.params=
"
,
req
.
params
);
const
{
sub
}
=
req
.
params
try
{
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) => {
}
}
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
)
=>
{
try
{
const
order
=
await
Order
.
findOne
({
userId
:
req
.
id
}).
populate
({
...
...
@@ -30,4 +41,4 @@ const showorder = async (req, res) => {
export
default
{
addorder
,
showorder
}
\ No newline at end of file
export
default
{
addorder
,
showorder
,
Ordered
}
\ 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