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
bora-it
Commits
897e2880
Commit
897e2880
authored
Jul 28, 2021
by
우지원
Browse files
0728
parent
fa2eeb1e
Changes
10
Hide whitespace changes
Inline
Side-by-side
client/src/apis/room.api.js
View file @
897e2880
import
axios
from
"
axios
"
;
const
getRoom
=
async
(
payloa
d
)
=>
{
const
{
data
}
=
await
axios
.
get
(
"
/api/room/getRoom
"
,
payload
);
const
getRoom
=
async
(
i
d
)
=>
{
const
{
data
}
=
await
axios
.
get
(
`
/api/room/getRoom
/
${
id
}
`
);
return
data
;
};
...
...
client/src/apis/user.api.js
View file @
897e2880
import
axios
from
"
axios
"
;
const
getUser
=
async
(
payloa
d
)
=>
{
const
{
data
}
=
await
axios
.
pos
t
(
"
/api/getUser
"
,
payload
);
const
getUser
=
async
(
i
d
)
=>
{
const
{
data
}
=
await
axios
.
ge
t
(
`
/api/getUser
/
${
id
}
`
);
return
data
;
};
...
...
client/src/components/Home/HomeProfile.js
View file @
897e2880
import
{
Link
}
from
"
react-router-dom
"
;
import
{
useState
,
useEffect
}
from
"
react
"
;
import
userApi
from
"
../../apis/user.api
"
;
import
catchErrors
from
"
../../context/catchError
"
;
const
userprofile
=
localStorage
.
getItem
(
"
user
"
);
console
.
log
(
userprofile
)
...
...
@@ -15,9 +16,8 @@ const HomeProfile = () => {
async
function
getSetUser
(
userID
)
{
try
{
// `/users/${userId}`랑 userId랑 같은지 확인
console
.
log
(
'
userID
'
,
userID
)
const
data
=
await
userApi
.
getUser
({
id
:
userID
})
console
.
log
(
'
userID
'
,
userID
)
const
data
=
await
userApi
.
getUser
(
{
userID
}
)
console
.
log
(
data
)
setUser
(
data
)
console
.
log
(
user
)
...
...
@@ -27,7 +27,6 @@ const HomeProfile = () => {
}
useEffect
(()
=>
{
console
.
log
(
'
예에에에에ㅔ에에
'
)
getSetUser
(
userprofile
)
},
[
userprofile
])
...
...
client/src/components/Home/RoomSingle.js
View file @
897e2880
...
...
@@ -5,27 +5,29 @@ import userApi from '../../apis/user.api';
const
RoomSingle
=
()
=>
{
const
[
roomNum
,
setRoomNum
]
=
useState
(
[]
)
const
[
roomNum
,
setRoomNum
]
=
useState
(
''
)
const
[
room
,
setRoom
]
=
useState
([])
const
id
=
localStorage
.
getItem
(
'
user
'
);
const
channelId
=
1
const
A
=
[]
async
function
getJoinRoom
(
Id
)
{
try
{
console
.
log
(
'
id:
'
,
id
)
const
User
=
await
userApi
.
getUser
({
id
:
Id
})
console
.
log
(
'
User1:
'
,
User
)
console
.
log
(
'
User2:
'
,
User
.
roomNumber
)
setRoomNum
(
User
.
data
.
roomNumber
)
const
Room
=
await
roomApi
.
getRoom
(
roomNum
)
}
catch
(
error
)
{
// catchErrors(error, setError)
}
}
// async function getJoinRoom(Id) {
// try {
// console.log('id:',id)
// const User = await userApi.getUser({id: Id})
// console.log('User1:',User)
// console.log('User2:',User.roomNumber)
// const RoomNumArr = User.roomNumber
// console.log('setRoomNum:',RoomNumArr)
// const Room = await roomApi.getRoom(RoomNumArr)
// } catch (error) {
// // catchErrors(error, setError)
// }
// }
useEffect
(()
=>
{
getJoinRoom
(
id
)
},
[
id
])
//
useEffect(() => {
//
getJoinRoom(id)
//
}, [id])
return
(
<
Link
...
...
client/src/context/auth.js
View file @
897e2880
...
...
@@ -2,6 +2,8 @@ import axios from 'axios'
export
function
handleLogin
(
userId
)
{
localStorage
.
setItem
(
"
user
"
,
userId
)
const
roomId
=
'
1234567890
'
localStorage
.
setItem
(
"
room
"
,
roomId
)
}
export
async
function
handleLogout
()
{
...
...
controllers/room.controller.js
View file @
897e2880
...
...
@@ -10,7 +10,7 @@ const joinRoom = async (req, res) => {
if
(
Boolean
(
room_Id
))
{
//roomId에 일치하는 방이 존재할때
//roomId에 일치하는 방의 member정보에 userId 저장하기
//member정보에 userId가 이미 저장되어 있는지 확인 -> 이미 참여된 방인지 확인
const
includeUserId
=
room_Id
.
member
.
includes
(
parseInt
(
userId
));
const
includeUserId
=
room_Id
.
member
.
includes
(
parseInt
(
userId
));
// console.log('Include확인:',includeUserId)
if
(
!
includeUserId
)
{
//아직 참여되지 않은 방인경우
room_Id
.
member
.
push
(
userId
)
//member에 userId추가
...
...
@@ -77,8 +77,8 @@ const createRoom = async (req, res) => {
}
}
const
getRoom
=
async
(
req
,
res
)
=>
{
console
.
log
(
'
req.body:
'
,
req
.
body
)
const
getRoom
=
async
(
req
,
res
)
=>
{
console
.
log
(
'
req.body:
'
,
req
.
body
)
}
export
default
{
...
...
controllers/user.controller.js
View file @
897e2880
...
...
@@ -6,6 +6,7 @@ import bcrypt from "bcryptjs";
const
getUser
=
async
(
req
,
res
)
=>
{
const
user
=
await
User
.
findOne
({
where
:
{
id
:
req
.
body
.
id
}
});
console
.
log
(
'
user:
'
,
user
)
res
.
json
(
user
)
};
...
...
index.js
View file @
897e2880
...
...
@@ -20,13 +20,22 @@ sequelize
email
:
"
admin
"
,
password
:
"
admin!
"
,
gender
:
0
,
roomNumber
:
[
"
1234567abc
"
,
"
abc7654321
"
],
});
await
Room
.
create
({
id
:
"
1234567
890
"
,
id
:
"
1234567
abc
"
,
name
:
"
room
"
,
owner
:
8888
,
member
:
[
8888
],
member
:
[
8888
,
9999
],
profileimg
:
"
C:
\
fakepath
\
스크린샷(1).png
"
,
});
await
Room
.
create
({
id
:
"
abc7654321
"
,
name
:
"
room1
"
,
owner
:
9999
,
member
:
[
9999
],
profileimg
:
"
C:
\
fakepath
\
스크린샷(1).png
"
,
});
...
...
routes/room.route.js
View file @
897e2880
...
...
@@ -2,7 +2,7 @@ import express from "express";
import
roomCrtl
from
"
../controllers/room.controller.js
"
;
const
router
=
express
.
Router
();
router
.
route
(
"
/getRoom
"
).
ge
t
(
roomCrtl
.
getRoom
);
router
.
route
(
"
/getRoom
"
).
pos
t
(
roomCrtl
.
getRoom
);
router
.
route
(
"
/create
"
).
post
(
roomCrtl
.
createRoom
);
router
.
route
(
"
/join
"
).
put
(
roomCrtl
.
joinRoom
);
...
...
routes/user.route.js
View file @
897e2880
...
...
@@ -3,7 +3,7 @@ import userCtrl from "../controllers/user.controller.js";
const
router
=
express
.
Router
();
router
.
route
(
"
/getUser
"
).
pos
t
(
userCtrl
.
getUser
);
router
.
route
(
"
/getUser
"
).
ge
t
(
userCtrl
.
getUser
);
router
.
route
(
"
/login
"
).
post
(
userCtrl
.
login
);
router
.
route
(
"
/signup
"
).
post
(
userCtrl
.
signup
);
...
...
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