Commit 48536fea authored by 우지원's avatar 우지원
Browse files

e

parent 6bcffb88
...@@ -9,6 +9,8 @@ function ClosedList(props) { ...@@ -9,6 +9,8 @@ function ClosedList(props) {
getClosedList(); getClosedList();
}, []); }, []);
const userId = sessionStorage.getItem('userId');
async function getClosedList() { async function getClosedList() {
let res = await axios.get('/room/closedlist') let res = await axios.get('/room/closedlist')
console.log('가져온거', res) console.log('가져온거', res)
......
import React, { useState } from 'react' import axios from 'axios';
import React, { useEffect, useState } from 'react'
import { ListGroup } from 'react-bootstrap'; import { ListGroup } from 'react-bootstrap';
function OpenList(props) { function OpenList(props) {
const [list, setList] = useState([ const [list, setList] = useState([]);
{ room: '테스트 방3', memnum: 7, admin: '가영2' },
{ room: '테스트 방4', memnum: 2, admin: '수현2' }] useEffect(() => {
); getOpenList();
}, []);
async function getOpenList() {
let res = await axios.get('/room/Openlist')
console.log('가져온거', res)
setList(res.data)
}
function enterChatroomCH(e) { function enterChatroomCH(e) {
console.log(e.target.name)
console.log(e.target)
const roomName = e.target.name const roomName = e.target.name
props.enterChatroom(roomName) // 각각의 room으로 들어가도록 설정해야 함 props.enterChatroom(roomName) // 각각의 room으로 들어가도록 설정해야 함
props.setRoomName(roomName) props.setRoomName(roomName)
// props.clearChat() // props.clearChat()
} }
//user.hasOwnProperty('이름');
return ( return (
<div> <div>
{list.map((list, index) => {list.map((item, index) =>
<ListGroup key={index}> <ListGroup key={index}>
<ListGroup.Item action onClick={enterChatroomCH} name={list.room}> <ListGroup.Item action onClick={enterChatroomCH} name={item.roomName}>
<h2>{list.room}</h2> {item.roomName}
</ListGroup.Item> </ListGroup.Item>
</ListGroup> </ListGroup>
)} )}
......
...@@ -38,6 +38,7 @@ function Home() { ...@@ -38,6 +38,7 @@ function Home() {
const handleShow2 = () => setShow2(true); const handleShow2 = () => setShow2(true);
const moderator = sessionStorage.getItem('userId'); const moderator = sessionStorage.getItem('userId');
const member = sessionStorage.getItem('userId');
useEffect(() => { useEffect(() => {
const isRoom = Object.values(room).every(el => Boolean(el)) const isRoom = Object.values(room).every(el => Boolean(el))
...@@ -46,7 +47,7 @@ function Home() { ...@@ -46,7 +47,7 @@ function Home() {
function handleChange(event) { function handleChange(event) {
const { name, value } = event.target const { name, value } = event.target
setRoom({ ...room, [name]: value, moderator }) setRoom({ ...room, [name]: value, moderator, member })
//console.log(room) //console.log(room)
} }
...@@ -90,7 +91,7 @@ function Home() { ...@@ -90,7 +91,7 @@ function Home() {
setSingleChat(msg) setSingleChat(msg)
}) })
}, [singleChat]) }, [singleChat])
return ( return (
<> <>
<Menu /> <Menu />
......
...@@ -6,8 +6,8 @@ const nanoid = customAlphabet('1234567890abcdef', 10) ...@@ -6,8 +6,8 @@ const nanoid = customAlphabet('1234567890abcdef', 10)
const makeRoom = async (req, res) => { const makeRoom = async (req, res) => {
console.log(req.body) console.log(req.body)
const { roomName, interest, isOpen, moderator } = req.body; const { roomName, interest, isOpen, moderator, member } = req.body;
console.log(roomName, interest, isOpen, moderator) console.log(roomName, interest, isOpen, moderator, member)
const roomId = nanoid() const roomId = nanoid()
const room = await Room.findOne({ roomId }) const room = await Room.findOne({ roomId })
...@@ -23,11 +23,12 @@ const makeRoom = async (req, res) => { ...@@ -23,11 +23,12 @@ const makeRoom = async (req, res) => {
return res.status(422).send('분야를 반드시 선택하여야 합니다.') return res.status(422).send('분야를 반드시 선택하여야 합니다.')
} }
const newRoom = await new Room({ const newRoom = await new Room({
roomId,
roomName, roomName,
interest, interest,
isOpen, isOpen,
moderator, moderator,
roomId, member,
}).save() }).save()
console.log(newRoom) console.log(newRoom)
res.json(newRoom) res.json(newRoom)
...@@ -40,6 +41,17 @@ const makeRoom = async (req, res) => { ...@@ -40,6 +41,17 @@ const makeRoom = async (req, res) => {
const getClosedList = async (req, res) => { const getClosedList = async (req, res) => {
try { try {
let list = await Room.find({ isOpen: false }) 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) console.log('list가져오기', list)
return res.json(list) return res.json(list)
} catch (error) { } catch (error) {
...@@ -47,4 +59,4 @@ const getClosedList = async (req, res) => { ...@@ -47,4 +59,4 @@ const getClosedList = async (req, res) => {
} }
} }
export default { makeRoom, getClosedList } export default { makeRoom, getClosedList, getOpenList }
import mongoose from 'mongoose' import mongoose from 'mongoose'
const {String} = mongoose.Schema.Types const {String} = mongoose.Schema.Types
const {Array} = mongoose.Schema.Types
const RoomSchema = new mongoose.Schema({ const RoomSchema = new mongoose.Schema({
roomId: {
type: String,
// default:() => nanoid(),
unique: true
},
roomName: { roomName: {
type: String, type: String,
required: true, required: true,
...@@ -15,18 +21,15 @@ const RoomSchema = new mongoose.Schema({ ...@@ -15,18 +21,15 @@ const RoomSchema = new mongoose.Schema({
isOpen: { isOpen: {
type: Boolean, type: Boolean,
required: true, required: true,
default: 'user',
enum: ['user', 'admin', 'root']
}, },
moderator: { moderator: {
type: String, type: String,
required: true, required: true,
}, },
roomId: { member: {
type: String, type: Array,
// default:() => nanoid(), required: true,
unique: true }
},
}, { }, {
timestamps: true timestamps: true
}) })
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
import mongoose from 'mongoose' import mongoose from 'mongoose'
const { String } = mongoose.Schema.Types const { String } = mongoose.Schema.Types
// const { Array } = mongoose.Schema.Types
//원래 java의 string이 아니라 mongoose의 string을 쓰기 위해 불러옴. //원래 java의 string이 아니라 mongoose의 string을 쓰기 위해 불러옴.
//object의 id를 쓸때에도 추가시켜줘야됨. //object의 id를 쓸때에도 추가시켜줘야됨.
......
...@@ -8,4 +8,8 @@ router.route('/room/makeRoom') ...@@ -8,4 +8,8 @@ router.route('/room/makeRoom')
router.route('/room/closedlist') router.route('/room/closedlist')
.get(roomCtrl.getClosedList) .get(roomCtrl.getClosedList)
router.route('/room/openlist')
.get(roomCtrl.getOpenList)
export default router export default router
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment