Commit db5383e3 authored by Choi Ga Young's avatar Choi Ga Young
Browse files

채팅방(x)

parent 645bf09c
import React, { useState } from 'react'
import React, { useState, useEffect } from 'react'
import { ListGroup, Row, Col } from 'react-bootstrap';
import axios from 'axios'
function ClosedList(props) {
const [list, setList] = useState([
{ room: '테스트 방1', memnum: 5, admin: '가영' },
{ room: '테스트 방2', memnum: 4, admin: '수현' }]
);
const [list, setList] = useState([]);
useEffect(() => {
getClosedList();
}, []);
async function getClosedList() {
let res = await axios.get('/room/closedlist')
console.log('가져온거', res)
setList(res.data)
}
function enterChatroomCH(e) {
console.log(e.target.name)
......@@ -20,8 +28,8 @@ function ClosedList(props) {
<div>
{list.map((item, index) =>
<ListGroup key={index}>
<ListGroup.Item action onClick={enterChatroomCH} name={item.room}>
{item.room}
<ListGroup.Item action onClick={enterChatroomCH} name={item.roomName}>
{item.roomName}
</ListGroup.Item>
</ListGroup>
)}
......
......@@ -80,6 +80,8 @@ function Home() {
})
}, [singleChat])
return (
<>
<Menu />
......
......@@ -19,7 +19,7 @@ const makeRoom = async (req, res) => {
try {
if (!isLength(roomName, { min: 3, max: 20 })) {
return res.status(422).send('채팅방의 이름은 3-20자여야 합니다.')
} else if (interest=='Choose...' || interest==''){
} else if (interest == 'Choose...' || interest == '') {
return res.status(422).send('분야를 반드시 선택하여야 합니다.')
}
const newRoom = await new Room({
......@@ -36,4 +36,14 @@ const makeRoom = async (req, res) => {
}
}
export default { makeRoom }
\ No newline at end of file
const getClosedList = async (req, res) => {
try {
let list = await Room.find({ isOpen: false })
console.log('list가져오기', list)
return res.json(list)
} catch (error) {
res.status(500).send('리스트 불러오기를 실패하였습니다!')
}
}
export default { makeRoom, getClosedList }
\ No newline at end of file
......@@ -2,8 +2,7 @@ import User from "../models/User.js"
import isLength from 'validator/lib/isLength.js'
import isEmail from 'validator/lib/isEmail.js'
import bcrypt from "bcryptjs";
import jwt from 'jsonwebtoken'
import config from "../config.js"
const signup = async (req, res) => {
......@@ -43,10 +42,7 @@ const signup = async (req, res) => {
res.status(500).send('회원가입 에러발생하였습니다.')
}
}
const hello = async (req, res) => {
let users = await User.find().select('name nickname email _id').exec()
return res.json(users)
}
const logineduser = async (req, res) => {
try {
......@@ -59,12 +55,12 @@ const logineduser = async (req, res) => {
const changenick = async (req, res) => {
try {
const newnick = req.body.nickname
await User.update({ 'username': req.body.username }, { 'nickname': newnick })
await User.updateOne({ 'username': req.body.username }, { 'nickname': newnick })
} catch (error) {
alert('올바르지 못한 접근입니다.')
}
}
export default { signup, hello, logineduser, changenick }
export default { signup, logineduser, changenick }
// {} : 객체로 return함
\ No newline at end of file
......@@ -5,4 +5,7 @@ const router = express.Router()
router.route('/room/makeRoom')
.post(roomCtrl.makeRoom)
router.route('/room/closedlist')
.get(roomCtrl.getClosedList)
export default router
\ No newline at end of file
......@@ -6,7 +6,6 @@ const router = express.Router()
router.route('/users/signup')
.post(userCtrl.signup)
.get(userCtrl.hello)
router.route(`/users/:userId`)
.post(userCtrl.logineduser)
......
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