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
messenger
Commits
fd82fdde
Commit
fd82fdde
authored
Jan 15, 2021
by
Soo Hyun Kim
Browse files
soo0115 룸스키마변경
parent
1b0c048c
Changes
6
Show whitespace changes
Inline
Side-by-side
client/src/Pages/HomePage.js
View file @
fd82fdde
...
@@ -17,8 +17,8 @@ import Chat from "../Components/Chat";
...
@@ -17,8 +17,8 @@ import Chat from "../Components/Chat";
const
socket
=
io
();
const
socket
=
io
();
const
INIT_
CHATR
=
{
const
INIT_
ROOM
=
{
n
ame
:
''
,
roomN
ame
:
''
,
interest
:
''
,
interest
:
''
,
isOpen
:
false
isOpen
:
false
}
}
...
@@ -27,7 +27,7 @@ function Home() {
...
@@ -27,7 +27,7 @@ function Home() {
const
[
show
,
setShow
]
=
useState
(
false
);
const
[
show
,
setShow
]
=
useState
(
false
);
const
[
show2
,
setShow2
]
=
useState
(
false
);
const
[
show2
,
setShow2
]
=
useState
(
false
);
const
[
chat
,
setChat
]
=
useState
(
false
);
const
[
chat
,
setChat
]
=
useState
(
false
);
const
[
chatR
,
setChatR
]
=
useState
(
INIT_
CHATR
);
const
[
room
,
setRoom
]
=
useState
(
INIT_
ROOM
);
const
[
disabled
,
setDisabled
]
=
useState
(
true
);
const
[
disabled
,
setDisabled
]
=
useState
(
true
);
const
[
error
,
setError
]
=
useState
(
''
);
const
[
error
,
setError
]
=
useState
(
''
);
...
@@ -43,21 +43,22 @@ function Home() {
...
@@ -43,21 +43,22 @@ function Home() {
// variant="pills"
// variant="pills"
useEffect
(()
=>
{
useEffect
(()
=>
{
const
is
ChatR
=
Object
.
values
(
chatR
).
every
(
el
=>
Boolean
(
el
))
const
is
Room
=
Object
.
values
(
room
).
every
(
el
=>
Boolean
(
el
))
is
ChatR
?
setDisabled
(
false
)
:
setDisabled
(
true
)
is
Room
?
setDisabled
(
false
)
:
setDisabled
(
true
)
},
[
chatR
])
},
[
room
])
function
handleChange
(
event
)
{
function
handleChange
(
event
)
{
const
{
name
,
value
}
=
event
.
target
const
{
name
,
value
}
=
event
.
target
setChatR
({
...
chatR
,
[
name
]:
value
})
setRoom
({
...
room
,
[
name
]:
value
})
console
.
log
(
room
)
}
}
async
function
handleSubmit
(
event
)
{
async
function
handleSubmit
(
event
)
{
event
.
preventDefault
()
event
.
preventDefault
()
try
{
try
{
setError
(
''
)
setError
(
''
)
const
response
=
await
axios
.
post
(
'
chat/makeChat
'
,
chatR
)
const
response
=
await
axios
.
post
(
'
/room/makeRoom
'
,
room
)
set
ChatR
(
INIT_
CHATR
)
set
Room
(
INIT_
ROOM
)
}
catch
(
error
){
}
catch
(
error
){
catchErrors
(
error
,
setError
)
catchErrors
(
error
,
setError
)
}
}
...
@@ -124,13 +125,13 @@ function Home() {
...
@@ -124,13 +125,13 @@ function Home() {
<
Form
.
Group
as
=
{
Row
}
controlId
=
"
chatName
"
>
<
Form
.
Group
as
=
{
Row
}
controlId
=
"
chatName
"
>
<
Form
.
Label
column
sm
=
{
4
}
>
방
이름
<
/Form.Label
>
<
Form
.
Label
column
sm
=
{
4
}
>
방
이름
<
/Form.Label
>
<
Col
>
<
Col
>
<
Form
.
Control
name
=
'
n
ame
'
type
=
'
text
'
value
=
{
chatR
.
n
ame
}
onChange
=
{
handleChange
}
/
>
<
Form
.
Control
name
=
'
roomN
ame
'
type
=
'
text
'
value
=
{
room
.
roomN
ame
}
onChange
=
{
handleChange
}
/
>
<
/Col
>
<
/Col
>
<
/Form.Group
>
<
/Form.Group
>
<
Form
.
Group
as
=
{
Row
}
controlId
=
"
chatInterest
"
>
<
Form
.
Group
as
=
{
Row
}
controlId
=
"
chatInterest
"
>
<
Form
.
Label
column
sm
=
{
4
}
>
관심
분야
<
/Form.Label
>
<
Form
.
Label
column
sm
=
{
4
}
>
관심
분야
<
/Form.Label
>
<
Col
>
<
Col
>
<
Form
.
Control
as
=
"
select
"
defaultValue
=
"
Choose...
"
name
=
'
interest
'
type
=
'
text
'
value
=
{
chatR
.
interest
}
onChange
=
{
handleChange
}
>
<
Form
.
Control
as
=
"
select
"
defaultValue
=
"
Choose...
"
name
=
'
interest
'
type
=
'
text
'
value
=
{
room
.
interest
}
onChange
=
{
handleChange
}
>
<
option
>
Choose
...
<
/option
>
<
option
>
Choose
...
<
/option
>
<
option
>
과학
<
/option
>
<
option
>
과학
<
/option
>
<
option
>
수학
<
/option
>
<
option
>
수학
<
/option
>
...
@@ -146,13 +147,13 @@ function Home() {
...
@@ -146,13 +147,13 @@ function Home() {
<
Col
>
<
Col
>
<
Form
.
Check
<
Form
.
Check
type
=
"
checkbox
"
type
=
"
checkbox
"
checked
=
{
chatR
.
isOpen
}
checked
=
{
room
.
isOpen
}
name
=
'
isOpen
'
name
=
'
isOpen
'
onChange
=
{()
=>
set
ChatR
({
...
chatR
,
isOpen
:
!
chatR
.
isOpen
})}
/
>
onChange
=
{()
=>
set
Room
({
...
room
,
isOpen
:
!
room
.
isOpen
})}
/
>
<
/Col
>
<
/Col
>
<
/Form.Group
>
<
/Form.Group
>
{
{
(
chatR
.
isOpen
)
(
room
.
isOpen
)
?
(
<
p
><
b
>
공개방
<
/b>으로 개설되어 공개방 목록에 공개되며, 코드를 공유하여 참가할 수도 있습니다.</
p
>
)
?
(
<
p
><
b
>
공개방
<
/b>으로 개설되어 공개방 목록에 공개되며, 코드를 공유하여 참가할 수도 있습니다.</
p
>
)
:
(
<
p
><
b
>
비밀방
<
/b>으로 개설되며, 참여자들에게 코드를 공유해야합니다.</
p
>
)
:
(
<
p
><
b
>
비밀방
<
/b>으로 개설되며, 참여자들에게 코드를 공유해야합니다.</
p
>
)
}
}
...
...
server/controllers/
chat
.controller.js
→
server/controllers/
room
.controller.js
View file @
fd82fdde
// import { useState } from 'react'
import
Room
from
"
../models/Room.js
"
import
Chat
from
"
../models/Chat.js
"
import
{
customAlphabet
}
from
'
nanoid
'
import
{
customAlphabet
}
from
'
nanoid
'
import
isLength
from
'
validator/lib/isLength.js
'
import
isLength
from
'
validator/lib/isLength.js
'
const
nanoid
=
customAlphabet
(
'
1234567890abcdef
'
,
10
)
const
nanoid
=
customAlphabet
(
'
1234567890abcdef
'
,
10
)
const
makeChat
=
async
(
req
,
res
)
=>
{
const
makeRoom
=
async
(
req
,
res
)
=>
{
const
{
name
,
interest
,
isOpen
}
=
req
.
body
;
console
.
log
(
req
.
body
)
const
{
roomName
,
interest
,
isOpen
}
=
req
.
body
;
console
.
log
(
roomName
,
interest
,
isOpen
)
const
roomId
=
nanoid
()
const
roomId
=
nanoid
()
const
chat
=
await
Chat
.
findOne
({
roomId
})
const
room
=
await
Room
.
findOne
({
roomId
})
while
(
chat
)
{
while
(
room
)
{
roomId
=
nanoid
()
roomId
=
nanoid
()
chat
=
await
Chat
.
findOne
({
roomId
})
room
=
await
Room
.
findOne
({
roomId
})
}
}
try
{
try
{
if
(
!
isLength
(
n
ame
,
{
min
:
3
,
max
:
20
}))
{
if
(
!
isLength
(
roomN
ame
,
{
min
:
3
,
max
:
20
}))
{
return
res
.
status
(
422
).
send
(
'
채팅방의 이름은 3-20자여야 합니다.
'
)
return
res
.
status
(
422
).
send
(
'
채팅방의 이름은 3-20자여야 합니다.
'
)
}
else
if
(
interest
==
'
Choose...
'
||
interest
==
''
){
}
else
if
(
interest
==
'
Choose...
'
||
interest
==
''
){
return
res
.
status
(
422
).
send
(
'
분야를 반드시 선택하여야 합니다.
'
)
return
res
.
status
(
422
).
send
(
'
분야를 반드시 선택하여야 합니다.
'
)
}
}
const
new
Chat
=
await
new
Chat
({
const
new
Room
=
await
new
Room
({
roomId
,
roomId
,
n
ame
,
roomN
ame
,
interest
,
interest
,
isOpen
isOpen
}).
save
()
}).
save
()
console
.
log
(
new
Chat
)
console
.
log
(
new
Room
)
res
.
json
(
new
Chat
)
res
.
json
(
new
Room
)
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
error
)
console
.
log
(
error
)
res
.
status
(
500
).
send
(
'
방생성 에러
'
)
res
.
status
(
500
).
send
(
'
방생성 에러
'
)
}
}
}
}
const
hello
=
(
req
,
res
)
=>
{
export
default
{
makeRoom
}
res
.
send
(
'
Hello from users controller
'
)
\ No newline at end of file
}
export
default
{
makeChat
,
hello
}
\ No newline at end of file
server/models/
chat
.js
→
server/models/
Room
.js
View file @
fd82fdde
...
@@ -2,13 +2,13 @@ import mongoose from 'mongoose'
...
@@ -2,13 +2,13 @@ import mongoose from 'mongoose'
const
{
String
}
=
mongoose
.
Schema
.
Types
const
{
String
}
=
mongoose
.
Schema
.
Types
const
Chat
Schema
=
new
mongoose
.
Schema
({
const
Room
Schema
=
new
mongoose
.
Schema
({
roomId
:
{
roomId
:
{
type
:
String
,
type
:
String
,
// default:() => nanoid(),
// default:() => nanoid(),
unique
:
true
unique
:
true
},
},
n
ame
:
{
roomN
ame
:
{
type
:
String
,
type
:
String
,
required
:
true
,
required
:
true
,
},
},
...
@@ -25,4 +25,4 @@ const ChatSchema = new mongoose.Schema({
...
@@ -25,4 +25,4 @@ const ChatSchema = new mongoose.Schema({
timestamps
:
true
timestamps
:
true
})
})
export
default
mongoose
.
models
.
Chat
||
mongoose
.
model
(
'
Chat
'
,
ChatSchema
)
export
default
mongoose
.
models
.
Room
||
mongoose
.
model
(
'
Room
'
,
RoomSchema
)
\ No newline at end of file
\ No newline at end of file
server/routes/chat.routers.js
deleted
100644 → 0
View file @
1b0c048c
import
express
from
'
express
'
import
chatCtrl
from
'
../controllers/chat.controller.js
'
const
router
=
express
.
Router
()
router
.
route
(
'
/chat/makeChat
'
)
.
post
(
chatCtrl
.
makeChat
)
.
get
(
chatCtrl
.
hello
)
export
default
router
\ No newline at end of file
server/routes/room.routers.js
0 → 100644
View file @
fd82fdde
import
express
from
'
express
'
import
roomCtrl
from
'
../controllers/room.controller.js
'
const
router
=
express
.
Router
()
router
.
route
(
'
/room/makeRoom
'
)
.
post
(
roomCtrl
.
makeRoom
)
export
default
router
\ No newline at end of file
server/server.js
View file @
fd82fdde
import
express
from
'
express
'
import
express
from
'
express
'
import
connectDb
from
'
./utils/connectDb.js
'
import
connectDb
from
'
./utils/connectDb.js
'
import
chat
Router
from
'
./routes/
chat
.routers.js
'
import
room
Router
from
'
./routes/
room
.routers.js
'
import
cors
from
"
cors
"
import
cors
from
"
cors
"
import
bodyParser
from
"
body-parser
"
import
bodyParser
from
"
body-parser
"
import
http
from
'
http
'
import
http
from
'
http
'
...
@@ -11,7 +11,7 @@ connectDb()
...
@@ -11,7 +11,7 @@ connectDb()
const
app
=
express
()
const
app
=
express
()
app
.
use
(
express
.
json
())
app
.
use
(
express
.
json
())
app
.
use
(
chat
Router
)
app
.
use
(
room
Router
)
const
server
=
http
.
createServer
(
app
);
const
server
=
http
.
createServer
(
app
);
...
...
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