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 @@
"integrity": "sha512-4WK/bYZmj8xLr+HUCODHGF1ZFzsYffasLUgEiMBY4fgtltdO6B4WJtlSbPaDTLpYTcGVwM2qLnFTICEcNxs3kA=="
},
"tar": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/tar/-/tar-6.1.0.tgz",
"integrity": "sha512-DUCttfhsnLCjwoDoFcI+B2iJgYa93vBnDUATYEeRx6sntCTdN01VnqsIuTlALXla/LWooNg0yEGeB+Y8WdFxGA==",
"version": "6.1.5",
"resolved": "https://registry.npmjs.org/tar/-/tar-6.1.5.tgz",
"integrity": "sha512-FiK6MQyyaqd5vHuUjbg/NpO8BuEGeSXcmlH7Pt/JkugWS8s0w8nKybWjHDJiwzCAIKZ66uof4ghm4tBADjcqRA==",
"requires": {
"chownr": "^2.0.0",
"fs-minipass": "^2.0.0",
......
import axios from "axios";
const getRoom = async (id) => {
const { data } = await axios.post('/api/room/getRoom', id);
const { data } = await axios.post("/api/room/getRoom", id);
return data;
};
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;
};
......@@ -21,10 +23,33 @@ const join = 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;
}
};
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;
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 catchErrors from '../context/catchError'
import { handleLogin } from '../context/auth'
......@@ -46,7 +46,7 @@ const Login = () => {
}
if (success) {
alert('로그인 되었습니다')
window.location.href = `/user/${id}`
return <Redirect to={`/user/${id}`} />;
}
const { email, password } = user
......
import { Link } from 'react-router-dom'
import React, { useState } from 'react';
import { Link, useParams } from 'react-router-dom'
import React, { useEffect, useState } from 'react';
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 { roomId } = useParams();
const [error, setError] = useState("");
const [channel, setChannel] = useState([INIT_CHANNEL]);
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 (
<div>
<nav className="navbar navbar-light ">
<div className="col-2"></div>
<div>
<div onClick={exitChannel}>
<Link to={`/user/${id}`}>
<img src="/BORA.png" style={{ width: '160px' }} />
</Link>
......
import { useState } from 'react'
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 { roomId, channelId } = useParams()
console.log('props', props.channel)
console.log('hi', channelId)
const [error, setError] = useState("");
const [success, setSuccess] = useState(false);
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 (
<div>
<div className="overflow-auto" style={{ height: '610px' }}>
......@@ -13,6 +73,7 @@ const ChannelSingle = (props) => {
<div
className="m-3 p-1 row"
style={{ backgroundColor: '#E0CEE8' }}
onClick={() => joinChannel(el.channelName)}
>
{el.channelName === channelId ? (
<img
......
......@@ -17,9 +17,7 @@ const InitRoom = () => {
async function getRoom(roomId) {
try {
const data = await roomApi.getRoom([roomId]);
console.log(data)
setRoom({...room, id:data[0].id, name:data[0].name, profileimg: data[0].profileimg})
console.log(room.profileimg)
} catch (error) {
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 = {
const INIT_CHANNEL = {
channelName: "",
joinName: [],
joinUser: [],
};
const RightHamburger = () => {
const [channel, setChannel] = useState([INIT_CHANNEL]);
......@@ -41,28 +41,22 @@ const RightHamburger = () => {
console.log("id, roomid정보", id, roomId);
try {
const data = await RoomApi.exitRoom({ id, roomId });
console.log(data);
} catch (error) {
catchErrors(error, setError);
}
}
async function getChannel(roomId) {
const ID = roomId;
try {
const data = await RoomApi.getRoom([ID]);
const data = await RoomApi.getRoom([roomId]);
const Channel = data[0].channel;
console.log("방데이터:", Channel);
const channelList = [];
for (const prop in Channel) {
// Channel의 항목(prop)으로 작업을 실행합니다
for (const key in Channel[prop]) {
console.log(key);
console.log(prop);
console.log(Channel[prop][key]);
for (const el in Channel[prop]) {
channelList.push({
channelName: key,
joinName: Channel[prop][key],
channelName: el,
joinUser: Channel[prop][el],
});
}
}
......
......@@ -9,7 +9,7 @@ const INIT_ROOM = {
const RoomHeader = () => {
const {roomId}=useParams();
const {roomId, channelId}=useParams();
const [room, setRoom] = useState([INIT_ROOM]);
const [error, setError] = useState("")
async function getRoom(Id) {
......@@ -47,7 +47,7 @@ const RoomHeader = () => {
color: '#6c33a2',
}}
>
# 회의
# {channelId}
</a>
</div>
</div>
......
......@@ -61,7 +61,7 @@ const Signup = () => {
if (success) {
alert('회원가입이 완료되었습니다!')
window.location.href = '/'
return <Redirect to="/" />;
}
const { name, id, password, checkpw, phone } = user
......
......@@ -34,7 +34,7 @@ const joinRoom = async (req, res) => {
{ roomNumber: user_Id.roomNumber },
{ where: { id: userId } }
);
res.json(true)
res.json(true);
} else {
return res.status(422).send("이미 참여된 방입니다.");
}
......@@ -44,17 +44,19 @@ const joinRoom = async (req, res) => {
};
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 { userId, name } = req.body;
const avatar = req.files["profileimg"][0];
const img = avatar.filename;
const id = nanoid()
const id = nanoid();
const Id = await Room.findOne({ where: { id: id } });
// console.log('id:', id)
while (Id) {
const id = nanoid()
const id = nanoid();
const Id = await Room.findOne({ where: { id: id } });
}
try {
......@@ -68,21 +70,25 @@ const createRoom = async (req, res) => {
owner: userId,
member: [userId],
profileimg: img,
}
};
// console.log('newRoom:', newRoom)
await Room.create(newRoom);
//user.roomNumber에 id추가
const user_Id = await User.findOne({ where: { id: userId } });
if (user_Id.roomNumber) { //다른 roomNumber가 이미 들어가 있는 경우 id추가
user_Id.roomNumber.push(id)
}
else { //첫 roomNumber인 경우
user_Id.roomNumber = [id]
if (user_Id.roomNumber) {
//다른 roomNumber가 이미 들어가 있는 경우 id추가
user_Id.roomNumber.push(id);
} else {
//첫 roomNumber인 경우
user_Id.roomNumber = [id];
}
// console.log('user_Id.roomNumber2:', user_Id.roomNumber)
await User.update({ 'roomNumber': user_Id.roomNumber }, { where: { id: userId } })
res.json(newRoom)
await User.update(
{ roomNumber: user_Id.roomNumber },
{ where: { id: userId } }
);
res.json(newRoom);
} catch (error) {
console.log(error);
res.status(500).send("방생성 에러");
......@@ -94,7 +100,7 @@ const getRoom = async (req, res) => {
try {
const roomlist = await Room.findAll({ where: { id: req.body } });
// console.log(roomlist);
res.json(roomlist)
res.json(roomlist);
} catch (error) {
console.log(error);
res.status(500).send("에러");
......@@ -102,36 +108,72 @@ const getRoom = async (req, res) => {
};
const exitRoom = async (req, res) => {
const { id, roomId } = req.params
console.log(id, roomId)
const { id, roomId } = req.params;
console.log(id, roomId);
const room = await Room.findOne({ where: { id: roomId } });
console.log(room.member)
const index = room.member.indexOf(id)
console.log('index',index)
room.member.splice(index,1)
console.log(room.member);
const index = room.member.indexOf(id);
console.log("index", index);
room.member.splice(index, 1);
await Room.update({ member: room.member }, { where: { id: roomId } });
const user = await User.findOne({ where: { id: id } });
console.log(user.roomNumber)
const index2 = user.roomNumber.indexOf(id)
console.log('index',index2)
user.roomNumber.splice(index2,1)
console.log(user.roomNumber);
const index2 = user.roomNumber.indexOf(id);
console.log("index", index2);
user.roomNumber.splice(index2, 1);
await User.update({ roomNumber: user.roomNumber }, { where: { id: id } });
}
};
const changename = async (req,res) => {
const {id, name} = req.body;
console.log(req.body)
const changename = async (req, res) => {
const { id, name } = req.body;
console.log(req.body);
try {
await Room.update({ 'name': name },{ where: { id: id } })
const room1 = await Room.findOne({ where: { id: id } })
console.log('Room:',room1)
}catch (error) {
await Room.update({ name: name }, { where: { id: id } });
const room1 = await Room.findOne({ where: { id: id } });
console.log("Room:", room1);
} catch (error) {
console.log(error);
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 {
joinRoom, roomImgUpload, createRoom, getRoom, exitRoom, changename
joinRoom,
roomImgUpload,
createRoom,
getRoom,
exitRoom,
changename,
joinChannel,
doubleJoin,
};
......@@ -17,11 +17,10 @@ const RoomModel = (sequelize) => {
},
member: {
type: DataTypes.ARRAY(DataTypes.STRING),
//type: DataTypes.STRING,
},
profileimg: {
type: DataTypes.STRING,
defaultValue: "defaultimg"
// defaultValue: "defaultimg"
},
channel: {
type: DataTypes.ARRAY(DataTypes.JSON),
......
......@@ -7,5 +7,8 @@ router.route("/exitRoom/:id/:roomId").delete(roomCrtl.exitRoom);
router.route("/create").post(roomCrtl.roomImgUpload, roomCrtl.createRoom);
router.route("/join").put(roomCrtl.joinRoom);
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;
\ 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