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";
import baseUrl from "../utils/baseUrl.js";
const addsubject = async (info, userId) => {
console.log('subject check', userId)
// info.user = userId;
const url = `${baseUrl}/api/subject/addsubject`;
const { data } = await axios.post(url, { info, userId });
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) => {
console.log("editSubject check", info, ',', id)
const url = `${baseUrl}/api/subject/editsubject`
const { data } = await axios.post(url, { info, id })
const url = `${baseUrl}/api/subject/${id}`
const { data } = await axios.put(url, info)
return data
}
const getSubInfo = async (info) => {
console.log('info', info)
const url = `${baseUrl}/api/subject/${info}`
const { data } = await axios.get(url);
return data
}
const subjectTitle = async (info) => {
const url = `${baseUrl}/api/subject/title/${info}`
const { data } = await axios.get(url);
return data
}
const subjectApi = {
addsubject,
getSubInfo,
editSubject
editSubject,
allSubject,
subjectTitle
};
export default subjectApi
\ No newline at end of file
......@@ -3,10 +3,7 @@ import styles from "./buttons.module.scss";
const EditBtn = ({ pathname }) => {
return (
<Link className="me-2 mb-1" to={{
pathname: "/" + pathname,
state: {}
}}>
<Link className="me-2 mb-1" to={"/" + pathname}>
<i className={`bi bi-plus-circle ${styles.icon}`}></i>
</Link>
)
......
......@@ -22,7 +22,7 @@ const addsubject = 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 {
const { subjectId } = req.params;
const findSubInfo = await Subject.findOne({ where: { id: subjectId } })
......@@ -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 {
addsubject,
getSubInfo,
editSubject
editSubject,
allSubject,
subjectTitle
}
\ No newline at end of file
......@@ -8,12 +8,16 @@ router
.post(subjectCtrl.addsubject)
router
.route("/:subjectId")
.get(subjectCtrl.getSubInfo)
.route("/all/:userId")
.get(subjectCtrl.allSubject)
router
.route("/editsubject")
.post(subjectCtrl.editSubject)
.route("/title/:userId")
.get(subjectCtrl.subjectTitle)
router
.route("/:subjectId")
.put(subjectCtrl.editSubject)
.get(subjectCtrl.getSubInfo)
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