Commit 74e4b4db authored by Kim, Subin's avatar Kim, Subin
Browse files

Plan 완성

parent bb632885
...@@ -7,20 +7,6 @@ const getDetail = async (planId) => { ...@@ -7,20 +7,6 @@ const getDetail = async (planId) => {
return data return data
} }
// const addPlan = async (info, id) => {
// console.log('addPlan 확인', id)
// const url = `${baseUrl}/api/plan/addplan/${id}`
// const { data } = await axios.post(url, { info, id });
// return data
// }
// const editPlan = async (info, id) => {
// console.log('editPlan확인', id)
// const url = `${baseUrl}/api/plan/edit/${id}`
// const { data } = await axios.put(url, { info, id });
// return data
// }
const submit = async (info) => { const submit = async (info) => {
const url = `${baseUrl}/api/plan` const url = `${baseUrl}/api/plan`
const { data } = await axios.post(url, info) const { data } = await axios.post(url, info)
...@@ -41,8 +27,6 @@ const remove = async (planId) => { ...@@ -41,8 +27,6 @@ const remove = async (planId) => {
const planApi = { const planApi = {
getDetail, getDetail,
// addPlan,
// editPlan,
submit, submit,
edit, edit,
remove remove
......
...@@ -11,10 +11,8 @@ const StudyPlanEditForm = () => { ...@@ -11,10 +11,8 @@ const StudyPlanEditForm = () => {
const { user } = useAuth(); const { user } = useAuth();
const params = useParams(); const params = useParams();
const [disabled, setDisabled] = useState(true) const [disabled, setDisabled] = useState(true)
const [selected, setSelected] = useState("");
const [error, setError] = useState(""); const [error, setError] = useState("");
const [success, setSuccess] = useState(false) const [success, setSuccess] = useState(false)
const [subjectName, setSubjectName] = useState("");
const [studyplan, setStudyplan] = useState({ const [studyplan, setStudyplan] = useState({
studyplanTitle: "", studyplanTitle: "",
endDate: "", endDate: "",
...@@ -43,13 +41,8 @@ const StudyPlanEditForm = () => { ...@@ -43,13 +41,8 @@ const StudyPlanEditForm = () => {
useEffect(() => { useEffect(() => {
getSubject(user.id) getSubject(user.id)
console.log("useEffect params 확인", params)
if (params.subjectId) setStudyplan({...studyplan, selected: params.subjectId }) if (params.subjectId) setStudyplan({...studyplan, selected: params.subjectId })
else if (params.planId) getInfo(params.planId); else if (params.planId) getInfo(params.planId);
// if (params.hasOwnProperty('planId')) {
// console.log('planId params확인');
// getInfo(params.planId);
// }
}, []) }, [])
async function getSubject(id) { async function getSubject(id) {
...@@ -66,29 +59,7 @@ const StudyPlanEditForm = () => { ...@@ -66,29 +59,7 @@ const StudyPlanEditForm = () => {
try { try {
setError("") setError("")
const result = await planApi.getDetail(planId) const result = await planApi.getDetail(planId)
console.log('수정 getInfo result', result)
setStudyplan({ ...studyplan, ...result }) setStudyplan({ ...studyplan, ...result })
// setSubjectName(result.subjectName)
// if (result.endTime) {
// setStudyplan({
// studyplanTitle: result.title,
// endDate: result.endDate,
// endTime: result.endTime,
// memo: result.memo,
// deadline: result.deadline,
// selected: result.subjectId
// })
// setSubjectName(result.subjectName)
// } else {
// setStudyplan({
// studyplanTitle: result.title,
// endDate: result.endDate,
// memo: result.memo,
// deadline: result.deadline,
// selected: result.subjectId
// })
// setSubjectName(result.subjectName)
// }
} catch (error) { } catch (error) {
catchErrors(error, setError) catchErrors(error, setError)
} }
......
import { Link } from "react-router-dom"; import { Link } from "react-router-dom";
import styles from "../Form/form.module.scss"; import styles from "./studyplan.module.scss";
const PlanLineList = ({ subjectId, planList = [] }) => { const PlanLineList = ({ subjectId, planList = [] }) => {
return ( return (
<> <>
{planList.length !== 0 ? planList.map(plan => <div className="d-flex justify-content-between"> {planList.length !== 0 ? planList.map(plan => <div className="d-flex justify-content-between">
<p className="card-text mb-1">- {plan.title}</p> <p className={`card-text mb-1 ${styles.text}`}>- {plan.title}</p>
<input className={`form-check-input shadow-none ${styles.checkBox}`} type="checkbox" /> <input className={`form-check-input shadow-none ${styles.checkBox}`} type="checkbox" />
</div>) : <Link className="text-decoration-none link-dark" to={`/studyplan/submit/${subjectId}`}> </div>) : <Link className="text-decoration-none link-dark" to={`/studyplan/submit/${subjectId}`}>
<div className="d-flex"> <div className="d-flex">
......
...@@ -16,3 +16,9 @@ ...@@ -16,3 +16,9 @@
background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='currentColor' d='M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0z'/%3e%3c/svg%3e"); background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='currentColor' d='M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0z'/%3e%3c/svg%3e");
} }
} }
.text {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
\ No newline at end of file
import { Plan, Subject } from "../db/index.js"; import { Plan } from "../db/index.js";
import * as ConvertDate from "./schedule.controller.js"; import { dateToString } from "./schedule.controller.js";
// const addPlan = async (req, res) => {
// console.log('server/addPlan req.body', req.body)
// try {
// let end = null;
// let tf = false;
// const { info } = req.body
// const { studyplanTitle, endDate, endTime, deadline, memo, selected } = info
// console.log('제목확인', studyplanTitle)
// if (deadline === "on") {
// end = new Date(endDate + " " + endTime)
// tf = true
// } else {
// end = new Date(endDate)
// }
// const result = await Plan.create({
// subjectId: selected,
// title: studyplanTitle,
// deadline: end,
// memo: memo,
// timeChecked: tf,
// checked: false
// })
// return res.json(result)
// } catch (error) {
// console.log(error)
// return res.status(500).send(error.message || "계획저장 에러발생")
// }
// }
// const editPlan = async (req, res) => {
// 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 || "계획수정 에러발생")
// }
// }
// 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 } })
// 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 || "계획 가져오기 에러발생")
// }
// }
const getOne = async (req, res) => { const getOne = async (req, res) => {
try { try {
let findPlan = null let sendPlan = null
const { planId } = req.query const planId = req.planId
console.log("get One", planId) const findPlan = await Plan.findOne({ where: { id: planId } })
if (planId) findPlan = await Plan.findOne({ where: { id: planId } })
if (!findPlan) throw new Error("학업 계획 정보를 찾지 못했습니다.") if (!findPlan) throw new Error("학업 계획 정보를 찾지 못했습니다.")
return res.json(find) else {
const { id, title, deadline, memo, timeChecked, checked, subjectId } = findPlan
const endDate = dateToString(deadline, "full")
if (timeChecked) {
const endTime = dateToString(deadline, "time")
sendPlan = { id: id, studyplanTitle: title, endDate: endDate, endTime: endTime, deadline: timeChecked ? "on" : "off", memo: memo, selected: subjectId }
} else sendPlan = { id: id, studyplanTitle: title, endDate: endDate, deadline: timeChecked ? "on" : "off", memo: memo, selected: subjectId }
}
return res.json(sendPlan)
} catch (error) { } catch (error) {
return res.status(500).send(error.message || "학업계획 조회 중 에러 발생") return res.status(500).send(error.message || "학업계획 조회 중 에러 발생")
} }
...@@ -151,7 +47,7 @@ const edit = async (req, res) => { ...@@ -151,7 +47,7 @@ const edit = async (req, res) => {
date = new Date(endDate + " " + endTime) date = new Date(endDate + " " + endTime)
check_v = true check_v = true
} else date = new Date(endDate) } else date = new Date(endDate)
const updated = await Plan.updated({ title: studyplanTitle, deadline: date, memo: memo, timeChecked: check_v, subjectId: selected }, { where: { id: planId } }) const updated = await Plan.update({ title: studyplanTitle, deadline: date, memo: memo, timeChecked: check_v, subjectId: selected }, { where: { id: planId } })
if (!updated) throw new Error("해당 학업계획의 일부 정보를 수정하는데 실패하였습니다.") if (!updated) throw new Error("해당 학업계획의 일부 정보를 수정하는데 실패하였습니다.")
else return res.send(200) else return res.send(200)
} catch (error) { } catch (error) {
...@@ -186,7 +82,4 @@ export default { ...@@ -186,7 +82,4 @@ export default {
edit, edit,
remove, remove,
getParams getParams
// addPlan,
// editPlan,
// getInfo
} }
\ 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