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
48536fea
Commit
48536fea
authored
Jan 18, 2021
by
우지원
Browse files
e
parent
6bcffb88
Changes
7
Show whitespace changes
Inline
Side-by-side
client/src/Components/ClosedList.js
View file @
48536fea
...
...
@@ -9,6 +9,8 @@ function ClosedList(props) {
getClosedList
();
},
[]);
const
userId
=
sessionStorage
.
getItem
(
'
userId
'
);
async
function
getClosedList
()
{
let
res
=
await
axios
.
get
(
'
/room/closedlist
'
)
console
.
log
(
'
가져온거
'
,
res
)
...
...
client/src/Components/OpenList.js
View file @
48536fea
import
React
,
{
useState
}
from
'
react
'
import
axios
from
'
axios
'
;
import
React
,
{
useEffect
,
useState
}
from
'
react
'
import
{
ListGroup
}
from
'
react-bootstrap
'
;
function
OpenList
(
props
)
{
const
[
list
,
setList
]
=
useState
([
{
room
:
'
테스트 방3
'
,
memnum
:
7
,
admin
:
'
가영2
'
},
{
room
:
'
테스트 방4
'
,
memnum
:
2
,
admin
:
'
수현2
'
}]
);
const
[
list
,
setList
]
=
useState
([]);
useEffect
(()
=>
{
getOpenList
();
},
[]);
async
function
getOpenList
()
{
let
res
=
await
axios
.
get
(
'
/room/Openlist
'
)
console
.
log
(
'
가져온거
'
,
res
)
setList
(
res
.
data
)
}
function
enterChatroomCH
(
e
)
{
console
.
log
(
e
.
target
.
name
)
console
.
log
(
e
.
target
)
const
roomName
=
e
.
target
.
name
props
.
enterChatroom
(
roomName
)
// 각각의 room으로 들어가도록 설정해야 함
props
.
setRoomName
(
roomName
)
// props.clearChat()
}
//user.hasOwnProperty('이름');
return
(
<
div
>
{
list
.
map
((
list
,
index
)
=>
{
list
.
map
((
item
,
index
)
=>
<
ListGroup
key
=
{
index
}
>
<
ListGroup
.
Item
action
onClick
=
{
enterChatroomCH
}
name
=
{
list
.
room
}
>
<
h2
>
{
list
.
room
}
<
/h2
>
<
ListGroup
.
Item
action
onClick
=
{
enterChatroomCH
}
name
=
{
item
.
room
Name
}
>
{
item
.
roomName
}
<
/ListGroup.Item
>
<
/ListGroup
>
)}
...
...
client/src/Pages/HomePage.js
View file @
48536fea
...
...
@@ -38,6 +38,7 @@ function Home() {
const
handleShow2
=
()
=>
setShow2
(
true
);
const
moderator
=
sessionStorage
.
getItem
(
'
userId
'
);
const
member
=
sessionStorage
.
getItem
(
'
userId
'
);
useEffect
(()
=>
{
const
isRoom
=
Object
.
values
(
room
).
every
(
el
=>
Boolean
(
el
))
...
...
@@ -46,7 +47,7 @@ function Home() {
function
handleChange
(
event
)
{
const
{
name
,
value
}
=
event
.
target
setRoom
({
...
room
,
[
name
]:
value
,
moderator
})
setRoom
({
...
room
,
[
name
]:
value
,
moderator
,
member
})
//console.log(room)
}
...
...
server/controllers/room.controller.js
View file @
48536fea
...
...
@@ -6,8 +6,8 @@ const nanoid = customAlphabet('1234567890abcdef', 10)
const
makeRoom
=
async
(
req
,
res
)
=>
{
console
.
log
(
req
.
body
)
const
{
roomName
,
interest
,
isOpen
,
moderator
}
=
req
.
body
;
console
.
log
(
roomName
,
interest
,
isOpen
,
moderator
)
const
{
roomName
,
interest
,
isOpen
,
moderator
,
member
}
=
req
.
body
;
console
.
log
(
roomName
,
interest
,
isOpen
,
moderator
,
member
)
const
roomId
=
nanoid
()
const
room
=
await
Room
.
findOne
({
roomId
})
...
...
@@ -23,11 +23,12 @@ const makeRoom = async (req, res) => {
return
res
.
status
(
422
).
send
(
'
분야를 반드시 선택하여야 합니다.
'
)
}
const
newRoom
=
await
new
Room
({
roomId
,
roomName
,
interest
,
isOpen
,
moderator
,
roomId
,
member
,
}).
save
()
console
.
log
(
newRoom
)
res
.
json
(
newRoom
)
...
...
@@ -40,6 +41,17 @@ const makeRoom = async (req, res) => {
const
getClosedList
=
async
(
req
,
res
)
=>
{
try
{
let
list
=
await
Room
.
find
({
isOpen
:
false
})
console
.
log
({
userId
})
console
.
log
(
'
list가져오기
'
,
list
)
return
res
.
json
(
list
)
}
catch
(
error
)
{
res
.
status
(
500
).
send
(
'
리스트 불러오기를 실패하였습니다!
'
)
}
}
const
getOpenList
=
async
(
req
,
res
)
=>
{
try
{
let
list
=
await
Room
.
find
({
isOpen
:
true
})
console
.
log
(
'
list가져오기
'
,
list
)
return
res
.
json
(
list
)
}
catch
(
error
)
{
...
...
@@ -47,4 +59,4 @@ const getClosedList = async (req, res) => {
}
}
export
default
{
makeRoom
,
getClosedList
}
export
default
{
makeRoom
,
getClosedList
,
getOpenList
}
server/models/Room.js
View file @
48536fea
import
mongoose
from
'
mongoose
'
const
{
String
}
=
mongoose
.
Schema
.
Types
const
{
Array
}
=
mongoose
.
Schema
.
Types
const
RoomSchema
=
new
mongoose
.
Schema
({
roomId
:
{
type
:
String
,
// default:() => nanoid(),
unique
:
true
},
roomName
:
{
type
:
String
,
required
:
true
,
...
...
@@ -15,18 +21,15 @@ const RoomSchema = new mongoose.Schema({
isOpen
:
{
type
:
Boolean
,
required
:
true
,
default
:
'
user
'
,
enum
:
[
'
user
'
,
'
admin
'
,
'
root
'
]
},
moderator
:
{
type
:
String
,
required
:
true
,
},
roomId
:
{
type
:
String
,
// default:() => nanoid(),
unique
:
true
},
member
:
{
type
:
Array
,
required
:
true
,
}
},
{
timestamps
:
true
})
...
...
server/models/User.js
View file @
48536fea
...
...
@@ -3,7 +3,6 @@
import
mongoose
from
'
mongoose
'
const
{
String
}
=
mongoose
.
Schema
.
Types
// const { Array } = mongoose.Schema.Types
//원래 java의 string이 아니라 mongoose의 string을 쓰기 위해 불러옴.
//object의 id를 쓸때에도 추가시켜줘야됨.
...
...
server/routes/room.routers.js
View file @
48536fea
...
...
@@ -8,4 +8,8 @@ router.route('/room/makeRoom')
router
.
route
(
'
/room/closedlist
'
)
.
get
(
roomCtrl
.
getClosedList
)
router
.
route
(
'
/room/openlist
'
)
.
get
(
roomCtrl
.
getOpenList
)
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