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
0cef6d11
Commit
0cef6d11
authored
Jan 15, 2021
by
이재연
Browse files
0115
parent
1dca5038
Changes
10
Hide whitespace changes
Inline
Side-by-side
client/src/Components/SubNav.js
View file @
0cef6d11
...
@@ -5,13 +5,13 @@ import axios from 'axios';
...
@@ -5,13 +5,13 @@ import axios from 'axios';
import
catchErrors
from
'
../utils/catchErrors
'
;
import
catchErrors
from
'
../utils/catchErrors
'
;
function
SubNav
()
{
function
SubNav
()
{
const
[
categor
y
sDiv
,
setCategor
y
sDiv
]
=
useState
([])
const
[
categor
ie
sDiv
,
setCategor
ie
sDiv
]
=
useState
([])
const
[
error
,
setError
]
=
useState
(
''
)
const
[
error
,
setError
]
=
useState
(
''
)
useEffect
(
async
()
=>
{
useEffect
(
async
()
=>
{
try
{
try
{
const
response
=
await
axios
.
get
(
'
/api/categor
ys
'
)
const
response
=
await
axios
.
get
(
'
/api/categor
ies/main
'
)
let
list
=
[]
let
list
=
[]
Object
.
keys
(
response
.
data
[
0
]).
forEach
((
ele
)
=>
{
Object
.
keys
(
response
.
data
[
0
]).
forEach
((
ele
)
=>
{
const
url
=
ele
.
toLowerCase
()
const
url
=
ele
.
toLowerCase
()
...
@@ -19,7 +19,7 @@ function SubNav() {
...
@@ -19,7 +19,7 @@ function SubNav() {
<
Nav
.
Link
as
=
{
Link
}
to
=
{
`/categories/
${
url
}
`
}
>
{
ele
}
<
/Nav.Link
>
<
Nav
.
Link
as
=
{
Link
}
to
=
{
`/categories/
${
url
}
`
}
>
{
ele
}
<
/Nav.Link
>
)
)
})
})
setCategor
y
sDiv
(
list
)
setCategor
ie
sDiv
(
list
)
}
catch
(
error
)
{
}
catch
(
error
)
{
catchErrors
(
error
,
setError
)
catchErrors
(
error
,
setError
)
}
}
...
@@ -35,7 +35,7 @@ function SubNav() {
...
@@ -35,7 +35,7 @@ function SubNav() {
`
}
`
}
<
/style
>
<
/style
>
<
Nav
>
<
Nav
>
{
categor
y
sDiv
.
map
(
item
=>
item
)}
{
categor
ie
sDiv
.
map
(
item
=>
item
)}
<
/Nav
>
<
/Nav
>
<
/Navbar
>
<
/Navbar
>
)
)
...
...
client/src/Pages/Login.js
View file @
0cef6d11
...
@@ -35,7 +35,7 @@ function Login() {
...
@@ -35,7 +35,7 @@ function Login() {
try
{
try
{
setError
(
''
)
setError
(
''
)
const
response
=
await
axios
.
post
(
'
/api/auth/login
'
,
user
)
const
response
=
await
axios
.
post
(
'
/api/auth/login
'
,
user
)
handleLogin
(
response
.
data
.
userId
)
handleLogin
(
response
.
data
)
setSuccess
(
true
)
setSuccess
(
true
)
}
catch
(
error
)
{
}
catch
(
error
)
{
catchErrors
(
error
,
setError
)
catchErrors
(
error
,
setError
)
...
...
client/src/utils/auth.js
View file @
0cef6d11
import
axios
from
"
axios
"
import
axios
from
"
axios
"
export
function
handleLogin
(
userId
){
export
function
handleLogin
({
userId
,
role
,
name
}){
localStorage
.
setItem
(
'
loginStatus
'
,
userId
)
localStorage
.
setItem
(
'
id
'
,
userId
)
localStorage
.
setItem
(
'
role
'
,
role
)
localStorage
.
setItem
(
'
name
'
,
name
)
}
}
export
async
function
handleLogout
(){
export
async
function
handleLogout
(){
localStorage
.
removeItem
(
'
loginStatus
'
)
localStorage
.
removeItem
(
'
id
'
)
localStorage
.
removeItem
(
'
role
'
)
localStorage
.
removeItem
(
'
name
'
)
await
axios
.
get
(
'
/api/auth/logout
'
)
await
axios
.
get
(
'
/api/auth/logout
'
)
window
.
location
.
href
=
'
/
'
window
.
location
.
href
=
'
/
'
}
}
export
function
isAuthenticated
(){
export
function
isAuthenticated
(){
const
userId
=
localStorage
.
getItem
(
'
loginStatus
'
)
const
userId
=
localStorage
.
getItem
(
'
id
'
)
if
(
userId
){
if
(
userId
){
return
userId
return
userId
}
else
{
}
else
{
...
...
server/app.js
View file @
0cef6d11
...
@@ -28,7 +28,7 @@ app.use('/images', express.static('uploads/'))
...
@@ -28,7 +28,7 @@ app.use('/images', express.static('uploads/'))
// app.use('/', indexRouter);
// app.use('/', indexRouter);
app
.
use
(
'
/
'
,
kakaopayRoutes
)
app
.
use
(
'
/
'
,
kakaopayRoutes
)
app
.
use
(
'
/api/categor
y
s
'
,
categoryRouter
)
app
.
use
(
'
/api/categor
ie
s
'
,
categoryRouter
)
app
.
use
(
'
/api/users
'
,
userRouter
)
app
.
use
(
'
/api/users
'
,
userRouter
)
app
.
use
(
'
/api/auth
'
,
authRouter
)
app
.
use
(
'
/api/auth
'
,
authRouter
)
app
.
use
(
'
/api/product
'
,
productRouter
)
app
.
use
(
'
/api/product
'
,
productRouter
)
...
...
server/controllers/auth.controller.js
View file @
0cef6d11
...
@@ -7,11 +7,11 @@ const login = async(req,res)=>{
...
@@ -7,11 +7,11 @@ const login = async(req,res)=>{
const
{
id
,
password
}
=
req
.
body
const
{
id
,
password
}
=
req
.
body
console
.
log
(
id
,
password
)
console
.
log
(
id
,
password
)
try
{
try
{
const
user
=
await
User
.
findOne
({
id
}).
select
(
'
+password
'
)
const
user
=
await
User
.
findOne
({
id
}).
select
(
'
password role name
'
)
console
.
log
(
'
u=
'
,
user
)
if
(
!
user
){
if
(
!
user
){
return
res
.
status
(
404
).
send
(
`
${
id
}
가 존재하지 않습니다.`
)
return
res
.
status
(
404
).
send
(
`
${
id
}
가 존재하지 않습니다.`
)
}
}
const
passwordMatch
=
await
bcrypt
.
compare
(
password
,
user
.
password
)
const
passwordMatch
=
await
bcrypt
.
compare
(
password
,
user
.
password
)
if
(
passwordMatch
){
if
(
passwordMatch
){
...
@@ -23,8 +23,8 @@ const login = async(req,res)=>{
...
@@ -23,8 +23,8 @@ const login = async(req,res)=>{
httpOnly
:
true
,
httpOnly
:
true
,
secure
:
config
.
env
===
'
production
'
secure
:
config
.
env
===
'
production
'
})
})
res
.
json
({
userId
:
user
.
_id
})
res
.
json
({
userId
:
user
.
_id
,
role
:
user
.
role
,
name
:
user
.
name
})
}
else
{
}
else
{
res
.
status
(
401
).
send
(
'
비밀번호가 일치하지 않습니다.
'
)
res
.
status
(
401
).
send
(
'
비밀번호가 일치하지 않습니다.
'
)
}
}
...
...
server/controllers/category.controller.js
View file @
0cef6d11
import
Category
from
"
../schemas/Category.js
"
;
import
Category
from
"
../schemas/Category.js
"
;
const
getCategory
=
async
(
req
,
res
)
=>
{
const
getCategory
=
async
(
req
,
res
)
=>
{
console
.
log
(
"
dsadd=
"
)
try
{
try
{
const
category
=
await
Category
.
find
({},
{
_id
:
0
})
const
category
=
await
Category
.
find
({},
{
_id
:
0
})
res
.
json
(
category
)
res
.
json
(
category
)
...
@@ -10,4 +11,16 @@ const getCategory = async (req, res) => {
...
@@ -10,4 +11,16 @@ const getCategory = async (req, res) => {
}
}
}
}
export
default
{
getCategory
}
const
getSubCategory
=
(
req
,
res
)
=>
{
\ No newline at end of file
}
const
getsubId
=
(
req
,
res
,
next
,
sub
)
=>
{
const
subcategory
=
await
category
.
find
({
"
Dress
"
})
console
.
log
(
'
sub=
'
,
sub
)
next
()
}
export
default
{
getCategory
,
getsubId
,
getSubCategory
}
\ No newline at end of file
server/controllers/product.controller.js
View file @
0cef6d11
...
@@ -41,12 +41,10 @@ const getlist=(req,res)=>{
...
@@ -41,12 +41,10 @@ const getlist=(req,res)=>{
const
categoryId
=
async
(
req
,
res
,
next
,
category
)
=>
{
const
categoryId
=
async
(
req
,
res
,
next
,
category
)
=>
{
try
{
try
{
console
.
log
(
category
)
const
productslist
=
await
Product
.
find
({
main_category
:
category
})
const
productslist
=
await
Product
.
find
({
"
main_category
"
:
`
${
category
}
`
})
if
(
!
productslist
)
{
if
(
!
productslist
)
{
res
.
status
(
404
).
send
(
'
상품을 찾을 수 없습니다.
'
)
res
.
status
(
404
).
send
(
'
상품을 찾을 수 없습니다.
'
)
}
}
console
.
log
(
"
list=
"
,
productslist
)
req
.
productslist
=
productslist
req
.
productslist
=
productslist
next
()
next
()
}
catch
(
error
)
{
}
catch
(
error
)
{
...
@@ -63,7 +61,7 @@ const subgetlist=(req,res)=>{
...
@@ -63,7 +61,7 @@ const subgetlist=(req,res)=>{
}
}
const
subcategoryId
=
async
(
req
,
res
,
next
,
subcategory
)
=>
{
const
subcategoryId
=
async
(
req
,
res
,
next
,
subcategory
)
=>
{
try
{
try
{
const
subproductslist
=
await
Product
.
find
({
"
sub_category
"
:
`
${
subcategory
}
`
}
)
const
subproductslist
=
await
Product
.
find
({
sub_category
:
subcategory
})
if
(
!
subproductslist
)
{
if
(
!
subproductslist
)
{
res
.
status
(
404
).
send
(
'
상품을 찾을 수 없습니다.
'
)
res
.
status
(
404
).
send
(
'
상품을 찾을 수 없습니다.
'
)
}
}
...
...
server/controllers/user.controller.js
View file @
0cef6d11
...
@@ -5,7 +5,7 @@ import bcrypt from 'bcryptjs';
...
@@ -5,7 +5,7 @@ import bcrypt from 'bcryptjs';
const
signup
=
async
(
req
,
res
)
=>
{
const
signup
=
async
(
req
,
res
)
=>
{
const
{
name
,
number1
,
number2
,
id
,
password
,
tel
}
=
req
.
body
const
{
name
,
number1
,
number2
,
id
,
password
,
tel
,
role
}
=
req
.
body
console
.
log
(
req
.
body
)
console
.
log
(
req
.
body
)
try
{
try
{
...
@@ -27,7 +27,7 @@ const signup = async (req, res) => {
...
@@ -27,7 +27,7 @@ const signup = async (req, res) => {
password
:
hash
,
password
:
hash
,
tel
,
tel
,
}).
save
()
}).
save
()
await
new
Cart
({
userId
:
newUser
.
_id
}).
save
()
await
new
Cart
({
userId
:
newUser
.
_id
,
role
}).
save
()
console
.
log
(
newUser
)
console
.
log
(
newUser
)
res
.
json
(
newUser
)
res
.
json
(
newUser
)
...
...
server/routes/category.routes.js
View file @
0cef6d11
...
@@ -3,7 +3,12 @@ import categoryCtrl from "../controllers/category.controller.js";
...
@@ -3,7 +3,12 @@ import categoryCtrl from "../controllers/category.controller.js";
const
router
=
express
.
Router
()
const
router
=
express
.
Router
()
router
.
route
(
'
/
'
)
router
.
route
(
'
/
main
'
)
.
get
(
categoryCtrl
.
getCategory
)
.
get
(
categoryCtrl
.
getCategory
)
router
.
route
(
'
/sub/:sub
'
)
.
get
(
categoryCtrl
.
getSubCategory
)
router
.
param
(
'
sub
'
,
categoryCtrl
.
getsubId
)
export
default
router
export
default
router
\ No newline at end of file
server/schemas/Category.js
View file @
0cef6d11
...
@@ -2,7 +2,7 @@ import mongoose from 'mongoose'
...
@@ -2,7 +2,7 @@ import mongoose from 'mongoose'
const
{
Array
}
=
mongoose
.
Schema
.
Types
const
{
Array
}
=
mongoose
.
Schema
.
Types
const
Categor
y
sSchema
=
new
mongoose
.
Schema
({
const
Categor
ie
sSchema
=
new
mongoose
.
Schema
({
"
DRESS
"
:
{
"
DRESS
"
:
{
type
:
Array
,
type
:
Array
,
required
:
true
required
:
true
...
@@ -33,4 +33,4 @@ const CategorysSchema = new mongoose.Schema ({
...
@@ -33,4 +33,4 @@ const CategorysSchema = new mongoose.Schema ({
},
},
})
})
export
default
mongoose
.
models
.
Categorys
||
mongoose
.
model
(
'
Categorys
'
,
CategorysSchema
)
export
default
mongoose
.
models
.
Categories
||
mongoose
.
model
(
'
Categories
'
,
CategoriesSchema
)
\ 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