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
Hide whitespace changes
Inline
Side-by-side
client/src/Pages/HomePage.js
View file @
fd82fdde
...
...
@@ -17,8 +17,8 @@ import Chat from "../Components/Chat";
const
socket
=
io
();
const
INIT_
CHATR
=
{
n
ame
:
''
,
const
INIT_
ROOM
=
{
roomN
ame
:
''
,
interest
:
''
,
isOpen
:
false
}
...
...
@@ -27,7 +27,7 @@ function Home() {
const
[
show
,
setShow
]
=
useState
(
false
);
const
[
show2
,
setShow2
]
=
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
[
error
,
setError
]
=
useState
(
''
);
...
...
@@ -43,21 +43,22 @@ function Home() {
// variant="pills"
useEffect
(()
=>
{
const
is
ChatR
=
Object
.
values
(
chatR
).
every
(
el
=>
Boolean
(
el
))
is
ChatR
?
setDisabled
(
false
)
:
setDisabled
(
true
)
},
[
chatR
])
const
is
Room
=
Object
.
values
(
room
).
every
(
el
=>
Boolean
(
el
))
is
Room
?
setDisabled
(
false
)
:
setDisabled
(
true
)
},
[
room
])
function
handleChange
(
event
)
{
const
{
name
,
value
}
=
event
.
target
setChatR
({
...
chatR
,
[
name
]:
value
})
setRoom
({
...
room
,
[
name
]:
value
})
console
.
log
(
room
)
}
async
function
handleSubmit
(
event
)
{
event
.
preventDefault
()
try
{
setError
(
''
)
const
response
=
await
axios
.
post
(
'
chat/makeChat
'
,
chatR
)
set
ChatR
(
INIT_
CHATR
)
const
response
=
await
axios
.
post
(
'
/room/makeRoom
'
,
room
)
set
Room
(
INIT_
ROOM
)
}
catch
(
error
){
catchErrors
(
error
,
setError
)
}
...
...
@@ -124,13 +125,13 @@ function Home() {
<
Form
.
Group
as
=
{
Row
}
controlId
=
"
chatName
"
>
<
Form
.
Label
column
sm
=
{
4
}
>
방
이름
<
/Form.Label
>
<
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
>
<
/Form.Group
>
<
Form
.
Group
as
=
{
Row
}
controlId
=
"
chatInterest
"
>
<
Form
.
Label
column
sm
=
{
4
}
>
관심
분야
<
/Form.Label
>
<
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
>
과학
<
/option
>
<
option
>
수학
<
/option
>
...
...
@@ -146,13 +147,13 @@ function Home() {
<
Col
>
<
Form
.
Check
type
=
"
checkbox
"
checked
=
{
chatR
.
isOpen
}
checked
=
{
room
.
isOpen
}
name
=
'
isOpen
'
onChange
=
{()
=>
set
ChatR
({
...
chatR
,
isOpen
:
!
chatR
.
isOpen
})}
/
>
onChange
=
{()
=>
set
Room
({
...
room
,
isOpen
:
!
room
.
isOpen
})}
/
>
<
/Col
>
<
/Form.Group
>
{
(
chatR
.
isOpen
)
(
room
.
isOpen
)
?
(
<
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
Chat
from
"
../models/Chat.js
"
import
Room
from
"
../models/Room.js
"
import
{
customAlphabet
}
from
'
nanoid
'
import
isLength
from
'
validator/lib/isLength.js
'
const
nanoid
=
customAlphabet
(
'
1234567890abcdef
'
,
10
)
const
makeChat
=
async
(
req
,
res
)
=>
{
const
{
name
,
interest
,
isOpen
}
=
req
.
body
;
const
makeRoom
=
async
(
req
,
res
)
=>
{
console
.
log
(
req
.
body
)
const
{
roomName
,
interest
,
isOpen
}
=
req
.
body
;
console
.
log
(
roomName
,
interest
,
isOpen
)
const
roomId
=
nanoid
()
const
chat
=
await
Chat
.
findOne
({
roomId
})
while
(
chat
)
{
const
room
=
await
Room
.
findOne
({
roomId
})
while
(
room
)
{
roomId
=
nanoid
()
chat
=
await
Chat
.
findOne
({
roomId
})
room
=
await
Room
.
findOne
({
roomId
})
}
try
{
if
(
!
isLength
(
n
ame
,
{
min
:
3
,
max
:
20
}))
{
if
(
!
isLength
(
roomN
ame
,
{
min
:
3
,
max
:
20
}))
{
return
res
.
status
(
422
).
send
(
'
채팅방의 이름은 3-20자여야 합니다.
'
)
}
else
if
(
interest
==
'
Choose...
'
||
interest
==
''
){
return
res
.
status
(
422
).
send
(
'
분야를 반드시 선택하여야 합니다.
'
)
}
const
new
Chat
=
await
new
Chat
({
const
new
Room
=
await
new
Room
({
roomId
,
n
ame
,
roomN
ame
,
interest
,
isOpen
}).
save
()
console
.
log
(
new
Chat
)
res
.
json
(
new
Chat
)
console
.
log
(
new
Room
)
res
.
json
(
new
Room
)
}
catch
(
error
)
{
console
.
log
(
error
)
res
.
status
(
500
).
send
(
'
방생성 에러
'
)
}
}
const
hello
=
(
req
,
res
)
=>
{
res
.
send
(
'
Hello from users controller
'
)
}
export
default
{
makeChat
,
hello
}
\ No newline at end of file
export
default
{
makeRoom
}
\ 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'
const
{
String
}
=
mongoose
.
Schema
.
Types
const
Chat
Schema
=
new
mongoose
.
Schema
({
const
Room
Schema
=
new
mongoose
.
Schema
({
roomId
:
{
type
:
String
,
// default:() => nanoid(),
unique
:
true
},
n
ame
:
{
roomN
ame
:
{
type
:
String
,
required
:
true
,
},
...
...
@@ -25,4 +25,4 @@ const ChatSchema = new mongoose.Schema({
timestamps
:
true
})
export
default
mongoose
.
models
.
Chat
||
mongoose
.
model
(
'
Chat
'
,
ChatSchema
)
\ No newline at end of file
export
default
mongoose
.
models
.
Room
||
mongoose
.
model
(
'
Room
'
,
RoomSchema
)
\ 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
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
bodyParser
from
"
body-parser
"
import
http
from
'
http
'
...
...
@@ -11,7 +11,7 @@ connectDb()
const
app
=
express
()
app
.
use
(
express
.
json
())
app
.
use
(
chat
Router
)
app
.
use
(
room
Router
)
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