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
7352203d
Commit
7352203d
authored
Aug 06, 2021
by
이재연
Browse files
Merge remote-tracking branch 'origin/woojiweon2' into jaeyeon2854
parents
5486346c
d7bf440f
Changes
9
Hide whitespace changes
Inline
Side-by-side
client/src/apis/room.api.js
View file @
7352203d
...
@@ -21,10 +21,21 @@ const join = async (payload) => {
...
@@ -21,10 +21,21 @@ const join = async (payload) => {
};
};
const
joinChannel
=
async
(
payload
)
=>
{
const
joinChannel
=
async
(
payload
)
=>
{
const
{
data
}
=
await
axios
.
p
u
t
(
"
/api/room/joinChannel
"
,
payload
);
const
{
data
}
=
await
axios
.
p
os
t
(
"
/api/room/joinChannel
"
,
payload
);
return
data
;
return
data
;
};
};
const
roomApi
=
{
getRoom
,
exitRoom
,
create
,
join
,
joinChannel
};
const
doubleJoin
=
async
(
payload
)
=>
{
const
{
data
}
=
await
axios
.
post
(
"
/api/room/doubleJoin
"
,
payload
);
return
data
;
};
// const makeChannel = async (payload) => {
// const { data } = await axios.post("/api/room/makeChannel", payload);
// return data;
// };
const
roomApi
=
{
getRoom
,
exitRoom
,
create
,
join
,
joinChannel
,
doubleJoin
};
export
default
roomApi
;
export
default
roomApi
;
client/src/components/Room/ChannelList.js
View file @
7352203d
import
{
Link
}
from
'
react-router-dom
'
import
{
Link
,
useParams
}
from
'
react-router-dom
'
import
React
,
{
useState
}
from
'
react
'
;
import
React
,
{
useEffect
,
useState
}
from
'
react
'
;
import
RightHamburger
from
'
./RightHamburger
'
;
import
RightHamburger
from
'
./RightHamburger
'
;
import
roomApi
from
'
../../apis/room.api
'
;
import
catchErrors
from
'
../../context/catchError
'
;
import
userApi
from
'
../../apis/user.api
'
;
const
INIT_CHANNEL
=
{
channelName
:
""
,
joinUser
:
[],
};
const
ChannelList
=
()
=>
{
const
ChannelList
=
()
=>
{
const
{
roomId
}
=
useParams
();
const
[
error
,
setError
]
=
useState
(
""
);
const
[
channel
,
setChannel
]
=
useState
([
INIT_CHANNEL
]);
const
id
=
localStorage
.
getItem
(
'
user
'
);
const
id
=
localStorage
.
getItem
(
'
user
'
);
async
function
getChannel
(
roomId
)
{
try
{
const
data
=
await
roomApi
.
getRoom
([
roomId
]);
const
Channel
=
data
[
0
].
channel
;
const
channelList
=
[];
for
(
const
prop
in
Channel
)
{
for
(
const
el
in
Channel
[
prop
])
{
channelList
.
push
({
channelName
:
el
,
joinUser
:
Channel
[
prop
][
el
],
});
}
}
setChannel
(
channelList
);
}
catch
(
error
)
{
catchErrors
(
error
,
setError
);
}
}
async
function
exitChannel
()
{
try
{
const
data
=
await
userApi
.
getUser
(
id
);
const
A
=
doubleJoinCheck
(
data
.
name
)
if
(
A
)
{
await
roomApi
.
doubleJoin
({
roomId
:
roomId
,
index1
:
A
.
index1
,
index2
:
A
.
index2
,
joinChName
:
A
.
joinChName
})
}
}
catch
(
error
)
{
catchErrors
(
error
,
setError
);
}
}
function
doubleJoinCheck
(
e
)
{
for
(
const
index
in
channel
)
{
for
(
const
el
in
channel
[
index
].
joinUser
)
{
if
(
channel
[
index
].
joinUser
[
el
]
===
e
)
{
const
doublejoinCh
=
channel
[
index
].
channelName
const
A
=
{
index1
:
index
,
index2
:
el
,
joinChName
:
doublejoinCh
,
}
return
A
}
}
}
}
useEffect
(()
=>
{
getChannel
(
roomId
);
},
[
roomId
])
return
(
return
(
<
div
>
<
div
>
<
nav
className
=
"
navbar navbar-light
"
>
<
nav
className
=
"
navbar navbar-light
"
>
<
div
className
=
"
col-2
"
><
/div
>
<
div
className
=
"
col-2
"
><
/div
>
<
div
>
<
div
onClick
=
{
exitChannel
}
>
<
Link
to
=
{
`/user/
${
id
}
`
}
>
<
Link
to
=
{
`/user/
${
id
}
`
}
>
<
img
src
=
"
/BORA.png
"
style
=
{{
width
:
'
160px
'
}}
/
>
<
img
src
=
"
/BORA.png
"
style
=
{{
width
:
'
160px
'
}}
/
>
<
/Link
>
<
/Link
>
...
...
client/src/components/Room/ChannelSingle.js
View file @
7352203d
import
{
useState
,
useEffect
}
from
'
react
'
import
{
useState
}
from
'
react
'
import
{
Link
,
Redirect
,
useParams
}
from
'
react-router-dom
'
import
{
Link
,
useParams
}
from
'
react-router-dom
'
import
roomApi
from
'
../../apis/room.api
'
;
import
roomApi
from
'
../../apis/room.api
'
;
import
userApi
from
'
../../apis/user.api
'
import
userApi
from
'
../../apis/user.api
'
import
catchErrors
from
"
../../context/catchError
"
;
import
catchErrors
from
"
../../context/catchError
"
;
const
ChannelSingle
=
(
props
)
=>
{
const
ChannelSingle
=
(
props
)
=>
{
const
[
error
,
setError
]
=
useState
(
""
);
const
[
error
,
setError
]
=
useState
(
""
);
const
[
succes
,
setSucces
]
=
useState
(
false
);
const
[
succes
s
,
setSucces
s
]
=
useState
(
false
);
const
[
roomName
,
setRoomName
]
=
useState
(
''
);
const
[
roomName
,
setRoomName
]
=
useState
(
''
);
const
{
roomId
,
channelId
}
=
useParams
();
const
{
roomId
,
channelId
}
=
useParams
();
const
userId
=
localStorage
.
getItem
(
'
user
'
)
const
userId
=
localStorage
.
getItem
(
'
user
'
)
...
@@ -15,13 +15,17 @@ const ChannelSingle = (props) => {
...
@@ -15,13 +15,17 @@ const ChannelSingle = (props) => {
async
function
joinChannel
(
e
)
{
async
function
joinChannel
(
e
)
{
try
{
try
{
const
data
=
await
userApi
.
getUser
(
userId
);
const
data
=
await
userApi
.
getUser
(
userId
);
const
key
=
indexCheck
(
e
)
const
index1
=
indexCheck
(
e
)
const
mem
=
props
.
channel
[
key
].
joinUser
const
A
=
doubleJoinCheck
(
data
.
name
)
const
mem
=
props
.
channel
[
index1
].
joinUser
const
joinCh
=
mem
.
includes
(
data
.
name
);
const
joinCh
=
mem
.
includes
(
data
.
name
);
if
(
!
joinCh
)
{
if
(
!
joinCh
)
{
const
roomA
=
await
roomApi
.
joinChannel
({
roomId
:
roomId
,
channelName
:
e
,
plusUser
:
data
.
name
,
index
:
key
})
if
(
A
)
{
await
roomApi
.
doubleJoin
({
roomId
:
roomId
,
index1
:
A
.
index1
,
index2
:
A
.
index2
,
joinChName
:
A
.
joinChName
})
}
const
roomA
=
await
roomApi
.
joinChannel
({
roomId
:
roomId
,
channelName
:
e
,
plusUser
:
data
.
name
,
index
:
index1
})
setRoomName
(
e
)
setRoomName
(
e
)
setSucces
(
true
)
setSucces
s
(
true
)
}
else
{
}
else
{
alert
(
'
이미 참여된 채널입니다.
'
)
alert
(
'
이미 참여된 채널입니다.
'
)
}
}
...
@@ -29,18 +33,34 @@ const ChannelSingle = (props) => {
...
@@ -29,18 +33,34 @@ const ChannelSingle = (props) => {
catchErrors
(
error
,
setError
);
catchErrors
(
error
,
setError
);
}
}
}
}
function
indexCheck
(
e
)
{
function
indexCheck
(
e
)
{
for
(
const
key
in
props
.
channel
)
{
for
(
const
index1
in
props
.
channel
)
{
if
(
props
.
channel
[
key
].
channelName
===
e
)
{
if
(
props
.
channel
[
index1
].
channelName
===
e
)
{
return
key
return
index1
}
}
}
function
doubleJoinCheck
(
e
)
{
for
(
const
index
in
props
.
channel
)
{
for
(
const
el
in
props
.
channel
[
index
].
joinUser
)
{
if
(
props
.
channel
[
index
].
joinUser
[
el
]
===
e
)
{
const
doublejoinCh
=
props
.
channel
[
index
].
channelName
const
A
=
{
index1
:
index
,
index2
:
el
,
joinChName
:
doublejoinCh
,
}
return
A
}
}
}
}
}
}
}
if
(
succes
)
{
if
(
succes
s
)
{
alert
(
`
${
roomName
}
채널에 참가되었습니다.`
)
alert
(
`
${
roomName
}
채널에 참가되었습니다.`
)
window
.
location
.
href
=
`/room/
${
roomId
}
/
${
roomName
}
`
window
.
location
.
href
=
`/room/
${
roomId
}
/
${
roomName
}
`
}
}
return
(
return
(
...
...
client/src/components/Room/MakeChannel.js
0 → 100644
View file @
7352203d
import
{
useState
}
from
"
react
"
;
import
{
useParams
}
from
"
react-router-dom
"
;
import
roomApi
from
"
../../apis/room.api
"
;
import
catchErrors
from
"
../../context/catchError
"
;
const
MakeChannel
=
()
=>
{
const
{
roomId
}
=
useParams
();
const
[
channelName
,
setChannelName
]
=
useState
(
""
);
const
[
error
,
setError
]
=
useState
(
""
);
const
[
success
,
setSuccess
]
=
useState
(
false
);
function
handleChange
(
event
)
{
const
{
value
}
=
event
.
target
;
setChannelName
(
value
);
}
console
.
log
(
channelName
)
async
function
handleSubmit
(
e
)
{
// e.preventDefault();
try
{
const
data
=
await
roomApi
.
makeChannel
({
roomId
:
roomId
,
channelName
:
channelName
});
console
.
log
(
'
서버연결됬나요
'
,
data
)
setSuccess
(
true
);
}
catch
(
error
)
{
catchErrors
(
error
,
setError
);
}
finally
{
// setLoading(false);
}
}
if
(
success
)
{
// console.log('success', success)
alert
(
'
채널생성이 완료되었습니다!
'
)
window
.
location
.
href
=
`/room/
${
roomId
}
/
${
channelName
}
`
}
return
(
<
div
className
=
"
modal-content
"
>
<
form
onSubmit
=
{
handleSubmit
}
>
<
div
className
=
"
modal-header
"
>
<
div
className
=
"
modal-title
"
id
=
"
MakeChannelModal
"
>
채널
생성하기
<
/div
>
<
button
type
=
"
button
"
className
=
"
btn-close
"
data
-
bs
-
dismiss
=
"
modal
"
aria
-
label
=
"
Close
"
><
/button
>
<
/div
>
<
div
className
=
"
modal-body
"
>
{
error
&&
<
div
className
=
"
alert alert-danger
"
>
{
error
}
<
/div>
}
<
div
className
=
"
input-group mb-3
"
>
<
input
type
=
"
text
"
className
=
"
form-control
"
placeholder
=
"
생성할 채널이름을 입력하세요
"
aria
-
label
=
"
생성할 채널이름을 입력하세요
"
aria
-
describedby
=
"
basic-addon1
"
name
=
"
channelName
"
// value={channelName}
onChange
=
{
handleChange
}
/
>
<
/div
>
<
div
className
=
"
modal-footer
"
>
<
button
type
=
"
submit
"
className
=
"
btn btn-primary
"
>
확인
<
/button
>
<
/div
>
<
/div
>
<
/form
>
<
/div
>
);
};
export
default
MakeChannel
;
client/src/components/Room/RightHamburger.js
View file @
7352203d
...
@@ -32,24 +32,22 @@ const RightHamburger = () => {
...
@@ -32,24 +32,22 @@ const RightHamburger = () => {
console
.
log
(
"
id, roomid정보
"
,
id
,
roomId
);
console
.
log
(
"
id, roomid정보
"
,
id
,
roomId
);
try
{
try
{
const
data
=
await
RoomApi
.
exitRoom
({
id
,
roomId
});
const
data
=
await
RoomApi
.
exitRoom
({
id
,
roomId
});
console
.
log
(
data
);
}
catch
(
error
)
{
}
catch
(
error
)
{
catchErrors
(
error
,
setError
);
catchErrors
(
error
,
setError
);
}
}
}
}
async
function
getChannel
(
roomId
)
{
async
function
getChannel
(
roomId
)
{
const
ID
=
roomId
;
try
{
try
{
const
data
=
await
RoomApi
.
getRoom
([
ID
]);
const
data
=
await
RoomApi
.
getRoom
([
roomId
]);
const
Channel
=
data
[
0
].
channel
;
const
Channel
=
data
[
0
].
channel
;
const
channelList
=
[];
const
channelList
=
[];
for
(
const
prop
in
Channel
)
{
for
(
const
prop
in
Channel
)
{
// Channel의 항목(prop)으로 작업을 실행합니다
// Channel의 항목(prop)으로 작업을 실행합니다
for
(
const
key
in
Channel
[
prop
])
{
for
(
const
el
in
Channel
[
prop
])
{
channelList
.
push
({
channelList
.
push
({
channelName
:
key
,
channelName
:
el
,
joinUser
:
Channel
[
prop
][
key
],
joinUser
:
Channel
[
prop
][
el
],
});
});
}
}
}
}
...
...
server/controllers/room.controller.js
View file @
7352203d
...
@@ -121,16 +121,33 @@ const exitRoom = async (req, res) => {
...
@@ -121,16 +121,33 @@ const exitRoom = async (req, res) => {
const
joinChannel
=
async
(
req
,
res
)
=>
{
const
joinChannel
=
async
(
req
,
res
)
=>
{
const
{
roomId
,
channelName
,
plusUser
,
index
}
=
req
.
body
const
{
roomId
,
channelName
,
plusUser
,
index
}
=
req
.
body
console
.
log
(
'
연결성공
'
)
const
room
=
await
Room
.
findOne
({
where
:
{
id
:
roomId
}
});
const
room
=
await
Room
.
findOne
({
where
:
{
id
:
roomId
}
});
room
.
channel
[
index
][
channelName
].
push
(
plusUser
)
room
.
channel
[
index
][
channelName
].
push
(
plusUser
)
console
.
log
(
'
확인2
'
,
room
.
channel
[
index
])
console
.
log
(
'
확인2
'
,
room
.
channel
[
index
])
console
.
log
(
'
확인2
'
,
room
.
channel
)
await
Room
.
update
({
channel
:
room
.
channel
},
{
where
:
{
id
:
roomId
}
});
await
Room
.
update
({
channel
:
room
.
channel
},
{
where
:
{
id
:
roomId
}
});
return
res
.
json
(
true
)
return
res
.
json
(
true
)
}
}
const
doubleJoin
=
async
(
req
,
res
)
=>
{
console
.
log
(
'
연결성공
'
,
req
.
body
)
const
{
roomId
,
index1
,
index2
,
joinChName
}
=
req
.
body
console
.
log
(
index1
)
const
room
=
await
Room
.
findOne
({
where
:
{
id
:
roomId
}
});
console
.
log
(
room
.
channel
[
index1
][
joinChName
])
room
.
channel
[
index1
][
joinChName
].
splice
(
index2
,
1
)
console
.
log
(
room
.
channel
[
index1
][
joinChName
])
console
.
log
(
'
room.channel
'
,
room
.
channel
)
await
Room
.
update
({
channel
:
room
.
channel
},
{
where
:
{
id
:
roomId
}
});
return
res
.
json
(
true
)
}
// const makeChannel = async (req, res) => {
// const { roomId, channelName } = req.body
// console.log(roomId, channelName)
// }
export
default
{
export
default
{
joinRoom
,
roomImgUpload
,
createRoom
,
getRoom
,
exitRoom
,
joinChannel
,
joinRoom
,
roomImgUpload
,
createRoom
,
getRoom
,
exitRoom
,
joinChannel
,
doubleJoin
,
};
};
server/index.js
View file @
7352203d
...
@@ -23,6 +23,22 @@ sequelize
...
@@ -23,6 +23,22 @@ sequelize
roomNumber
:
[
"
1234567abc
"
,
"
abc7654321
"
],
roomNumber
:
[
"
1234567abc
"
,
"
abc7654321
"
],
});
});
await
Room
.
create
({
id
:
"
1234567abc
"
,
name
:
"
room
"
,
owner
:
8888
,
member
:
[
'
8888
'
,
'
9999
'
],
profileimg
:
"
23bf0d83f161b5bf066f0a81beeb4e78
"
,
});
await
Room
.
create
({
id
:
"
abc7654321
"
,
name
:
"
room1
"
,
owner
:
9999
,
member
:
[
'
9999
'
],
profileimg
:
"
23bf0d83f161b5bf066f0a81beeb4e78
"
,
});
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/models/room.model.js
View file @
7352203d
...
@@ -17,11 +17,10 @@ const RoomModel = (sequelize) => {
...
@@ -17,11 +17,10 @@ const RoomModel = (sequelize) => {
},
},
member
:
{
member
:
{
type
:
DataTypes
.
ARRAY
(
DataTypes
.
STRING
),
type
:
DataTypes
.
ARRAY
(
DataTypes
.
STRING
),
//type: DataTypes.STRING,
},
},
profileimg
:
{
profileimg
:
{
type
:
DataTypes
.
STRING
,
type
:
DataTypes
.
STRING
,
defaultValue
:
"
defaultimg
"
//
defaultValue: "defaultimg"
},
},
channel
:
{
channel
:
{
type
:
DataTypes
.
ARRAY
(
DataTypes
.
JSON
),
type
:
DataTypes
.
ARRAY
(
DataTypes
.
JSON
),
...
...
server/routes/room.route.js
View file @
7352203d
...
@@ -6,7 +6,8 @@ router.route("/getRoom").post(roomCrtl.getRoom);
...
@@ -6,7 +6,8 @@ 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
);
router
.
route
(
"
/joinChannel
"
).
post
(
roomCrtl
.
joinChannel
);
router
.
route
(
"
/doubleJoin
"
).
post
(
roomCrtl
.
doubleJoin
);
// router.route("/makeChannel").post(roomCrtl.makeChannel);
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