Commit fd8277ba authored by Choi Ga Young's avatar Choi Ga Young
Browse files

subject관련

parent 2eb32b90
...@@ -2,31 +2,41 @@ import axios from "axios"; ...@@ -2,31 +2,41 @@ import axios from "axios";
import baseUrl from "../utils/baseUrl.js"; import baseUrl from "../utils/baseUrl.js";
const addsubject = async (info, userId) => { const addsubject = async (info, userId) => {
console.log('subject check', userId)
// info.user = userId;
const url = `${baseUrl}/api/subject/addsubject`; const url = `${baseUrl}/api/subject/addsubject`;
const { data } = await axios.post(url, { info, userId }); const { data } = await axios.post(url, { info, userId });
return data return data
} }
const allSubject = async (info) => {
const url = `${baseUrl}/api/subject/all/${info}`
const { data } = await axios.get(url);
return data
}
const editSubject = async (info, id) => { const editSubject = async (info, id) => {
console.log("editSubject check", info, ',', id) const url = `${baseUrl}/api/subject/${id}`
const url = `${baseUrl}/api/subject/editsubject` const { data } = await axios.put(url, info)
const { data } = await axios.post(url, { info, id })
return data return data
} }
const getSubInfo = async (info) => { const getSubInfo = async (info) => {
console.log('info', info)
const url = `${baseUrl}/api/subject/${info}` const url = `${baseUrl}/api/subject/${info}`
const { data } = await axios.get(url); const { data } = await axios.get(url);
return data return data
} }
const subjectTitle = async (info) => {
const url = `${baseUrl}/api/subject/title/${info}`
const { data } = await axios.get(url);
return data
}
const subjectApi = { const subjectApi = {
addsubject, addsubject,
getSubInfo, getSubInfo,
editSubject editSubject,
allSubject,
subjectTitle
}; };
export default subjectApi export default subjectApi
\ No newline at end of file
...@@ -3,10 +3,7 @@ import styles from "./buttons.module.scss"; ...@@ -3,10 +3,7 @@ import styles from "./buttons.module.scss";
const EditBtn = ({ pathname }) => { const EditBtn = ({ pathname }) => {
return ( return (
<Link className="me-2 mb-1" to={{ <Link className="me-2 mb-1" to={"/" + pathname}>
pathname: "/" + pathname,
state: {}
}}>
<i className={`bi bi-plus-circle ${styles.icon}`}></i> <i className={`bi bi-plus-circle ${styles.icon}`}></i>
</Link> </Link>
) )
......
...@@ -22,7 +22,7 @@ const addsubject = async (req, res) => { ...@@ -22,7 +22,7 @@ const addsubject = async (req, res) => {
} }
const getSubInfo = async (req, res) => { const getSubInfo = async (req, res) => {
console.log('server/getSubInfo req.body', req.params) console.log('server/getSubInfo req.params', req.params)
try { try {
const { subjectId } = req.params; const { subjectId } = req.params;
const findSubInfo = await Subject.findOne({ where: { id: subjectId } }) const findSubInfo = await Subject.findOne({ where: { id: subjectId } })
...@@ -61,8 +61,56 @@ const editSubject = async (req, res) => { ...@@ -61,8 +61,56 @@ const editSubject = async (req, res) => {
} }
} }
const allSubject = async (req, res) => {
console.log('server/allSubject req.params', req.params)
try {
const { userId } = req.params;
const findAllInfo = await Subject.findAll({ where: { userId: userId } })
const sublist = findAllInfo.map(info => {
const newList = {
id: info.id,
name: info.name,
prof: info.prof,
room: info.room,
time: info.updatedAt
}
return newList
})
// const addplanlist = sublist.map(async(info)=>{
// const resplan = await Plan
// })
} catch (error) {
console.log(error)
return res.status(500).send(error.message || "전체과목 조회 에러")
}
}
const subjectTitle = async (req, res) => {
console.log('server/subjectTitle req.params', req.params)
try {
const { userId } = req.params
const findAllTitle = await Subject.findAll({ where: { userId: userId } })
const sublist = findAllTitle.map(info => {
const newList = {
id: info.id,
name: info.name,
}
return newList
})
res.json(sublist)
} catch (error) {
console.log(error)
return res.status(500).send(error.message || "과목명 조회 에러")
}
}
export default { export default {
addsubject, addsubject,
getSubInfo, getSubInfo,
editSubject editSubject,
allSubject,
subjectTitle
} }
\ No newline at end of file
...@@ -8,12 +8,16 @@ router ...@@ -8,12 +8,16 @@ router
.post(subjectCtrl.addsubject) .post(subjectCtrl.addsubject)
router router
.route("/:subjectId") .route("/all/:userId")
.get(subjectCtrl.getSubInfo) .get(subjectCtrl.allSubject)
router router
.route("/editsubject") .route("/title/:userId")
.post(subjectCtrl.editSubject) .get(subjectCtrl.subjectTitle)
router
.route("/:subjectId")
.put(subjectCtrl.editSubject)
.get(subjectCtrl.getSubInfo)
export default router; export default router;
\ 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