diff --git a/client/src/apis/plan.api.js b/client/src/apis/plan.api.js index 277456f25d8abdaadc4d977efb03ba88bcd3cadc..c424f09704ee605714abb986fb7d1db9a2141898 100644 --- a/client/src/apis/plan.api.js +++ b/client/src/apis/plan.api.js @@ -11,7 +11,7 @@ const addPlan = async (info, id) => { const editPlan = async (info, id) => { console.log('editPlan확인', id) const url = `${baseUrl}/api/plan/edit/${id}` - const { data } = await axios.put(url, info); + const { data } = await axios.put(url, { info, id }); return data } diff --git a/client/src/components/Card/StudyPlanCard.js b/client/src/components/Card/StudyPlanCard.js index 1ed3be4c04f743dffad3f943722a294102d15851..54772e63dff80ee3f9d234135b081489502bf087 100644 --- a/client/src/components/Card/StudyPlanCard.js +++ b/client/src/components/Card/StudyPlanCard.js @@ -1,57 +1,41 @@ -import { useState } from "react"; import { Link } from "react-router-dom"; import styles from "../Form/form.module.scss"; -const StudyPlanCard = () => { - // studyPlanList에서 props로 받아서 뿌리기 +const StudyPlanCard = ({ renList }) => { + console.log('props 확인', renList) return ( - <> -
-
- -
-
-
운영체제
-
- - -
-
-

김민호 - 과학기술2관 310호

-
-

- ch02 내용정리하기

+
+ +
+
+
{renList.name}
+
+ + +
+
+

{renList.prof && renList.room ? renList.prof + '-' + renList.room : (renList.prof || renList.room)}

+ {renList.planList.length !== 0 ? + renList.planList.map((info, idx) => <>
+

- {info.title}

+ +
+

- {info.title}

-
-
-

- ch03 내용정리하기

+
+

- {info.title}

-
-
- -
-
- {/*계획 없을 때 보여질 카드*/} -
-
-
-
-
네트워크 프로그래밍 및 실습
-
- - -
-
-

임치헌 - 과학기술2관 323호

- +
) + + :

새로운 계획 추가하기

- -
+ }
-
- + +
) } diff --git a/client/src/components/Form/StudyPlanEditForm.js b/client/src/components/Form/StudyPlanEditForm.js index e0fb2932a9d72b317dedcb8986d0244f6f0faa16..91987a1d87e84aab077f07f0e92b20424eea511e 100644 --- a/client/src/components/Form/StudyPlanEditForm.js +++ b/client/src/components/Form/StudyPlanEditForm.js @@ -13,10 +13,10 @@ const StudyPlanEditForm = () => { const [disabled, setDisabled] = useState(true) const [selected, setSelected] = useState(""); const [error, setError] = useState(""); + const [subName, setSubName] = useState(""); const [studyplan, setStudyplan] = useState({ studyplanTitle: "", endDate: "", - deadline: "", memo: "", deadline: "", selected: "" @@ -51,6 +51,26 @@ const StudyPlanEditForm = () => { async function getInfo(id) { const result = await planApi.getDetail(id) console.log('수정 getInfo result', result) + if (result.endTime) { + setStudyplan({ + studyplanTitle: result.title, + endDate: result.endDate, + endTime: result.endTime, + memo: result.memo, + deadline: result.deadline, + selected: result.subjectId + }) + setSubName(result.subjectName) + } else { + setStudyplan({ + studyplanTitle: result.title, + endDate: result.endDate, + memo: result.memo, + deadline: result.deadline, + selected: result.subjectId + }) + setSubName(result.subjectName) + } } async function subjectTitle(id) { @@ -93,7 +113,7 @@ const StudyPlanEditForm = () => { } else { //수정함수 실행 console.log('수정함수') - const result = await planApi.editPlan(studyplan, params.subjectId) + const result = await planApi.editPlan(studyplan, params.planId) console.log('수정 후 result확인', result) } @@ -115,7 +135,7 @@ const StudyPlanEditForm = () => { return (
{
- +
diff --git a/client/src/components/Form/SubjectForm.js b/client/src/components/Form/SubjectForm.js index 656d02a5d98299eb6f48c57a6e89a9fe5ddb8417..d0f91fa4e3d48e9e0c1199e7b53d51914220fbbb 100644 --- a/client/src/components/Form/SubjectForm.js +++ b/client/src/components/Form/SubjectForm.js @@ -49,7 +49,7 @@ const SubjectForm = () => { }) } - async function handleSubmit(e) { + async function handleSubmit(e) { e.preventDefault(); try { setError("") @@ -60,7 +60,15 @@ const SubjectForm = () => { setSuccess(true) } else { //등록함수 실행 - await subjectApi.addsubject(subject, user.id) + const result = await subjectApi.addsubject(subject, user.id) + if (result) { + alert("등록되었습니다") + setSubject({ + lectureName: "", + prof: "", + classRoom: "" + }) + } else alert("등록에 실패하였습니다.") } } catch (error) { catchErrors(error, setError) @@ -72,31 +80,31 @@ const SubjectForm = () => { } } - + if (success) { return } return ( -
-
-
- - -
-
- - -
-
- - -
+
+
+
+ + +
+
+ +
-
- +
+ +
+
+ +
+
) } 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)