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
04f8aedb
Commit
04f8aedb
authored
Aug 06, 2021
by
seoyeon
Browse files
Merge remote-tracking branch 'origin/woojiweon2' into seoyeon3
parents
cfe0f96b
d7bf440f
Changes
7
Hide whitespace changes
Inline
Side-by-side
client/src/apis/room.api.js
View file @
04f8aedb
...
...
@@ -25,11 +25,17 @@ const joinChannel = async (payload) => {
return
data
;
};
const
makeChannel
=
async
(
payload
)
=>
{
const
{
data
}
=
await
axios
.
post
(
"
/api/room/
makeChannel
"
,
payload
);
const
doubleJoin
=
async
(
payload
)
=>
{
const
{
data
}
=
await
axios
.
post
(
"
/api/room/
doubleJoin
"
,
payload
);
return
data
;
};
const
roomApi
=
{
getRoom
,
exitRoom
,
create
,
join
,
joinChannel
,
makeChannel
};
// 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
;
client/src/components/Room/ChannelList.js
View file @
04f8aedb
import
{
Link
}
from
'
react-router-dom
'
import
React
,
{
useState
}
from
'
react
'
;
import
{
Link
,
useParams
}
from
'
react-router-dom
'
import
React
,
{
useEffect
,
useState
}
from
'
react
'
;
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
{
roomId
}
=
useParams
();
const
[
error
,
setError
]
=
useState
(
""
);
const
[
channel
,
setChannel
]
=
useState
([
INIT_CHANNEL
]);
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
(
<
div
>
<
nav
className
=
"
navbar navbar-light
"
>
<
div
className
=
"
col-2
"
><
/div
>
<
div
>
<
div
onClick
=
{
exitChannel
}
>
<
Link
to
=
{
`/user/
${
id
}
`
}
>
<
img
src
=
"
/BORA.png
"
style
=
{{
width
:
'
160px
'
}}
/
>
<
/Link
>
...
...
client/src/components/Room/ChannelSingle.js
View file @
04f8aedb
...
...
@@ -9,8 +9,6 @@ const ChannelSingle = (props) => {
const
[
success
,
setSuccess
]
=
useState
(
false
);
const
[
roomName
,
setRoomName
]
=
useState
(
''
);
const
{
roomId
,
channelId
}
=
useParams
();
console
.
log
(
'
props
'
,
props
.
channel
)
console
.
log
(
'
hi
'
,
channelId
)
const
userId
=
localStorage
.
getItem
(
'
user
'
)
...
...
@@ -18,15 +16,15 @@ const ChannelSingle = (props) => {
console
.
log
(
e
,
userId
)
try
{
const
data
=
await
userApi
.
getUser
(
userId
);
const
el
=
indexCheck
(
e
)
console
.
log
(
el
)
const
mem
=
props
.
channel
[
el
].
joinUser
console
.
log
(
mem
)
const
index1
=
indexCheck
(
e
)
const
A
=
doubleJoinCheck
(
data
.
name
)
const
mem
=
props
.
channel
[
index1
].
joinUser
const
joinCh
=
mem
.
includes
(
data
.
name
);
console
.
log
(
joinCh
)
if
(
!
joinCh
)
{
const
roomA
=
await
roomApi
.
joinChannel
({
roomId
:
roomId
,
channelName
:
e
,
plusUser
:
data
.
name
,
index
:
el
})
console
.
log
(
roomA
)
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
)
setSuccess
(
true
)
}
else
{
...
...
@@ -37,15 +35,26 @@ const ChannelSingle = (props) => {
}
}
console
.
log
(
'
정보들어왔나
'
,
roomName
,
success
)
function
indexCheck
(
e
)
{
for
(
const
el
in
props
.
channel
)
{
console
.
log
(
'
체크
'
,
props
.
channel
[
el
].
channelName
,
e
)
console
.
log
(
'
체크
'
,
props
.
channel
[
el
].
channelName
===
e
)
if
(
props
.
channel
[
el
].
channelName
===
e
)
{
console
.
log
(
'
el
'
,
el
)
return
el
for
(
const
index1
in
props
.
channel
)
{
if
(
props
.
channel
[
index1
].
channelName
===
e
)
{
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
}
}
}
}
...
...
client/src/components/Room/InitRoom.js
View file @
04f8aedb
...
...
@@ -17,9 +17,7 @@ const InitRoom = () => {
async
function
getRoom
(
roomId
)
{
try
{
const
data
=
await
roomApi
.
getRoom
([
roomId
]);
console
.
log
(
data
)
setRoom
({...
room
,
id
:
data
[
0
].
id
,
name
:
data
[
0
].
name
,
profileimg
:
data
[
0
].
profileimg
})
console
.
log
(
room
.
profileimg
)
}
catch
(
error
)
{
catchErrors
(
error
,
setError
);
}
...
...
client/src/components/Room/RightHamburger.js
View file @
04f8aedb
...
...
@@ -32,28 +32,22 @@ const RightHamburger = () => {
console
.
log
(
"
id, roomid정보
"
,
id
,
roomId
);
try
{
const
data
=
await
RoomApi
.
exitRoom
({
id
,
roomId
});
console
.
log
(
data
);
}
catch
(
error
)
{
catchErrors
(
error
,
setError
);
}
}
async
function
getChannel
(
roomId
)
{
const
ID
=
roomId
;
try
{
const
data
=
await
RoomApi
.
getRoom
([
ID
]);
const
data
=
await
RoomApi
.
getRoom
([
roomId
]);
const
Channel
=
data
[
0
].
channel
;
console
.
log
(
"
방데이터:
"
,
Channel
);
const
channelList
=
[];
for
(
const
prop
in
Channel
)
{
// Channel의 항목(prop)으로 작업을 실행합니다
for
(
const
key
in
Channel
[
prop
])
{
console
.
log
(
key
);
console
.
log
(
prop
);
console
.
log
(
Channel
[
prop
][
key
]);
for
(
const
el
in
Channel
[
prop
])
{
channelList
.
push
({
channelName
:
key
,
joinUser
:
Channel
[
prop
][
key
],
channelName
:
el
,
joinUser
:
Channel
[
prop
][
el
],
});
}
}
...
...
server/controllers/room.controller.js
View file @
04f8aedb
...
...
@@ -121,18 +121,33 @@ const exitRoom = async (req, res) => {
const
joinChannel
=
async
(
req
,
res
)
=>
{
const
{
roomId
,
channelName
,
plusUser
,
index
}
=
req
.
body
console
.
log
(
'
연결성공
'
)
const
room
=
await
Room
.
findOne
({
where
:
{
id
:
roomId
}
});
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
}
});
return
res
.
json
(
true
)
}
const
makeChannel
=
async
(
req
,
res
)
=>
{
const
{
roomId
,
channelName
}
=
req
.
body
console
.
log
(
roomId
,
channelName
)
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
{
joinRoom
,
roomImgUpload
,
createRoom
,
getRoom
,
exitRoom
,
joinChannel
,
makeChannel
,
joinRoom
,
roomImgUpload
,
createRoom
,
getRoom
,
exitRoom
,
joinChannel
,
doubleJoin
,
};
server/routes/room.route.js
View file @
04f8aedb
...
...
@@ -7,6 +7,7 @@ router.route("/exitRoom/:id/:roomId").delete(roomCrtl.exitRoom);
router
.
route
(
"
/create
"
).
post
(
roomCrtl
.
roomImgUpload
,
roomCrtl
.
createRoom
);
router
.
route
(
"
/join
"
).
put
(
roomCrtl
.
joinRoom
);
router
.
route
(
"
/joinChannel
"
).
post
(
roomCrtl
.
joinChannel
);
router
.
route
(
"
/makeChannel
"
).
post
(
roomCrtl
.
makeChannel
);
router
.
route
(
"
/doubleJoin
"
).
post
(
roomCrtl
.
doubleJoin
);
// router.route("/makeChannel").post(roomCrtl.makeChannel);
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