+
+
+
+
+
+
+
+
-
+
+
+
+
)
}
diff --git a/client/src/components/StudyPlanList.js b/client/src/components/StudyPlanList.js
index eb6e26082a226d2fc76a512cb09e97a3bc7fab54..b513ec9acd119e8f9293139980f450d9cd499514 100644
--- a/client/src/components/StudyPlanList.js
+++ b/client/src/components/StudyPlanList.js
@@ -3,20 +3,24 @@ import { useAuth } from "../utils/context";
import { Link } from "react-router-dom";
import StudyPlanCard from "./Card/StudyPlanCard";
import subjectApi from '../apis/subject.api';
+import styles from "./StudyPlan/studyplan.module.scss";
const StudyPlanList = () => {
const { user } = useAuth();
+ const [renList, setRenList] = useState([]);
+
useEffect(() => {
getList(user.id);
}, [])
async function getList(id) {
const result = await subjectApi.allSubject(id)
+ setRenList(result)
}
-
+ //여기서 삭제함수 만들어서 StudyPlanCard에게 넘기기
return (
- <>
-
+
+ {renList.length !== 0 ? renList.map((info, idx) =>
) : null}
@@ -27,7 +31,7 @@ const StudyPlanList = () => {
- >
+
)
}
diff --git a/server/controllers/plan.controller.js b/server/controllers/plan.controller.js
index 650a34f912730c9591536756b4613f45b5eacd5b..f489d9e0d16162b784f025e1848d65660ade75a6 100644
--- a/server/controllers/plan.controller.js
+++ b/server/controllers/plan.controller.js
@@ -1,4 +1,5 @@
-import { Plan } from "../db/index.js";
+import { Plan, Subject } from "../db/index.js";
+import * as ConvertDate from "./schedule.controller.js";
const addPlan = async (req, res) => {
console.log('server/addPlan req.body', req.body)
@@ -30,9 +31,37 @@ const addPlan = async (req, res) => {
}
const editPlan = async (req, res) => {
- console.log('server/editPlan req.body', req.body)
+ const { info, id } = req.body
+ console.log('editPlan info', info, '|', id)
try {
-
+ let result = null
+ if (info.deadline === "on") {
+ result = await Plan.update({
+ subjectId: info.selected,
+ title: info.studyplanTitle,
+ deadline: new Date(info.endDate + " " + info.endTime),
+ memo: info.memo,
+ timeChecked: true,
+ checked: false
+ }, { where: { id: id } })
+ res.send(200)
+ } else {
+ result = await Plan.update({
+ subjectId: info.selected,
+ title: info.studyplanTitle,
+ deadline: new Date(info.endDate),
+ memo: info.memo,
+ timeChecked: false,
+ checked: false
+ }, {
+ where: { id: id }
+ })
+ }
+ if (!result) {
+ throw new Error("과목정보 수정 에러발생")
+ } else {
+ return res.send(200)
+ }
} catch (error) {
console.log(error)
return res.status(500).send(error.message || "계획수정 에러발생")
@@ -42,9 +71,41 @@ const editPlan = async (req, res) => {
const getInfo = async (req, res) => {
console.log('server/getInfo req.params', req.params)
try {
+ let deadlineStr = null
+ let endTimeStr = null
+
const { planId } = req.params;
const findInfo = await Plan.findOne({ where: { id: planId } })
- console.log('findInfo확인', findInfo.dataValues)
+ const Info = findInfo.dataValues;
+
+ const getSubTitle = await Subject.findAll({
+ attributes: ['name'],
+ where: { id: Info.subjectId }
+ })
+
+ deadlineStr = ConvertDate.dateToString(Info.deadline, "full")
+ endTimeStr = ConvertDate.dateToString(Info.deadline, "time")
+
+ if (Info.timeChecked) {
+ res.json({
+ subjectId: Info.subjectId,
+ subjectName: getSubTitle[0].dataValues.name,
+ title: Info.title,
+ endDate: deadlineStr,
+ endTime: endTimeStr,
+ deadline: "on",
+ memo: Info.memo
+ })
+ } else {
+ res.json({
+ subjectId: Info.subjectId,
+ subjectName: getSubTitle[0].dataValues.name,
+ title: Info.title,
+ endDate: deadlineStr,
+ deadline: "",
+ memo: Info.memo
+ })
+ }
} catch (error) {
console.log(error)
return res.status(500).send(error.message || "계획 가져오기 에러발생")
diff --git a/server/controllers/schedule.controller.js b/server/controllers/schedule.controller.js
index 218817b53eec404c976a6a920c5c4563cadb43fb..c4d3bcec6875d27023814f6efa1293f9afdae5c2 100644
--- a/server/controllers/schedule.controller.js
+++ b/server/controllers/schedule.controller.js
@@ -282,7 +282,7 @@ const send = async (req, res) => {
}
}
-function dateToString(dateObj, method) {
+export function dateToString(dateObj, method) {
const year = dateObj.getFullYear()
const year_disit = String(year).substring(2, 4)
const month = dateObj.getMonth() + 1
diff --git a/server/controllers/subject.controller.js b/server/controllers/subject.controller.js
index 68a3476484da0804fc36ea9ef44844d5c00c636a..1da9cbb2186c2205bd3b70e59833493e56e5154d 100644
--- a/server/controllers/subject.controller.js
+++ b/server/controllers/subject.controller.js
@@ -1,4 +1,4 @@
-import { Subject } from '../db/index.js';
+import { Subject, Plan } from '../db/index.js';
const addsubject = async (req, res) => {
console.log('server/addsubject req.body', req.body)
@@ -8,12 +8,17 @@ const addsubject = async (req, res) => {
if (findName) {
throw new Error("이미 있는 과목입니다.")
}
- await Subject.create({
+ const result = await Subject.create({
name: info.lectureName,
prof: info.prof,
- room: info.classRoom,
+ room: info.classRoom,
userId: userId
})
+ if (!result) {
+ throw new Error("과목추가 에러발생")
+ } else {
+ return res.send(200)
+ }
} catch (error) {
console.log(error)
@@ -53,7 +58,7 @@ const editSubject = async (req, res) => {
if (!result) {
throw new Error("과목정보 수정 에러발생")
} else {
- res.send(200)
+ return res.send(200)
}
} catch (error) {
console.log(error)
@@ -76,10 +81,14 @@ const allSubject = async (req, res) => {
}
return newList
})
- // const addplanlist = sublist.map(async(info)=>{
- // const resplan = await Plan
- // })
+ const addplanlist = await Promise.all(sublist.map(async (info) => {
+ const resplan = await Plan.findAll({ where: { subjectId: info.id } })
+ info.planList = resplan
+ return info
+ }))
+
+ return res.json(addplanlist)
} catch (error) {
console.log(error)