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
57c9ec85
Commit
57c9ec85
authored
Aug 05, 2021
by
우지원
Browse files
채널참여(DB에저장)가능 - 다른채널에 참가 or 방에서 나갈시 채널퇴장 추가해야됨....
parent
17fb0773
Changes
8
Hide whitespace changes
Inline
Side-by-side
client/src/apis/room.api.js
View file @
57c9ec85
...
@@ -20,6 +20,11 @@ const join = async (payload) => {
...
@@ -20,6 +20,11 @@ const join = async (payload) => {
return
data
;
return
data
;
};
};
const
roomApi
=
{
getRoom
,
exitRoom
,
create
,
join
};
const
joinChannel
=
async
(
payload
)
=>
{
const
{
data
}
=
await
axios
.
put
(
"
/api/room/joinChannel
"
,
payload
);
return
data
;
};
const
roomApi
=
{
getRoom
,
exitRoom
,
create
,
join
,
joinChannel
};
export
default
roomApi
;
export
default
roomApi
;
client/src/components/Login.js
View file @
57c9ec85
import
{
useEffect
,
useState
}
from
'
react
'
import
{
useEffect
,
useState
}
from
'
react
'
import
{
Link
}
from
'
react-router-dom
'
import
{
Link
,
Redirect
}
from
'
react-router-dom
'
import
userApi
from
'
../apis/user.api
'
import
userApi
from
'
../apis/user.api
'
import
catchErrors
from
'
../context/catchError
'
import
catchErrors
from
'
../context/catchError
'
import
{
handleLogin
}
from
'
../context/auth
'
import
{
handleLogin
}
from
'
../context/auth
'
...
@@ -46,7 +46,7 @@ const Login = () => {
...
@@ -46,7 +46,7 @@ const Login = () => {
}
}
if
(
success
)
{
if
(
success
)
{
alert
(
'
로그인 되었습니다
'
)
alert
(
'
로그인 되었습니다
'
)
window
.
location
.
href
=
`/user/
${
id
}
`
return
<
Redirect
to
=
{
`/user/
${
id
}
`
}
/>
;
}
}
const
{
email
,
password
}
=
user
const
{
email
,
password
}
=
user
...
...
client/src/components/Room/ChannelSingle.js
View file @
57c9ec85
import
{
Link
,
useParams
}
from
'
react-router-dom
'
import
{
useState
,
useEffect
}
from
'
react
'
import
{
Link
,
Redirect
,
useParams
}
from
'
react-router-dom
'
import
roomApi
from
'
../../apis/room.api
'
;
import
userApi
from
'
../../apis/user.api
'
import
catchErrors
from
"
../../context/catchError
"
;
const
ChannelSingle
=
(
props
)
=>
{
const
ChannelSingle
=
(
props
)
=>
{
const
{
roomId
,
channelId
}
=
useParams
()
const
[
error
,
setError
]
=
useState
(
""
);
const
[
succes
,
setSucces
]
=
useState
(
false
);
const
[
roomName
,
setRoomName
]
=
useState
(
''
);
const
{
roomId
,
channelId
}
=
useParams
();
console
.
log
(
'
props
'
,
props
.
channel
)
console
.
log
(
'
props
'
,
props
.
channel
)
console
.
log
(
'
hi
'
,
channelId
)
console
.
log
(
'
hi
'
,
channelId
)
const
userId
=
localStorage
.
getItem
(
'
user
'
)
async
function
joinChannel
(
e
)
{
console
.
log
(
e
,
userId
)
try
{
const
data
=
await
userApi
.
getUser
(
userId
);
const
key
=
indexCheck
(
e
)
console
.
log
(
key
)
const
mem
=
props
.
channel
[
key
].
joinUser
console
.
log
(
mem
)
const
joinCh
=
mem
.
includes
(
data
.
name
);
console
.
log
(
joinCh
)
if
(
!
joinCh
)
{
const
roomA
=
await
roomApi
.
joinChannel
({
roomId
:
roomId
,
channelName
:
e
,
plusUser
:
data
.
name
,
index
:
key
})
console
.
log
(
roomA
)
setRoomName
(
e
)
setSucces
(
true
)
}
else
{
alert
(
'
이미 참여된 채널입니다.
'
)
}
}
catch
(
error
)
{
catchErrors
(
error
,
setError
);
}
}
function
indexCheck
(
e
)
{
for
(
const
key
in
props
.
channel
)
{
console
.
log
(
'
체크
'
,
props
.
channel
[
key
].
channelName
,
e
)
console
.
log
(
'
체크
'
,
props
.
channel
[
key
].
channelName
===
e
)
if
(
props
.
channel
[
key
].
channelName
===
e
)
{
console
.
log
(
'
key
'
,
key
)
return
key
}
}
}
if
(
succes
){
alert
(
`
${
roomName
}
채널에 참가되었습니다.`
)
window
.
location
.
href
=
`/room/
${
roomId
}
/
${
roomName
}
`
}
return
(
return
(
<
div
>
<
div
>
<
div
className
=
"
overflow-auto
"
style
=
{{
height
:
'
610px
'
}}
>
<
div
className
=
"
overflow-auto
"
style
=
{{
height
:
'
610px
'
}}
>
...
@@ -13,6 +62,7 @@ const ChannelSingle = (props) => {
...
@@ -13,6 +62,7 @@ const ChannelSingle = (props) => {
<
div
<
div
className
=
"
m-3 p-1 row
"
className
=
"
m-3 p-1 row
"
style
=
{{
backgroundColor
:
'
#E0CEE8
'
}}
style
=
{{
backgroundColor
:
'
#E0CEE8
'
}}
onClick
=
{()
=>
joinChannel
(
el
.
channelName
)}
>
>
{
el
.
channelName
===
channelId
?
(
{
el
.
channelName
===
channelId
?
(
<
img
<
img
...
@@ -35,8 +85,8 @@ const ChannelSingle = (props) => {
...
@@ -35,8 +85,8 @@ const ChannelSingle = (props) => {
<
/div
>
<
/div
>
<
/Link
>
<
/Link
>
{
el
.
join
Name
&&
{
el
.
join
User
&&
el
.
join
Name
.
map
((
e
)
=>
(
el
.
join
User
.
map
((
e
)
=>
(
<
div
>
<
div
>
<
ul
className
=
"
mx-5
"
style
=
{{
color
:
'
#76D079
'
}}
>
<
ul
className
=
"
mx-5
"
style
=
{{
color
:
'
#76D079
'
}}
>
<
li
>
<
li
>
...
...
client/src/components/Room/RightHamburger.js
View file @
57c9ec85
...
@@ -10,7 +10,7 @@ const INIT_ROOM = {
...
@@ -10,7 +10,7 @@ const INIT_ROOM = {
const
INIT_CHANNEL
=
{
const
INIT_CHANNEL
=
{
channelName
:
""
,
channelName
:
""
,
join
Name
:
[],
join
User
:
[],
};
};
const
RightHamburger
=
()
=>
{
const
RightHamburger
=
()
=>
{
const
[
channel
,
setChannel
]
=
useState
([
INIT_CHANNEL
]);
const
[
channel
,
setChannel
]
=
useState
([
INIT_CHANNEL
]);
...
@@ -53,7 +53,7 @@ const RightHamburger = () => {
...
@@ -53,7 +53,7 @@ const RightHamburger = () => {
console
.
log
(
Channel
[
prop
][
key
]);
console
.
log
(
Channel
[
prop
][
key
]);
channelList
.
push
({
channelList
.
push
({
channelName
:
key
,
channelName
:
key
,
join
Name
:
Channel
[
prop
][
key
],
join
User
:
Channel
[
prop
][
key
],
});
});
}
}
}
}
...
...
client/src/components/SignUp.js
View file @
57c9ec85
...
@@ -61,7 +61,7 @@ const Signup = () => {
...
@@ -61,7 +61,7 @@ const Signup = () => {
if
(
success
)
{
if
(
success
)
{
alert
(
'
회원가입이 완료되었습니다!
'
)
alert
(
'
회원가입이 완료되었습니다!
'
)
window
.
location
.
href
=
'
/
'
return
<
Redirect
to
=
"
/
"
/>
;
}
}
const
{
name
,
id
,
password
,
checkpw
,
phone
}
=
user
const
{
name
,
id
,
password
,
checkpw
,
phone
}
=
user
...
...
server/controllers/room.controller.js
View file @
57c9ec85
...
@@ -107,18 +107,27 @@ const exitRoom = async (req, res) => {
...
@@ -107,18 +107,27 @@ const exitRoom = async (req, res) => {
const
room
=
await
Room
.
findOne
({
where
:
{
id
:
roomId
}
});
const
room
=
await
Room
.
findOne
({
where
:
{
id
:
roomId
}
});
console
.
log
(
room
.
member
)
console
.
log
(
room
.
member
)
const
index
=
room
.
member
.
indexOf
(
id
)
const
index
=
room
.
member
.
indexOf
(
id
)
console
.
log
(
'
index
'
,
index
)
console
.
log
(
'
index
'
,
index
)
room
.
member
.
splice
(
index
,
1
)
room
.
member
.
splice
(
index
,
1
)
await
Room
.
update
({
member
:
room
.
member
},
{
where
:
{
id
:
roomId
}
});
await
Room
.
update
({
member
:
room
.
member
},
{
where
:
{
id
:
roomId
}
});
const
user
=
await
User
.
findOne
({
where
:
{
id
:
id
}
});
const
user
=
await
User
.
findOne
({
where
:
{
id
:
id
}
});
console
.
log
(
user
.
roomNumber
)
console
.
log
(
user
.
roomNumber
)
const
index2
=
user
.
roomNumber
.
indexOf
(
id
)
const
index2
=
user
.
roomNumber
.
indexOf
(
id
)
console
.
log
(
'
index
'
,
index2
)
console
.
log
(
'
index
'
,
index2
)
user
.
roomNumber
.
splice
(
index2
,
1
)
user
.
roomNumber
.
splice
(
index2
,
1
)
await
User
.
update
({
roomNumber
:
user
.
roomNumber
},
{
where
:
{
id
:
id
}
});
await
User
.
update
({
roomNumber
:
user
.
roomNumber
},
{
where
:
{
id
:
id
}
});
}
}
const
joinChannel
=
async
(
req
,
res
)
=>
{
const
{
roomId
,
channelName
,
plusUser
,
index
}
=
req
.
body
const
room
=
await
Room
.
findOne
({
where
:
{
id
:
roomId
}
});
room
.
channel
[
index
][
channelName
].
push
(
plusUser
)
console
.
log
(
'
확인2
'
,
room
.
channel
[
index
])
await
Room
.
update
({
channel
:
room
.
channel
},
{
where
:
{
id
:
roomId
}
});
return
res
.
json
(
true
)
}
export
default
{
export
default
{
joinRoom
,
roomImgUpload
,
createRoom
,
getRoom
,
exitRoom
,
joinRoom
,
roomImgUpload
,
createRoom
,
getRoom
,
exitRoom
,
joinChannel
,
};
};
server/index.js
View file @
57c9ec85
...
@@ -23,21 +23,21 @@ sequelize
...
@@ -23,21 +23,21 @@ sequelize
roomNumber
:
[
"
1234567abc
"
,
"
abc7654321
"
],
roomNumber
:
[
"
1234567abc
"
,
"
abc7654321
"
],
});
});
//
await Room.create({
await
Room
.
create
({
//
id: "1234567abc",
id
:
"
1234567abc
"
,
//
name: "room",
name
:
"
room
"
,
//
owner: 8888,
owner
:
8888
,
//
member: [8888],
member
:
[
'
8888
'
,
'
9999
'
],
//
profileimg: "defaultimg",
profileimg
:
"
defaultimg
"
,
//
});
});
//
await Room.create({
await
Room
.
create
({
//
id: "abc7654321",
id
:
"
abc7654321
"
,
//
name: "room1",
name
:
"
room1
"
,
//
owner: 9999,
owner
:
9999
,
//
member: [9999],
member
:
[
'
9999
'
],
//
profileimg: "defaultimg",
profileimg
:
"
defaultimg
"
,
//
});
});
app
.
listen
(
appConfig
.
port
,
()
=>
{
app
.
listen
(
appConfig
.
port
,
()
=>
{
console
.
log
(
`Server is running on port
${
appConfig
.
port
}
`
);
console
.
log
(
`Server is running on port
${
appConfig
.
port
}
`
);
...
...
server/routes/room.route.js
View file @
57c9ec85
...
@@ -6,5 +6,7 @@ router.route("/getRoom").post(roomCrtl.getRoom);
...
@@ -6,5 +6,7 @@ router.route("/getRoom").post(roomCrtl.getRoom);
router
.
route
(
"
/exitRoom/:id/:roomId
"
).
delete
(
roomCrtl
.
exitRoom
);
router
.
route
(
"
/exitRoom/:id/:roomId
"
).
delete
(
roomCrtl
.
exitRoom
);
router
.
route
(
"
/create
"
).
post
(
roomCrtl
.
roomImgUpload
,
roomCrtl
.
createRoom
);
router
.
route
(
"
/create
"
).
post
(
roomCrtl
.
roomImgUpload
,
roomCrtl
.
createRoom
);
router
.
route
(
"
/join
"
).
put
(
roomCrtl
.
joinRoom
);
router
.
route
(
"
/join
"
).
put
(
roomCrtl
.
joinRoom
);
router
.
route
(
"
/joinChannel
"
).
put
(
roomCrtl
.
joinChannel
);
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