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

e

parent 6bcffb88
......@@ -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)
......
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.roomName}>
{item.roomName}
</ListGroup.Item>
</ListGroup>
)}
......
......@@ -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)
}
......
......@@ -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 }
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
})
......
......@@ -3,7 +3,6 @@
import mongoose from 'mongoose'
const { String } = mongoose.Schema.Types
// const { Array } = mongoose.Schema.Types
//원래 java의 string이 아니라 mongoose의 string을 쓰기 위해 불러옴.
//object의 id를 쓸때에도 추가시켜줘야됨.
......
......@@ -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
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