)
}
diff --git a/client/src/components/Card/StudyPlanCard.js b/client/src/components/StudyPlan/StudyPlanCard.js
similarity index 92%
rename from client/src/components/Card/StudyPlanCard.js
rename to client/src/components/StudyPlan/StudyPlanCard.js
index a6b1bd1b5a38ea48549d1dbc97d1937ace4c68e9..5c1a036e34bf11cfb6146e6e3c69900a175a1322 100644
--- a/client/src/components/Card/StudyPlanCard.js
+++ b/client/src/components/StudyPlan/StudyPlanCard.js
@@ -1,5 +1,5 @@
import { Link } from "react-router-dom";
-import PlanLineList from "../StudyPlan/PlanLineList";
+import PlanLineList from "./PlanLineList";
const StudyPlanCard = ({ renList }) => {
diff --git a/client/src/components/StudyPlanList.js b/client/src/components/StudyPlan/StudyPlanList.js
similarity index 80%
rename from client/src/components/StudyPlanList.js
rename to client/src/components/StudyPlan/StudyPlanList.js
index 0595e61a78a969417aa0f6bb94395df04699b69a..b9a82d016eb7f5416fe62080a6a39fc14f0007b4 100644
--- a/client/src/components/StudyPlanList.js
+++ b/client/src/components/StudyPlan/StudyPlanList.js
@@ -1,10 +1,10 @@
import { useState, useEffect } from 'react';
import { Link } from "react-router-dom";
-import StudyPlanCard from "./Card/StudyPlanCard";
-import subjectApi from '../apis/subject.api';
-import catchErrors from "../utils/catchErrors";
-import { useAuth } from "../utils/context";
-import styles from "./StudyPlan/studyplan.module.scss";
+import StudyPlanCard from "./StudyPlanCard";
+import subjectApi from '../../apis/subject.api';
+import catchErrors from "../../utils/catchErrors";
+import { useAuth } from "../../utils/context";
+import styles from "./studyplan.module.scss";
const StudyPlanList = () => {
const { user } = useAuth();
diff --git a/client/src/components/TodoList.js b/client/src/components/TodoList.js
index 23ee2833424d04e970409485e1197e1373b551de..daa3b52d4d32c75cc488cd9c2d1f0f8e53ea1e06 100644
--- a/client/src/components/TodoList.js
+++ b/client/src/components/TodoList.js
@@ -1,21 +1,72 @@
+import { useState, useEffect } from "react";
+import { useParams } from "react-router-dom";
import TodoModal from "../components/Modal/TodoModal";
import TodoPostModal from "../components/Modal/TodoPostModal";
+import todoApi from "../apis/todo.api";
+import { useAuth } from "../utils/context";
+import catchErrors from "../utils/catchErrors";
+import moment from "moment";
import styles from "../components/Form/form.module.scss";
const TodoList = () => {
+ const { user } = useAuth()
+ const { date } = useParams()
+ const [todoList, setTodoList] = useState([])
+ const [selectTodo, setSelectTodo] = useState(null)
+ const [error, setError] = useState("");
+
+ useEffect(() => {
+ getAll()
+ }, [date])
+
+ async function getAll() {
+ try {
+ setError("")
+ const resList = await todoApi.getTodo(user.id, date)
+ setTodoList(resList)
+ } catch (error) {
+ catchErrors(error, setError)
+ }
+ }
+
+ async function delayTodo() {
+ try {
+ setError("")
+ const nextDate = moment(date).add(1, 'day').format("YYYY-MM-DD")
+ await todoApi.edit({ id: selectTodo.id, todoDate: nextDate }, user.id)
+ getAll()
+ } catch (error) {
+ catchErrors(error, setError)
+ }
+ }
+
+ async function delTodo(todoId) {
+ try {
+ setError("")
+ await todoApi.remove(todoId, user.id)
+ alert("해당 할일이 성공적으로 삭제되었습니다.")
+ getAll()
+ } catch (error) {
+ catchErrors(error, setError)
+ }
+ }
return (
-
-
-
-
-
-
-
-
-
-
-
+
+ {todoList.length !== 0 ?
+ todoList.map((todo, idx) => <>
+
+
+
+
+
+ setSelectTodo(todo)}>
+ setSelectTodo(todo)}>
+ delTodo(todo.id)}>
+
+ >) :
등록된 할일이 없습니다.
}
+
+
)
}
diff --git a/client/src/pages/StudyPlanListPage.js b/client/src/pages/StudyPlanListPage.js
index 54ba45e38c440de3e42fe70d7209304497331a57..aeba4c016cca79fba9fd1a076dff363bfa06df4f 100644
--- a/client/src/pages/StudyPlanListPage.js
+++ b/client/src/pages/StudyPlanListPage.js
@@ -1,6 +1,6 @@
import Menu from "../components/Menu/Menu";
import HomeBtn from "../components/Buttons/HomeBtn";
-import StudyPlanList from "../components/StudyPlanList";
+import StudyPlanList from "../components/StudyPlan/StudyPlanList";
const StudyPlanListPage = () => {
return (
diff --git a/client/src/pages/ToDoPage.js b/client/src/pages/ToDoPage.js
index 5acaeeeaa9a8f497daaa8504b2864eb814b479af..5a508ff3d1abbc02eaa16b981e088f4144190cec 100644
--- a/client/src/pages/ToDoPage.js
+++ b/client/src/pages/ToDoPage.js
@@ -6,14 +6,14 @@ import Footer from "../components/Footer";
const ToDoPage = () => {
return (
- <>
+
To-do
- >
+
)
}
diff --git a/server/controllers/todo.controller.js b/server/controllers/todo.controller.js
index 8a27637e40ba9357ce3e5a6ef93226512a32f79a..f2086d9d29883ccead2565c123e2bd0fe2464eb4 100644
--- a/server/controllers/todo.controller.js
+++ b/server/controllers/todo.controller.js
@@ -1,9 +1,103 @@
import { Todo } from '../db/index.js';
+import sequelize from 'sequelize';
-const AddTodo = async(req, res)=>{
+const { Op } = sequelize
+const findbyId = async (req, res, next) => {
+ try {
+ const userId = req.userId
+ const { todoId } = req.query
+ if (todoId) {
+ console.log(" findbyId todoId가 있을 때 실행", todoId)
+ const findTodo = await Todo.findOne({ where: { [Op.and]: [{ id: todoId }, { userId: userId }] }, attributes: ['id', ['title', 'todoTitle'], ['date', 'todoDate'], 'done'] })
+ if (!findTodo) throw new Error("해당 todo를 찾지 못했습니다.")
+ req.todoOne = findTodo
+ }
+ next()
+ } catch (error) {
+ return res.status(500).send(error.message || "todo 가져오는 중 에러 발생")
+ }
}
-export default{
- AddTodo,
+const findbyDate = async (req, res, next) => {
+ try {
+ const userId = req.userId
+ const { date } = req.query
+ if (date) {
+ console.log(" findbydate 날짜가 있을 때 실행", date, userId)
+ const findList = await Todo.findAll({ where: { [Op.and]: [{ date: { [Op.eq]: date } }, { userId: userId }] }, attributes: ['id', ['title', 'todoTitle'], ['date', 'todoDate'], 'done'] })
+ console.log("find==", findList)
+ req.todoList = findList
+ }
+ next()
+ } catch (error) {
+ return res.status(500).send(error.message || "todo 가져오는 중 에러 발생")
+ }
+}
+
+const create = async (req, res) => {
+ try {
+ const userId = req.userId
+ const { todoTitle, todoDate } = req.body
+ const newTodo = await Todo.create({ title: todoTitle, date: todoDate, userId: userId })
+ return res.json(newTodo)
+ } catch (error) {
+ return res.status(500).send(error.message || "todo 등록 중 에러 발생")
+ }
+}
+
+const edit = async (req, res) => {
+ try {
+ let updated = null
+ const userId = req.userId
+ const { todoId } = req.query
+ const { todoTitle, todoDate } = req.body
+ if (todoTitle) updated = await Todo.update({ title: todoTitle, date: todoDate }, { where: { [Op.and]: [{ id: todoId }, { userId: userId }] } })
+ else updated = await Todo.update({ date: todoDate }, { where: { [Op.and]: [{ id: todoId }, { userId: userId }] } })
+ if (!updated) throw new Error("해당 todo의 일부 정보를 수정하는데 실패하였습니다.")
+ else return res.send(200)
+ } catch (error) {
+ return res.status(500).send(error.message || "todo 수정 중 에러 발생")
+ }
+}
+
+const remove = async (req, res) => {
+ try {
+ const userId = req.userId
+ const { todoId } = req.query
+ const deleted = await Todo.destroy({ where: { [Op.and]: [{ id: todoId }, { userId: userId }] } })
+ if (!deleted) throw new Error("해당 todo를 삭제하는데 실패하였습니다.")
+ else return res.send(200)
+ } catch (error) {
+ return res.status(500).send(error.message || "todo 삭제 중 에러 발생")
+ }
+}
+
+const getParams = async (req, res, next) => {
+ try {
+ const { userId } = req.params
+ req.userId = userId
+ next()
+ } catch (error) {
+ return res.status(500).send(error.message || "todo 가져오는 중 에러 발생")
+ }
+}
+
+const send = async (req, res) => {
+ try {
+ const result = req.todoOne || req.todoList
+ return res.json(result)
+ } catch (error) {
+ return res.status(500).send(error.message || "todo 가져오는 중 에러 발생")
+ }
+}
+
+export default {
+ findbyId,
+ findbyDate,
+ create,
+ edit,
+ remove,
+ getParams,
+ send
}
\ No newline at end of file
diff --git a/server/db/index.js b/server/db/index.js
index d2e2243700b0605fd77fe58a351896985b356366..52de16950392337b7afad58c0c06060a534f34c9 100644
--- a/server/db/index.js
+++ b/server/db/index.js
@@ -33,6 +33,7 @@ const Plan = PlanModel(sequelize)
Schedule.belongsTo(User)
Subject.belongsTo(User)
+Todo.belongsTo(User)
Plan.belongsTo(Subject)
export {
diff --git a/server/routes/index.js b/server/routes/index.js
index dacd8a9cad5098819e4411323afec36ae5ccffa9..f035c8964eff8b177b5cdb34e8dfc785c37cd0c9 100644
--- a/server/routes/index.js
+++ b/server/routes/index.js
@@ -2,7 +2,8 @@ import express from "express";
import userRouter from './user.route.js';
import scheduleRouter from "./schedule.route.js";
import subjectRouter from './subject.route.js';
-import planRouter from './plan.route.js'
+import planRouter from './plan.route.js';
+import todoRouter from "./todo.route.js";
const router = express.Router();
@@ -10,5 +11,6 @@ router.use('/auth', userRouter)
router.use('/schedule', scheduleRouter)
router.use('/subject', subjectRouter)
router.use('/plan', planRouter)
+router.use('/todo', todoRouter)
export default router;
\ No newline at end of file
diff --git a/server/routes/todo.route.js b/server/routes/todo.route.js
new file mode 100644
index 0000000000000000000000000000000000000000..d1af3e5ebf0704aa7188e812882801efaa3dde2a
--- /dev/null
+++ b/server/routes/todo.route.js
@@ -0,0 +1,15 @@
+import express from 'express';
+import todoCtrl from "../controllers/todo.controller.js";
+
+const router = express.Router();
+
+router
+ .route("/:userId")
+ .get(todoCtrl.findbyId, todoCtrl.findbyDate, todoCtrl.send)
+ .post(todoCtrl.create)
+ .put(todoCtrl.edit)
+ .delete(todoCtrl.remove)
+
+router.param("userId", todoCtrl.getParams)
+
+export default router;
\ No newline at end of file