Commit a27376e3 authored by Kim, Chaerin's avatar Kim, Chaerin
Browse files

Merge remote-tracking branch 'origin/woojiweon2'

parents 12c642ee d7bf440f
...@@ -14078,9 +14078,9 @@ ...@@ -14078,9 +14078,9 @@
"integrity": "sha512-4WK/bYZmj8xLr+HUCODHGF1ZFzsYffasLUgEiMBY4fgtltdO6B4WJtlSbPaDTLpYTcGVwM2qLnFTICEcNxs3kA==" "integrity": "sha512-4WK/bYZmj8xLr+HUCODHGF1ZFzsYffasLUgEiMBY4fgtltdO6B4WJtlSbPaDTLpYTcGVwM2qLnFTICEcNxs3kA=="
}, },
"tar": { "tar": {
"version": "6.1.0", "version": "6.1.5",
"resolved": "https://registry.npmjs.org/tar/-/tar-6.1.0.tgz", "resolved": "https://registry.npmjs.org/tar/-/tar-6.1.5.tgz",
"integrity": "sha512-DUCttfhsnLCjwoDoFcI+B2iJgYa93vBnDUATYEeRx6sntCTdN01VnqsIuTlALXla/LWooNg0yEGeB+Y8WdFxGA==", "integrity": "sha512-FiK6MQyyaqd5vHuUjbg/NpO8BuEGeSXcmlH7Pt/JkugWS8s0w8nKybWjHDJiwzCAIKZ66uof4ghm4tBADjcqRA==",
"requires": { "requires": {
"chownr": "^2.0.0", "chownr": "^2.0.0",
"fs-minipass": "^2.0.0", "fs-minipass": "^2.0.0",
......
import axios from "axios"; import axios from "axios";
const getRoom = async (id) => { const getRoom = async (id) => {
const { data } = await axios.post('/api/room/getRoom', id); const { data } = await axios.post("/api/room/getRoom", id);
return data; return data;
}; };
const exitRoom = async (ID) => { const exitRoom = async (ID) => {
const { data } = await axios.delete(`/api/room/exitRoom/${ID.id}/${ID.roomId}`); const { data } = await axios.delete(
`/api/room/exitRoom/${ID.id}/${ID.roomId}`
);
return data; return data;
}; };
...@@ -21,10 +23,33 @@ const join = async (payload) => { ...@@ -21,10 +23,33 @@ const join = async (payload) => {
}; };
const changename = async (payload) => { const changename = async (payload) => {
const { data } = await axios.put("/api/room/changename", payload) const { data } = await axios.put("/api/room/changename", payload);
return data; return data;
} };
const roomApi = { getRoom, exitRoom, create, join, changename }; const joinChannel = async (payload) => {
const { data } = await axios.post("/api/room/joinChannel", payload);
return data;
};
const doubleJoin = async (payload) => {
const { data } = await axios.post("/api/room/doubleJoin", payload);
return data;
};
// const makeChannel = async (payload) => {
// const { data } = await axios.post("/api/room/makeChannel", payload);
// return data;
// };
const roomApi = {
getRoom,
exitRoom,
create,
join,
changename,
joinChannel,
doubleJoin,
};
export default roomApi; export default roomApi;
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import { Link } from 'react-router-dom' import { Link, Redirect } from 'react-router-dom'
import userApi from '../apis/user.api' import userApi from '../apis/user.api'
import catchErrors from '../context/catchError' import catchErrors from '../context/catchError'
import { handleLogin } from '../context/auth' import { handleLogin } from '../context/auth'
...@@ -46,7 +46,7 @@ const Login = () => { ...@@ -46,7 +46,7 @@ const Login = () => {
} }
if (success) { if (success) {
alert('로그인 되었습니다') alert('로그인 되었습니다')
window.location.href = `/user/${id}` return <Redirect to={`/user/${id}`} />;
} }
const { email, password } = user const { email, password } = user
......
import { Link } from 'react-router-dom' import { Link, useParams } from 'react-router-dom'
import React, { useState } from 'react'; import React, { useEffect, useState } from 'react';
import RightHamburger from './RightHamburger'; import RightHamburger from './RightHamburger';
import roomApi from '../../apis/room.api';
import catchErrors from '../../context/catchError';
import userApi from '../../apis/user.api';
const INIT_CHANNEL = {
channelName: "",
joinUser: [],
};
const ChannelList = () => { const ChannelList = () => {
const { roomId } = useParams();
const [error, setError] = useState("");
const [channel, setChannel] = useState([INIT_CHANNEL]);
const id = localStorage.getItem('user'); const id = localStorage.getItem('user');
async function getChannel(roomId) {
try {
const data = await roomApi.getRoom([roomId]);
const Channel = data[0].channel;
const channelList = [];
for (const prop in Channel) {
for (const el in Channel[prop]) {
channelList.push({
channelName: el,
joinUser: Channel[prop][el],
});
}
}
setChannel(channelList);
} catch (error) {
catchErrors(error, setError);
}
}
async function exitChannel() {
try {
const data = await userApi.getUser(id);
const A = doubleJoinCheck(data.name)
if (A) {
await roomApi.doubleJoin({ roomId: roomId, index1: A.index1, index2: A.index2, joinChName: A.joinChName })
}
} catch (error) {
catchErrors(error, setError);
}
}
function doubleJoinCheck(e) {
for (const index in channel) {
for (const el in channel[index].joinUser) {
if (channel[index].joinUser[el] === e) {
const doublejoinCh = channel[index].channelName
const A = {
index1: index,
index2: el,
joinChName: doublejoinCh,
}
return A
}
}
}
}
useEffect(() => {
getChannel(roomId);
}, [roomId])
return ( return (
<div> <div>
<nav className="navbar navbar-light "> <nav className="navbar navbar-light ">
<div className="col-2"></div> <div className="col-2"></div>
<div> <div onClick={exitChannel}>
<Link to={`/user/${id}`}> <Link to={`/user/${id}`}>
<img src="/BORA.png" style={{ width: '160px' }} /> <img src="/BORA.png" style={{ width: '160px' }} />
</Link> </Link>
......
import { useState } from 'react'
import { Link, useParams } from 'react-router-dom' import { Link, useParams } from 'react-router-dom'
import roomApi from '../../apis/room.api';
import userApi from '../../apis/user.api'
import catchErrors from "../../context/catchError";
const ChannelSingle = (props) => { const ChannelSingle = (props) => {
const { roomId, channelId } = useParams() const [error, setError] = useState("");
console.log('props', props.channel) const [success, setSuccess] = useState(false);
console.log('hi', channelId) const [roomName, setRoomName] = useState('');
const { roomId, channelId } = useParams();
const userId = localStorage.getItem('user')
async function joinChannel(e) {
console.log(e, userId)
try {
const data = await userApi.getUser(userId);
const index1 = indexCheck(e)
const A = doubleJoinCheck(data.name)
const mem = props.channel[index1].joinUser
const joinCh = mem.includes(data.name);
if (!joinCh) {
if (A) {
await roomApi.doubleJoin({ roomId: roomId, index1: A.index1, index2: A.index2, joinChName: A.joinChName })
}
const roomA = await roomApi.joinChannel({ roomId: roomId, channelName: e, plusUser: data.name, index: index1 })
setRoomName(e)
setSuccess(true)
} else {
alert('이미 참여된 채널입니다.')
}
} catch (error) {
catchErrors(error, setError);
}
}
function indexCheck(e) {
for (const index1 in props.channel) {
if (props.channel[index1].channelName === e) {
return index1
}
}
}
function doubleJoinCheck(e) {
for (const index in props.channel) {
for (const el in props.channel[index].joinUser) {
if (props.channel[index].joinUser[el] === e) {
const doublejoinCh = props.channel[index].channelName
const A = {
index1: index,
index2: el,
joinChName: doublejoinCh,
}
return A
}
}
}
}
if (success) {
alert(`${roomName} 채널에 참가되었습니다.`)
window.location.href = `/room/${roomId}/${roomName}`
}
return ( return (
<div> <div>
<div className="overflow-auto" style={{ height: '610px' }}> <div className="overflow-auto" style={{ height: '610px' }}>
...@@ -13,6 +73,7 @@ const ChannelSingle = (props) => { ...@@ -13,6 +73,7 @@ const ChannelSingle = (props) => {
<div <div
className="m-3 p-1 row" className="m-3 p-1 row"
style={{ backgroundColor: '#E0CEE8' }} style={{ backgroundColor: '#E0CEE8' }}
onClick={() => joinChannel(el.channelName)}
> >
{el.channelName === channelId ? ( {el.channelName === channelId ? (
<img <img
......
...@@ -17,9 +17,7 @@ const InitRoom = () => { ...@@ -17,9 +17,7 @@ const InitRoom = () => {
async function getRoom(roomId) { async function getRoom(roomId) {
try { try {
const data = await roomApi.getRoom([roomId]); const data = await roomApi.getRoom([roomId]);
console.log(data)
setRoom({...room, id:data[0].id, name:data[0].name, profileimg: data[0].profileimg}) setRoom({...room, id:data[0].id, name:data[0].name, profileimg: data[0].profileimg})
console.log(room.profileimg)
} catch (error) { } catch (error) {
catchErrors(error, setError); catchErrors(error, setError);
} }
......
import { useState } from "react";
import { useParams } from "react-router-dom";
import roomApi from "../../apis/room.api";
import catchErrors from "../../context/catchError";
const MakeChannel = () => {
const { roomId } = useParams();
const [channelName, setChannelName] = useState("");
const [error, setError] = useState("");
const [success, setSuccess] = useState(false);
function handleChange(event) {
const { value } = event.target;
setChannelName(value);
}
console.log(channelName)
async function handleSubmit(e) {
// e.preventDefault();
try {
const data = await roomApi.makeChannel({ roomId: roomId, channelName: channelName });
console.log('서버연결됬나요', data)
setSuccess(true);
} catch (error) {
catchErrors(error, setError);
} finally {
// setLoading(false);
}
}
if (success) {
// console.log('success', success)
alert('채널생성이 완료되었습니다!')
window.location.href = `/room/${roomId}/${channelName}`
}
return (
<div className="modal-content">
<form
onSubmit={handleSubmit}
>
<div className="modal-header">
<div className="modal-title" id="MakeChannelModal">
채널 생성하기
</div>
<button
type="button"
className="btn-close"
data-bs-dismiss="modal"
aria-label="Close"
></button>
</div>
<div className="modal-body">
{error && <div className="alert alert-danger">{error}</div>}
<div className="input-group mb-3">
<input
type="text"
className="form-control"
placeholder="생성할 채널이름을 입력하세요"
aria-label="생성할 채널이름을 입력하세요"
aria-describedby="basic-addon1"
name="channelName"
// value={channelName}
onChange={handleChange}
/>
</div>
<div className="modal-footer">
<button
type="submit"
className="btn btn-primary">
확인
</button>
</div>
</div>
</form>
</div>
);
};
export default MakeChannel;
...@@ -13,7 +13,7 @@ const INIT_ROOM = { ...@@ -13,7 +13,7 @@ const INIT_ROOM = {
const INIT_CHANNEL = { const INIT_CHANNEL = {
channelName: "", channelName: "",
joinName: [], joinUser: [],
}; };
const RightHamburger = () => { const RightHamburger = () => {
const [channel, setChannel] = useState([INIT_CHANNEL]); const [channel, setChannel] = useState([INIT_CHANNEL]);
...@@ -41,28 +41,22 @@ const RightHamburger = () => { ...@@ -41,28 +41,22 @@ const RightHamburger = () => {
console.log("id, roomid정보", id, roomId); console.log("id, roomid정보", id, roomId);
try { try {
const data = await RoomApi.exitRoom({ id, roomId }); const data = await RoomApi.exitRoom({ id, roomId });
console.log(data);
} catch (error) { } catch (error) {
catchErrors(error, setError); catchErrors(error, setError);
} }
} }
async function getChannel(roomId) { async function getChannel(roomId) {
const ID = roomId;
try { try {
const data = await RoomApi.getRoom([ID]); const data = await RoomApi.getRoom([roomId]);
const Channel = data[0].channel; const Channel = data[0].channel;
console.log("방데이터:", Channel);
const channelList = []; const channelList = [];
for (const prop in Channel) { for (const prop in Channel) {
// Channel의 항목(prop)으로 작업을 실행합니다 // Channel의 항목(prop)으로 작업을 실행합니다
for (const key in Channel[prop]) { for (const el in Channel[prop]) {
console.log(key);
console.log(prop);
console.log(Channel[prop][key]);
channelList.push({ channelList.push({
channelName: key, channelName: el,
joinName: Channel[prop][key], joinUser: Channel[prop][el],
}); });
} }
} }
......
...@@ -9,7 +9,7 @@ const INIT_ROOM = { ...@@ -9,7 +9,7 @@ const INIT_ROOM = {
const RoomHeader = () => { const RoomHeader = () => {
const {roomId}=useParams(); const {roomId, channelId}=useParams();
const [room, setRoom] = useState([INIT_ROOM]); const [room, setRoom] = useState([INIT_ROOM]);
const [error, setError] = useState("") const [error, setError] = useState("")
async function getRoom(Id) { async function getRoom(Id) {
...@@ -47,7 +47,7 @@ const RoomHeader = () => { ...@@ -47,7 +47,7 @@ const RoomHeader = () => {
color: '#6c33a2', color: '#6c33a2',
}} }}
> >
# 회의 # {channelId}
</a> </a>
</div> </div>
</div> </div>
......
...@@ -61,7 +61,7 @@ const Signup = () => { ...@@ -61,7 +61,7 @@ const Signup = () => {
if (success) { if (success) {
alert('회원가입이 완료되었습니다!') alert('회원가입이 완료되었습니다!')
window.location.href = '/' return <Redirect to="/" />;
} }
const { name, id, password, checkpw, phone } = user const { name, id, password, checkpw, phone } = user
......
...@@ -34,7 +34,7 @@ const joinRoom = async (req, res) => { ...@@ -34,7 +34,7 @@ const joinRoom = async (req, res) => {
{ roomNumber: user_Id.roomNumber }, { roomNumber: user_Id.roomNumber },
{ where: { id: userId } } { where: { id: userId } }
); );
res.json(true) res.json(true);
} else { } else {
return res.status(422).send("이미 참여된 방입니다."); return res.status(422).send("이미 참여된 방입니다.");
} }
...@@ -44,17 +44,19 @@ const joinRoom = async (req, res) => { ...@@ -44,17 +44,19 @@ const joinRoom = async (req, res) => {
}; };
const upLoadRoomImg = multer({ dest: "roomUploads/" }); const upLoadRoomImg = multer({ dest: "roomUploads/" });
const roomImgUpload = upLoadRoomImg.fields([{ name: "profileimg", maxCount: 1 }]); const roomImgUpload = upLoadRoomImg.fields([
{ name: "profileimg", maxCount: 1 },
]);
const createRoom = async (req, res) => { const createRoom = async (req, res) => {
const { userId, name } = req.body; const { userId, name } = req.body;
const avatar = req.files["profileimg"][0]; const avatar = req.files["profileimg"][0];
const img = avatar.filename; const img = avatar.filename;
const id = nanoid() const id = nanoid();
const Id = await Room.findOne({ where: { id: id } }); const Id = await Room.findOne({ where: { id: id } });
// console.log('id:', id) // console.log('id:', id)
while (Id) { while (Id) {
const id = nanoid() const id = nanoid();
const Id = await Room.findOne({ where: { id: id } }); const Id = await Room.findOne({ where: { id: id } });
} }
try { try {
...@@ -68,21 +70,25 @@ const createRoom = async (req, res) => { ...@@ -68,21 +70,25 @@ const createRoom = async (req, res) => {
owner: userId, owner: userId,
member: [userId], member: [userId],
profileimg: img, profileimg: img,
} };
// console.log('newRoom:', newRoom) // console.log('newRoom:', newRoom)
await Room.create(newRoom); await Room.create(newRoom);
//user.roomNumber에 id추가 //user.roomNumber에 id추가
const user_Id = await User.findOne({ where: { id: userId } }); const user_Id = await User.findOne({ where: { id: userId } });
if (user_Id.roomNumber) { //다른 roomNumber가 이미 들어가 있는 경우 id추가 if (user_Id.roomNumber) {
user_Id.roomNumber.push(id) //다른 roomNumber가 이미 들어가 있는 경우 id추가
} user_Id.roomNumber.push(id);
else { //첫 roomNumber인 경우 } else {
user_Id.roomNumber = [id] //첫 roomNumber인 경우
user_Id.roomNumber = [id];
} }
// console.log('user_Id.roomNumber2:', user_Id.roomNumber) // console.log('user_Id.roomNumber2:', user_Id.roomNumber)
await User.update({ 'roomNumber': user_Id.roomNumber }, { where: { id: userId } }) await User.update(
res.json(newRoom) { roomNumber: user_Id.roomNumber },
{ where: { id: userId } }
);
res.json(newRoom);
} catch (error) { } catch (error) {
console.log(error); console.log(error);
res.status(500).send("방생성 에러"); res.status(500).send("방생성 에러");
...@@ -94,7 +100,7 @@ const getRoom = async (req, res) => { ...@@ -94,7 +100,7 @@ const getRoom = async (req, res) => {
try { try {
const roomlist = await Room.findAll({ where: { id: req.body } }); const roomlist = await Room.findAll({ where: { id: req.body } });
// console.log(roomlist); // console.log(roomlist);
res.json(roomlist) res.json(roomlist);
} catch (error) { } catch (error) {
console.log(error); console.log(error);
res.status(500).send("에러"); res.status(500).send("에러");
...@@ -102,36 +108,72 @@ const getRoom = async (req, res) => { ...@@ -102,36 +108,72 @@ const getRoom = async (req, res) => {
}; };
const exitRoom = async (req, res) => { const exitRoom = async (req, res) => {
const { id, roomId } = req.params const { id, roomId } = req.params;
console.log(id, roomId) console.log(id, roomId);
const room = await Room.findOne({ where: { id: roomId } }); const room = await Room.findOne({ where: { id: roomId } });
console.log(room.member) console.log(room.member);
const index = room.member.indexOf(id) const index = room.member.indexOf(id);
console.log('index',index) console.log("index", index);
room.member.splice(index,1) room.member.splice(index, 1);
await Room.update({ member: room.member }, { where: { id: roomId } }); await Room.update({ member: room.member }, { where: { id: roomId } });
const user = await User.findOne({ where: { id: id } }); const user = await User.findOne({ where: { id: id } });
console.log(user.roomNumber) console.log(user.roomNumber);
const index2 = user.roomNumber.indexOf(id) const index2 = user.roomNumber.indexOf(id);
console.log('index',index2) console.log("index", index2);
user.roomNumber.splice(index2,1) user.roomNumber.splice(index2, 1);
await User.update({ roomNumber: user.roomNumber }, { where: { id: id } }); await User.update({ roomNumber: user.roomNumber }, { where: { id: id } });
} };
const changename = async (req,res) => { const changename = async (req, res) => {
const {id, name} = req.body; const { id, name } = req.body;
console.log(req.body) console.log(req.body);
try { try {
await Room.update({ 'name': name },{ where: { id: id } }) await Room.update({ name: name }, { where: { id: id } });
const room1 = await Room.findOne({ where: { id: id } }) const room1 = await Room.findOne({ where: { id: id } });
console.log('Room:',room1) console.log("Room:", room1);
}catch (error) { } catch (error) {
console.log(error); console.log(error);
res.status(500).send("에러"); res.status(500).send("에러");
} }
}; };
const joinChannel = async (req, res) => {
const { roomId, channelName, plusUser, index } = req.body;
console.log("연결성공");
const room = await Room.findOne({ where: { id: roomId } });
room.channel[index][channelName].push(plusUser);
console.log("확인2", room.channel[index]);
console.log("확인2", room.channel);
await Room.update({ channel: room.channel }, { where: { id: roomId } });
return res.json(true);
};
const doubleJoin = async (req, res) => {
console.log("연결성공", req.body);
const { roomId, index1, index2, joinChName } = req.body;
console.log(index1);
const room = await Room.findOne({ where: { id: roomId } });
console.log(room.channel[index1][joinChName]);
room.channel[index1][joinChName].splice(index2, 1);
console.log(room.channel[index1][joinChName]);
console.log("room.channel", room.channel);
await Room.update({ channel: room.channel }, { where: { id: roomId } });
return res.json(true);
};
// const makeChannel = async (req, res) => {
// const { roomId, channelName } = req.body
// console.log(roomId, channelName)
// }
export default { export default {
joinRoom, roomImgUpload, createRoom, getRoom, exitRoom, changename joinRoom,
roomImgUpload,
createRoom,
getRoom,
exitRoom,
changename,
joinChannel,
doubleJoin,
}; };
...@@ -17,11 +17,10 @@ const RoomModel = (sequelize) => { ...@@ -17,11 +17,10 @@ const RoomModel = (sequelize) => {
}, },
member: { member: {
type: DataTypes.ARRAY(DataTypes.STRING), type: DataTypes.ARRAY(DataTypes.STRING),
//type: DataTypes.STRING,
}, },
profileimg: { profileimg: {
type: DataTypes.STRING, type: DataTypes.STRING,
defaultValue: "defaultimg" // defaultValue: "defaultimg"
}, },
channel: { channel: {
type: DataTypes.ARRAY(DataTypes.JSON), type: DataTypes.ARRAY(DataTypes.JSON),
......
...@@ -7,5 +7,8 @@ router.route("/exitRoom/:id/:roomId").delete(roomCrtl.exitRoom); ...@@ -7,5 +7,8 @@ router.route("/exitRoom/:id/:roomId").delete(roomCrtl.exitRoom);
router.route("/create").post(roomCrtl.roomImgUpload, roomCrtl.createRoom); router.route("/create").post(roomCrtl.roomImgUpload, roomCrtl.createRoom);
router.route("/join").put(roomCrtl.joinRoom); router.route("/join").put(roomCrtl.joinRoom);
router.route("/changename").put(roomCrtl.changename); router.route("/changename").put(roomCrtl.changename);
router.route("/joinChannel").post(roomCrtl.joinChannel);
router.route("/doubleJoin").post(roomCrtl.doubleJoin);
// router.route("/makeChannel").post(roomCrtl.makeChannel);
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