Commit 558e3ef4 authored by 권병윤's avatar 권병윤
Browse files

Merge remote-tracking branch 'origin/jaeyeon2854' into byoungyun1

parents 7ad5341d fecf0818
......@@ -52,6 +52,17 @@ const channelDelete = async (payload) => {
const { data } = await axios.put("/api/room/channelDelete", payload);
return data;
};
const removeRoom = async (ID)=>{
const { data } = await axios.delete(
`/api/room/removeRoom/${ID.roomId}`
);
return data;
}
// const makeChannel = async (payload) => {
// const { data } = await axios.post("/api/room/makeChannel", payload);
// return data;
// };
const roomApi = {
getRoom,
......@@ -63,7 +74,8 @@ const roomApi = {
doubleJoin,
profileimg,
makeChannel,
channelDelete
channelDelete,
removeRoom
};
export default roomApi;
......@@ -2,7 +2,7 @@ import { Link } from 'react-router-dom'
import { handleLogout } from '../context/auth'
const Header = () => {
const id = localStorage.getItem('user');
const id = sessionStorage.getItem('user');
return (
<div>
<form
......
......@@ -3,7 +3,7 @@ import { Redirect } from "react-router-dom";
import roomApi from "../../apis/room.api";
import catchErrors from "../../context/catchError";
const id = localStorage.getItem('user');
const id = sessionStorage.getItem('user');
const INIT_ROOM = {
name: '',
profileimg: '',
......@@ -28,7 +28,6 @@ const CreateRoom = () => {
} else {
setRoom({ ...room, [name]: value })
}
console.log(room)
}
async function handleSubmit(e) {
......
......@@ -3,7 +3,7 @@ import { useState, useEffect } from "react";
import userApi from "../../apis/user.api";
import catchErrors from "../../context/catchError";
const userprofile = localStorage.getItem("user");
const userprofile = sessionStorage.getItem("user");
const INIT_USER = {
id: userprofile,
email: "",
......
......@@ -3,7 +3,7 @@ import { Redirect } from "react-router-dom";
import roomApi from "../../apis/room.api";
import catchErrors from "../../context/catchError";
const id = localStorage.getItem("user");
const id = sessionStorage.getItem("user");
const JoinRoom = () => {
const [roomId, setRoomId] = useState("");
......
......@@ -4,7 +4,7 @@ import roomApi from "../../apis/room.api";
import userApi from "../../apis/user.api";
import catchErrors from "../../context/catchError";
const id = localStorage.getItem("user");
const id = sessionStorage.getItem("user");
const INIT_ROOM = {
roomId: "",
name: "",
......
......@@ -13,7 +13,7 @@ const KakaoShareButton = (porps) => {
const [inviteperson, setProfile] = useState(INIT_invite);
const [error, setError] = useState("");
const { roomId } = useParams();
const invitepersonId = localStorage.getItem("user");
const invitepersonId = sessionStorage.getItem("user");
async function getProfile(userID) {
try {
......
......@@ -46,7 +46,7 @@ const Login = () => {
}
if (success) {
alert('로그인 되었습니다')
return <Redirect to={`/user/${id}`} />;
window.location.href=`/user/${id}`
}
const { email, password } = user
......
......@@ -2,7 +2,7 @@ import userApi from "../../apis/user.api";
import { useEffect, useState } from "react";
import catchErrors from "../../context/catchError";
const userprofile = localStorage.getItem("user");
const userprofile = sessionStorage.getItem("user");
const INIT_PROFILE = {
name: "",
email: "a",
......
......@@ -3,7 +3,7 @@ import React, { useEffect, useState } from "react";
import userApi from "../../apis/user.api";
import catchErrors from "../../context/catchError";
const userprofile = localStorage.getItem("user");
const userprofile = sessionStorage.getItem("user");
const INIT_PROFILE = {
id: userprofile,
name:"",
......
......@@ -3,7 +3,7 @@ import { useState, useEffect } from "react";
import userApi from "../../apis/user.api";
import catchErrors from "../../context/catchError";
const userprofile = localStorage.getItem("user");
const userprofile = sessionStorage.getItem("user");
const INIT_PROFILE = {
img:"",
};
......
......@@ -15,7 +15,7 @@ const ChannelList = () => {
const { roomId } = useParams();
const [error, setError] = useState("");
const [channel, setChannel] = useState([INIT_CHANNEL]);
const id = localStorage.getItem('user');
const id = sessionStorage.getItem('user');
async function getChannel(roomId) {
try {
......
......@@ -10,11 +10,10 @@ const ChannelSingle = (props) => {
const [success, setSuccess] = useState(false);
const [roomName, setRoomName] = useState('');
const { roomId, channelId } = useParams();
const userId = localStorage.getItem('user')
const userId = sessionStorage.getItem('user')
async function joinChannel(e) {
console.log(e, userId)
try {
const data = await userApi.getUser(userId);
const index1 = indexCheck(e)
......
......@@ -6,6 +6,8 @@ import catchErrors from "../../context/catchError";
import KakaoShareButton from "../KakaoShareButton";
import RoomSettingChange from "./RoomSettingChange";
import ChannelSettingChange from "./ChannelSettingChange";
import userApi from "../../apis/user.api";
import roomApi from "../../apis/room.api";
const INIT_ROOM = {
name: "",
......@@ -22,7 +24,7 @@ const RightHamburger = () => {
const [room, setRoom] = useState([INIT_ROOM]);
const { roomId } = useParams();
const [error, setError] = useState("");
const id = localStorage.getItem("user");
const id = sessionStorage.getItem("user");
async function getRoom(roomId) {
try {
......@@ -32,7 +34,6 @@ const RightHamburger = () => {
name: data[0].name,
owner: data[0].owner,
});
console.log(roomdata);
setRoom(roomdata);
} catch (error) {
catchErrors(error, setError);
......@@ -40,9 +41,12 @@ const RightHamburger = () => {
}
async function exitRoom() {
console.log("id, roomid정보", id, roomId);
try {
const data = await RoomApi.exitRoom({ id, roomId });
if (data.owner === Number(id)){
const room = await RoomApi.removeRoom({roomId : roomId})
console.log(room)
}
} catch (error) {
catchErrors(error, setError);
}
......@@ -67,6 +71,38 @@ const RightHamburger = () => {
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;
}
}
}
}
// console.log(channel)
......@@ -281,6 +317,7 @@ const RightHamburger = () => {
<button
type="button"
onClick={exitRoom}
onSubmit={exitChannel}
className="btn btn-primary"
data-bs-dismiss="modal"
>
......
import axios from 'axios'
export function handleLogin(userId) {
localStorage.setItem("user", userId)
sessionStorage.setItem("user", userId)
}
export async function handleLogout() {
alert("로그아웃되었습니다.")
localStorage.removeItem("user")
sessionStorage.removeItem("user")
await axios.get('/api/auth/logout')
window.location.href='/'
}
export function isAuthenticated() {
const userId = localStorage.getItem('loginStatus')
const userId = sessionStorage.getItem('loginStatus')
if (userId) {
return userId
}else{
......
......@@ -36,7 +36,7 @@ const AuthProvider = ({ children }) => {
setError("");
setLoading(true);
const user = await authApi.login(email, password);
localStorage.setItem(config.loginUser, JSON.stringify(user));
sessionStorage.setItem(config.loginUser, JSON.stringify(user));
setUser(user);
return true;
......@@ -53,7 +53,7 @@ const AuthProvider = ({ children }) => {
setError("");
setUser(null);
alert("로그아웃되었습니다.");
localStorage.removeItem(config.loginUser);
sessionStorage.removeItem(config.loginUser);
setLoading(true);
await axios.get(`${baseUrl}/api/auth/logout`);
} catch (error) {
......
......@@ -14,7 +14,7 @@ const INIT_PROFILE = {
const InvitePage = () => {
const [profile, setProfile] = useState([INIT_PROFILE]);
const [error, setError] = useState("");
const usercheck = localStorage.getItem("user");
const usercheck = sessionStorage.getItem("user");
const { roomId } = useParams();
async function getProfile(userID) {
......
......@@ -12,14 +12,11 @@ const joinRoom = async (req, res) => {
//roomId에 일치하는 방이 존재할때
//roomId에 일치하는 방의 member정보에 userId 저장하기
//member정보에 userId가 이미 저장되어 있는지 확인 -> 이미 참여된 방인지 확인
const includeUserId = room_Id.member.includes(parseInt(userId));// 이미 참여되어있는데 확인 못하고 있음.
// console.log('Include확인:',includeUserId)
const includeUserId = room_Id.member.includes(userId);
if (!includeUserId) {
//아직 참여되지 않은 방인경우
room_Id.member.push(userId); //member에 userId추가
// console.log('room_Id.member2:', room_Id.member)
await Room.update({ member: room_Id.member }, { where: { id: roomId } });
//userId에 일치하는 사용자의 roomNumber에 roomId저장하기
const user_Id = await User.findOne({ where: { id: userId } });
if (Boolean(user_Id.roomNumber)) {
......@@ -29,7 +26,6 @@ const joinRoom = async (req, res) => {
//첫 roomNumber인 경우
user_Id.roomNumber = [roomId];
}
// console.log('user_Id.roomNumber2:', user_Id.roomNumber)
await User.update(
{ roomNumber: user_Id.roomNumber },
{ where: { id: userId } }
......@@ -69,7 +65,6 @@ const createRoom = async (req, res) => {
const img = avatar.filename;
const id = nanoid();
const Id = await Room.findOne({ where: { id: id } });
// console.log('id:', id)
while (Id) {
const id = nanoid();
const Id = await Room.findOne({ where: { id: id } });
......@@ -86,7 +81,6 @@ const createRoom = async (req, res) => {
member: [userId],
profileimg: img,
};
// console.log('newRoom:', newRoom)
await Room.create(newRoom);
//user.roomNumber에 id추가
......@@ -98,7 +92,6 @@ const createRoom = async (req, res) => {
//첫 roomNumber인 경우
user_Id.roomNumber = [id];
}
// console.log('user_Id.roomNumber2:', user_Id.roomNumber)
await User.update(
{ roomNumber: user_Id.roomNumber },
{ where: { id: userId } }
......@@ -111,62 +104,80 @@ const createRoom = async (req, res) => {
};
const getRoom = async (req, res) => {
// console.log("fhgfghdgfdgf:", req.body);
try {
const roomlist = await Room.findAll({ where: { id: req.body } });
// console.log(roomlist);
res.json(roomlist);
} catch (error) {
console.log(error);
res.status(500).send("에러");
}
};
const exitRoom = async (req, res) => {
const { id, roomId } = req.params;
console.log(id, roomId);
try {
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);
await Room.update({ member: room.member }, { where: { id: roomId } });
const newRoom = 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);
await User.update({ roomNumber: user.roomNumber }, { where: { id: id } });
const newUser = await User.update(
{ roomNumber: user.roomNumber },
{ where: { id: id } }
);
return res.json(room);
} catch (error) {
res.status(500).send("에러");
}
};
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) {
console.log(error);
res.status(500).send("에러");
}
};
const joinChannel = async (req, res) => {
const { roomId, channelName, plusUser, index } = req.body;
try {
const room = await Room.findOne({ where: { id: roomId } });
room.channel[index][channelName].push(plusUser);
await Room.update({ channel: room.channel }, { where: { id: roomId } });
return res.json(true);
return res.json(true)
} catch (error) {
res.status(500).send("error");
}
};
const doubleJoin = async (req, res) => {
const { roomId, index1, index2, joinChName } = req.body;
try {
const room = await Room.findOne({ where: { id: roomId } });
room.channel[index1][joinChName].splice(index2, 1);
await Room.update({ channel: room.channel }, { where: { id: roomId } });
return res.json(true);
return res.json(true)
} catch (error) {
res.status(500).send("error");
}
};
const removeRoom = async (req, res) => {
const { roomId } = req.params;
console.log('서버연결성공!!!!',roomId)
try {
const room = await Room.destroy({ where: { id: roomId } });
} catch (error) {
res.status(500).send("error");
}
};
const makeChannel = async (req, res) => {
......@@ -197,5 +208,6 @@ export default {
doubleJoin,
update,
makeChannel,
channelDelete
channelDelete,
removeRoom,
};
......@@ -24,7 +24,7 @@ const RoomModel = (sequelize) => {
},
channel: {
type: DataTypes.ARRAY(DataTypes.JSON),
defaultValue: [{"회의": ["지원", "재연"]}, {"사담": ["지원", "재연", "서연"]}],
defaultValue: [{"회의": []}, {"일반": []}],
},
},
{ timestamps: true }
......
......@@ -12,5 +12,7 @@ router.route("/joinChannel").post(roomCrtl.joinChannel);
router.route("/doubleJoin").post(roomCrtl.doubleJoin);
router.route("/makeChannel").put(roomCrtl.makeChannel);
router.route("/channelDelete").put(roomCrtl.channelDelete);
router.route("/removeRoom/:roomId").delete(roomCrtl.removeRoom);
// 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