채지성

commuPage

......@@ -198,3 +198,15 @@ npm start
> }
>```
>> 제2기숙사 학식 메뉴 일주일치 가져오기
-------------
### /api/todayMenu
#### GET호출
> response
> ```
> [
> "도시락: 돈까스마요덮밥,매운콩나물국,카레크로켓,마카로니샐러드,볶음김치"
> "운영없음"
> ]
>```
>> 제2기숙사 학식 오늘의 메뉴 가져오기
......
.commuPage{
height: 90%;
width: 80%;
display:grid;
grid-template-rows: 85% 15%;
margin: 1%;
background-color: #FDF5E6;
}
.commuPage > :nth-child(1){
overflow-y: scroll;
overflow-x: hidden;
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
height:100%;
}
.commuPage > :nth-child(1)::-webkit-scrollbar {
display: none; /* Chrome, Safari, Opera*/
}
.commuPage > :nth-child(2){
display:flex;
justify-content: end;
align-items: flex-end;
}
.commuPage > :nth-child(2) > button {
width: 15%;
margin:3% 4%;
margin-left: 0%;
}
.outer {
font-size: 10px;
height: 30%;
max-height: 30px;
width: 98%;
background-color: #FDF5F3;
border:0px solid black;
border-bottom: 1px solid black;
padding-left:10%;
display:grid;
grid-template-columns: 15% 20% 40%;
grid-template-rows: 100%;
align-items: center;
padding-top: 1%;
margin: 0.5%
}
.inner{
border: 0px solid black;
background-color: #FDF5F3;
height:100%;
max-height: 18px;
display: block;
text-align: left;
padding:0%;
margin:0%;
overflow: hidden;
}
\ No newline at end of file
import './App.css';
import axios from "axios";
import { useEffect, useState } from 'react';
import './CommuPage.css'
function InnerContent(props) {
return (
<div className='outer'>
<div className='inner'>{props.title}</div>
<div className='inner'></div>
<div className='inner'>{props.content}</div>
</div>
);
}
function CommuPage() {
const [list, setList] = useState([]);
const moveToYesterDay = () => {window.location.href = '/mealtalk/yesterday';}
const moveToWriting = () => {window.location.href = '/writing';}
const todayInnerContent = async () => { // 게시글 목록 가져오기
const arr = (await axios.get('/api/getList')).data;
var idArray = [];
for(var id of arr) idArray.push(id);
axios.post('/api/get',{idArray:idArray}).then((res)=>{
const reverseArr = res.data.reverse();
setList(reverseArr);
console.log(reverseArr);
})
};
useEffect(() => {
todayInnerContent();
}, []);
return (
<div className='commuPage'>
<div>
{list.map((item, index) => {
return (
<InnerContent key={index} title={item.title} content={item.content} />
)
})}
</div>
<div>
<button onClick={moveToWriting}> 작성</button>
<button onClick={moveToYesterDay}>어제 보기</button>
</div>
</div>
);
}
//첫번째: 오늘 메뉴/ 두번째: 오늘 메뉴에 대한 이야기/ 세번째: 어제 메뉴에 대한 이야기
export default CommuPage;
\ No newline at end of file
import './App.css';
import axios from "axios";
import { useEffect, useState } from 'react';
import './CommuPage.css'
function InnerContent(props) {
return (
<div className='outer'>
<div className='inner'>{props.title}</div>
<div className='inner'></div>
<div className='inner'>{props.content}</div>
</div>
);
}
function CommuPageYes() {
const [list2, setList2] = useState([]);
const moveToToday = () => {window.location.href = '/mealtalk';}
const moveToWriting = () => {window.location.href = '/writing';}
const yesterInnerContent = async () =>{
let today = new Date();
let year = today.getFullYear(); // 년도
let month = today.getMonth() + 1; // 월
let date = today.getDate() -1; // 날짜
let todayDate = year+'-0'+month+'-0'+date; // date에 넣을 문자열
const arr = (await axios.get(`/api/getList/:${todayDate}`)).data;
var idArray = [];
for(var id of arr) idArray.push(id);
axios.post('/api/get',{idArray:idArray}).then((res)=>{
const reverseArr = res.data.reverse();
setList2(reverseArr);
console.log(reverseArr);
})
};
useEffect(() => {
yesterInnerContent();
}, []);
return (
<div className='commuPage'>
<div>
{list2.map((item, index) => {
return (
<InnerContent key={index} title={item.title} content={item.content} />
)
})}
</div>
<div>
<button onClick={moveToWriting}> 작성</button>
<button onClick={moveToToday}>오늘 보기</button>
</div>
</div>
);
}
//첫번째: 오늘 메뉴/ 두번째: 오늘 메뉴에 대한 이야기/ 세번째: 어제 메뉴에 대한 이야기
export default CommuPageYes;
\ No newline at end of file
......@@ -11,7 +11,7 @@
}
.mainpage :nth-child(1):not(.mainpage :nth-child(1) :nth-child(1)){
.mainpage :nth-child(1):not(.mainpage :nth-child(1) *, .mainpage :nth-child(2) > * ){
display:grid;
grid-template-columns: 1fr 1fr;
grid-template-rows: 8% 12% 79%;
......@@ -78,4 +78,36 @@
display:flex;
flex-direction: column;
background-color: #FDF5E6;
padding:0px;
margin: 0px;
}
.mainpage .mainpageUnder :nth-child(2) > div {
font-size: 10px;
height: 30%;
max-height: 30px;
width: 98%;
background-color: #FDF5F3;
border:0px solid black;
border-bottom: 1px solid black;
padding-left:10%;
display:grid;
grid-template-columns: 15% 20% 40%;
grid-template-rows: 100%;
align-items: center;
padding-top: 1%;
margin: 0.5%
}
.mainpage .mainpageUnder :nth-child(2) > div >div{
border: 0px solid black;
background-color: #FDF5F3;
height:100%;
max-height: 18px;
display: block;
text-align: left;
padding:0%;
margin:0%;
overflow: hidden;
}
\ No newline at end of file
......
import './App.css';
import axios from "axios";
import { useEffect, useState } from 'react';
import './mainpage.css'
import './MainPage.css'
function InnerContent(props) {
return (
<div>
<div style={{ fontSize: '15px', height: '10px', width: '100%', backgroundColor: '#FDF5E6' }}>{props.title} {props.content}</div>
<div className='outer'>
<div className='inner'>{props.title}</div>
<div className='inner'></div>
<div className='inner'>{props.content}</div>
</div>
);
}
function MainPage() {
const [list, setList] = useState([{ title: '하이', content: '바보' }, { title: '하이2', content: '바보2' }, { title: '하이3', content: '바보3' }]);
const [list, setList] = useState([]);
let currentYear = new Date().getFullYear();
let currentMonth = new Date().getMonth() + 1;
let currentDate = new Date().getDate();
......@@ -28,6 +30,11 @@ function MainPage() {
arr_.forEach((elem) => {
let span_ = document.createElement('div');
span_.innerHTML = elem;
span_.style.borderWidth = '0px';
span_.style.textAlign = 'center';
span_.style.gridTemplateColumns = '100%';
span_.style.backgroundColor = '#FDF5E6';
span_.style.padding = '0%';
dom_.appendChild(span_);
});
......@@ -66,8 +73,9 @@ function MainPage() {
var idArray = [];
for(var id of arr) idArray.push(id);
axios.post('/api/get',{idArray:idArray}).then((res)=>{
setList(res.data);
console.log(res.data);
const reverseArr = res.data.reverse().slice(0,8);
setList(reverseArr);
console.log(reverseArr);
})
}
......
......@@ -7,9 +7,10 @@ import 'bootstrap/dist/css/bootstrap.min.css';
//컴포넌트
import TopBanner from './Component/TopBanner'; // 상단 메뉴
import SideChat from './Component/SideChat'; // 측면 대기시간 채팅
import MainPage from './Component/mainpage'; // 초기화면
import MainPage from './Component/MainPage'; // 초기화면
import MenuPage from './Component/MenuPage'; // 학식 메뉴 화면
import CommuPage from './Component/CommuPage'; // 학식 커뮤 화면(오늘)
import CommuPageYes from './Component/CommuPageYes'; // 학식 커뮤 화면(어제)
import Writing from './Component/Writing'; // 글 작성 화면
import {
......@@ -29,7 +30,8 @@ root.render(
<Routes>
<Route path="/" element={<MainPage />} />
<Route path="/menu" element={<MenuPage />} />
<Route path="/mealtalk" element={<MainPage />} />
<Route path="/mealtalk" element={<CommuPage />} />
<Route path="/mealtalk/yesterday" element={<CommuPageYes />} />
<Route path="/writing" element={<Writing />} />
</Routes>
</Router>
......
......@@ -18,6 +18,7 @@ const dayPostList = mongoose.Schema({
const dayPostListModel = mongoose.model('dayPostList', dayPostList);
const post = mongoose.Schema({
date: 'string',
time: 'string',
title: 'string',
content: 'string',
password: 'string'
......@@ -49,11 +50,22 @@ function getCurrentDate(originDate) {
return year + '-' + month + '-' + day;
}
function getCurrentTime() {
var date = new Date();
var hour = date.getHours();
hour = hour < 10 ? '0' + hour.toString() : hour.toString();
var minute = date.getMinutes();
minute = minute < 10 ? '0' + minute.toString() : minute.toString();
return hour + ":" + minute;
}
function arrayEquals(a, b) {
return Array.isArray(a) &&
Array.isArray(b) &&
a.length === b.length &&
a.every((val, index) => val === b[index]);
Array.isArray(b) &&
a.length === b.length &&
a.every((val, index) => val === b[index]);
}
router.get('/api/getList', async (req, res) => { // 오늘 게시물들의 아이디 표시
......@@ -88,10 +100,12 @@ router.post('/api/get', async (req, res) => {
const onePost = await postModel.findById(id);
var tempJSON = {};
tempJSON.id = onePost.id;
tempJSON.time = onePost.time;
tempJSON.title = onePost.title;
tempJSON.content = onePost.content;
tempJSON.content = tempJSON.content.replace(/(?:\r\n|\r|\n)/g, '');
tempJSON.content = tempJSON.content.replace(/(?:\r\n|\r|\n| )/g, '');
const sliceLength = 10;
if (tempJSON.title.length > sliceLength) tempJSON.title = tempJSON.title.slice(0, sliceLength) + "...";
if (tempJSON.content.length > sliceLength) tempJSON.content = tempJSON.content.slice(0, sliceLength) + "...";
resultArray.push(tempJSON);
}
......@@ -105,7 +119,7 @@ router.post('/api/get', async (req, res) => {
router.get('/api/get/:id', async (req, res) => { // 특정 id의 게시물 불러오기
try {
const currentPost = await postModel.findById(req.params.id);
res.send({ title: currentPost.title, content: currentPost.content });
res.send({ date: currentPost.date, time: currentPost.time, title: currentPost.title, content: currentPost.content });
}
catch (err) {
res.send(err.message);
......@@ -127,6 +141,7 @@ router.post('/api/postSave', async (req, res) => {
try {
var isFirst = false;
const today = getCurrentDate();
const time = getCurrentTime();
var testDayPostList = await dayPostListModel.findOne({ date: today });
if (testDayPostList == null) {
......@@ -134,7 +149,7 @@ router.post('/api/postSave', async (req, res) => {
isFirst = true;
}
var postListArr = testDayPostList.idArray;
var newPost = new postModel({ date: today, title: req.body.title, content: req.body.content, password: req.body.password });
var newPost = new postModel({ date: today, time:time, title: req.body.title, content: req.body.content, password: req.body.password });
var newPostData = await newPost.save();
postListArr.push(newPostData._id.toString());
......@@ -166,9 +181,9 @@ router.delete('/api/delete/:id', async (req, res) => {
const id = req.params.id;
const list = await dayPostListModel.find();
for (const dayList of list) {
var newArray = dayList.idArray.filter((data)=>{return data != id;})
if(!arrayEquals(dayList.idArray, newArray)){
await dayPostListModel.findByIdAndUpdate(dayList._id.toString(), {idArray: newArray});
var newArray = dayList.idArray.filter((data) => { return data != id; })
if (!arrayEquals(dayList.idArray, newArray)) {
await dayPostListModel.findByIdAndUpdate(dayList._id.toString(), { idArray: newArray });
}
}
await postModel.findByIdAndDelete(id);
......@@ -195,8 +210,13 @@ router.get('/api/waiting', async (req, res) => {
const time = Number(hour + minute);
var result = [];
<<<<<<< HEAD
for(const waiting of waitingList){
if(time - Number(waiting.time.replace(':','')) <= 100){
=======
for (const waiting of waitingList) {
if (time - Number(waiting.time.replace(':', '')) <= 100) {
>>>>>>> 18c016a2decd0bfd1caea0f6375e92c895b444f3
result.push(waiting)
}
}
......@@ -212,6 +232,7 @@ router.post('/api/waiting', async (req, res) => {
const today = getCurrentDate();
var waitingList = await waitingModel.findOne({ date: today });
<<<<<<< HEAD
const date = new Date();
var hour = date.getHours();
hour = hour < 10 ? '0' + hour.toString() : hour.toString();
......@@ -219,11 +240,15 @@ router.post('/api/waiting', async (req, res) => {
minute = minute < 10 ? '0' + minute.toString() : minute.toString();
const time = hour + ":" + minute;
const newWaiting = {value: req.body.value, time: time};
=======
const time = getCurrentTime();
const newWaiting = { value: req.body.value, time: time };
>>>>>>> 18c016a2decd0bfd1caea0f6375e92c895b444f3
if (waitingList == null) await waitingModel({date: today, waiting: [newWaiting]}).save();
else{
if (waitingList == null) await waitingModel({ date: today, waiting: [newWaiting] }).save();
else {
waitingList.waiting.push(newWaiting);
await waitingModel.findOneAndUpdate({ date: today }, {waiting: waitingList.waiting});
await waitingModel.findOneAndUpdate({ date: today }, { waiting: waitingList.waiting });
}
var waitingListResult = await waitingModel.findOne({ date: today });
......@@ -236,7 +261,11 @@ router.post('/api/waiting', async (req, res) => {
<<<<<<< HEAD
function setting(resultJson){
=======
function setting(resultJson) {
>>>>>>> 18c016a2decd0bfd1caea0f6375e92c895b444f3
var result = {}
result.fo_date = [resultJson.fo_date1, resultJson.fo_date2, resultJson.fo_date3, resultJson.fo_date4, resultJson.fo_date5];
result.fo_menu_lun = [resultJson.fo_menu_lun1, resultJson.fo_menu_lun2, resultJson.fo_menu_lun3, resultJson.fo_menu_lun4, resultJson.fo_menu_lun5];
......@@ -249,40 +278,40 @@ router.get('/api/menuList', async (req, res) => {
let newRequest = new XMLHttpRequest();
newRequest.onreadystatechange = () => {
if (newRequest.status == 200 && newRequest.readyState == 4) {
var dt = new Date();
if (dt.getDay() == 0 || dt.getDay() == 6) {
resJSON0 = JSON.parse(newRequest.responseText).root[0].LASTNEXT[0]
resJSON1 = JSON.parse(newRequest.responseText).root[0].LASTNEXT[1]
if (resJSON0.go === "next_mon") {
let nextRequest = new XMLHttpRequest();
nextRequest.onreadystatechange = () => {
if (nextRequest.status == 200 && nextRequest.readyState == 4) {
newResJSON = JSON.parse(nextRequest.responseText).root[0].WEEKLYMENU[0]
res.send(setting(newResJSON));
}
}
nextRequest.open('POST', 'https://dorm2.khu.ac.kr/food/getWeeklyMenu.kmc')
nextRequest.setRequestHeader('Content-type', 'application/x-www-form-urlencoded')
nextRequest.send("locgbn=K1&sch_date=" + resJSON0.mon_date + "&fo_gbn=stu")
} else if (resJSON1.go === "next_mon") {
let nextRequest = new XMLHttpRequest();
nextRequest.onreadystatechange = () => {
if (nextRequest.status == 200 && nextRequest.readyState == 4) {
newResJSON = JSON.parse(nextRequest.responseText).root[0].WEEKLYMENU[0]
res.send(setting(newResJSON));
}
}
nextRequest.open('POST', 'https://dorm2.khu.ac.kr/food/getWeeklyMenu.kmc')
nextRequest.setRequestHeader('Content-type', 'application/x-www-form-urlencoded')
nextRequest.send("locgbn=K1&sch_date=" + resJSON1.mon_date + "&fo_gbn=stu")
}
if (newRequest.status == 200 && newRequest.readyState == 4) {
var dt = new Date();
if (dt.getDay() == 0 || dt.getDay() == 6) {
resJSON0 = JSON.parse(newRequest.responseText).root[0].LASTNEXT[0]
resJSON1 = JSON.parse(newRequest.responseText).root[0].LASTNEXT[1]
if (resJSON0.go === "next_mon") {
let nextRequest = new XMLHttpRequest();
nextRequest.onreadystatechange = () => {
if (nextRequest.status == 200 && nextRequest.readyState == 4) {
newResJSON = JSON.parse(nextRequest.responseText).root[0].WEEKLYMENU[0]
res.send(setting(newResJSON));
}
}
else {
resJSON = JSON.parse(newRequest.responseText).root[0].WEEKLYMENU[0]
res.send(setting(resJSON));
nextRequest.open('POST', 'https://dorm2.khu.ac.kr/food/getWeeklyMenu.kmc')
nextRequest.setRequestHeader('Content-type', 'application/x-www-form-urlencoded')
nextRequest.send("locgbn=K1&sch_date=" + resJSON0.mon_date + "&fo_gbn=stu")
} else if (resJSON1.go === "next_mon") {
let nextRequest = new XMLHttpRequest();
nextRequest.onreadystatechange = () => {
if (nextRequest.status == 200 && nextRequest.readyState == 4) {
newResJSON = JSON.parse(nextRequest.responseText).root[0].WEEKLYMENU[0]
res.send(setting(newResJSON));
}
}
nextRequest.open('POST', 'https://dorm2.khu.ac.kr/food/getWeeklyMenu.kmc')
nextRequest.setRequestHeader('Content-type', 'application/x-www-form-urlencoded')
nextRequest.send("locgbn=K1&sch_date=" + resJSON1.mon_date + "&fo_gbn=stu")
}
}
else {
resJSON = JSON.parse(newRequest.responseText).root[0].WEEKLYMENU[0]
res.send(setting(resJSON));
}
}
}
newRequest.open('POST', 'https://dorm2.khu.ac.kr/food/getWeeklyMenu.kmc')
newRequest.setRequestHeader('Content-type', 'application/x-www-form-urlencoded')
......@@ -297,16 +326,16 @@ router.get('/api/todayMenu', async (req, res) => {
try {
let newRequest = new XMLHttpRequest();
newRequest.onreadystatechange = () => {
if (newRequest.status == 200 && newRequest.readyState == 4) {
var dt = new Date();
if(dt.getDay() > 0 && dt.getDay() < 6){
resJSON = JSON.parse(newRequest.responseText).root[0].WEEKLYMENU[0];
const weekMenu = setting(resJSON);
const todayMenu = [weekMenu.fo_menu_lun[dt.getDay()-1], weekMenu.fo_menu_eve[dt.getDay()-1]];
res.send(todayMenu);
}else res.send("weekend");
}
if (newRequest.status == 200 && newRequest.readyState == 4) {
var dt = new Date();
if (dt.getDay() > 0 && dt.getDay() < 6) {
resJSON = JSON.parse(newRequest.responseText).root[0].WEEKLYMENU[0];
const weekMenu = setting(resJSON);
const todayMenu = [weekMenu.fo_menu_lun[dt.getDay() - 1], weekMenu.fo_menu_eve[dt.getDay() - 1]];
res.send(todayMenu);
} else res.send("weekend");
}
}
newRequest.open('POST', 'https://dorm2.khu.ac.kr/food/getWeeklyMenu.kmc')
newRequest.setRequestHeader('Content-type', 'application/x-www-form-urlencoded')
......