Commit 229f8a70 authored by Kim, Subin's avatar Kim, Subin
Browse files

Merge remote-tracking branch 'origin/rkyoung7'

parents 54044c94 7176f8e0
......@@ -28,6 +28,7 @@ function App() {
<Route path="/studyplan/edit" component={StudyPlanEditPage} />
<Route path="/studyplan/:" component={StudyPlanPage} />
<Route path="/studyplan" component={StudyPlanListPage} />
<Route path="/subject/edit/:subjectId" component={SubjectEditPage} />
<Route path="/subject/edit" component={SubjectEditPage} />
<Route path="/admin/edit" component={ScheduleEditPage} />
<Route path="/admin" component={AdminPage} />
......
import axios from "axios";
const addsubject = async (info) => {
console.log('info확인', info)
const url = `/api/subject/addsubject`;
const { data, status } = await axios.post(url, info);
console.log('data status', data, '|', status)
return { data, status }
}
const subjectApi = {
addsubject
};
export default subjectApi
\ No newline at end of file
import { useHistory } from "react-router-dom";
import styles from "./buttons.module.scss";
const BtnGroup = ({ disabled }) => {
const BtnGroup = ({ disabled, handleSubmit }) => {
const history = useHistory();
return (
<div className="d-flex justify-content-around my-4">
<button className="btn btn-white col-5 shadow-none border-dark" type="button" onClick={() => history.goBack()}>취소</button>
<button className={`btn btn-crimson col-5 ${styles.disabledBtn}`} type="submit" disabled={disabled}>등록</button>
<button className={`btn btn-crimson col-5 ${styles.disabledBtn}`} type="button" onClick={handleSubmit} disabled={disabled}>등록</button>
</div>
)
}
......
import { useState, useEffect } from 'react';
import BtnGroup from "../Buttons/BtnGroup";
import styles from "./form.module.scss";
import { useParams } from 'react-router-dom';
import subjectApi from '../../apis/subject.api';
import catchErrors from '../../utils/catchErrors.js';
const SubjectForm = () => {
const { subjectId } = useParams();
const [error, setError] = useState("");
const [subject, setSubject] = useState({
lectureName: "",
prof: "",
......@@ -28,6 +33,22 @@ const SubjectForm = () => {
setSubject({ ...subject, [name]: value })
}
async function handleSubmit(e) {
e.preventDefault();
try {
if (subjectId) {
//수정함수 실행
} else {
await subjectApi.addsubject(subject)
}
} catch (error) {
catchErrors(error, setError)
}
}
return (
<>
<div className="position-absolute top-50 start-50 translate-middle" style={{ width: "80%" }}>
......@@ -46,7 +67,7 @@ const SubjectForm = () => {
</div>
</div>
<div className="pt-2">
<BtnGroup disabled={disabled} />
<BtnGroup disabled={disabled} handleSubmit={handleSubmit} />
</div>
</div>
</>
......
......@@ -12,7 +12,7 @@ const StudyPlanList = () => {
<div className="card">
<div className="card-body d-flex flex-column bg-secondary bg-opacity-25 ">
<div>
<i class="bi bi-plus-lg d-flex justify-content-center fs-3"></i>
<i className="bi bi-plus-lg d-flex justify-content-center fs-3"></i>
<p className="card-text mt-2 text-center">새로운 과목 추가하기</p>
</div>
</div>
......
import { Subject } from '../db/index.js';
const addsubject = async (req, res) => {
console.log('server/addsubject req.body', req.body)
const { lectureName, prof, classRoom } = req.body;
try {
const findName = await Subject.findOne({ where: { name: lectureName } });
if (findName) {
throw new Error("이미 있는 과목입니다.")
}
await Subject.create({
name: lectureName,
prof: prof,
room: classRoom,
})
} catch (error) {
console.log(error)
return res.status(500).send(error.message || "과목저장 에러발생")
}
}
export default {
addsubject
}
\ No newline at end of file
import { Todo } from '../db/index.js';
const AddTodo = async(req, res)=>{
}
export default{
AddTodo,
}
\ No newline at end of file
......@@ -14,7 +14,8 @@ const signup = async (req, res) => {
userID: userId,
password: password,
userName: userName,
studNum: userStudNum
studNum: userStudNum,
role:"user"
});
res.status(201).json("success")
} catch (error) {
......
import { Sequelize } from "sequelize"
import dbConfig from "../config/db.config.js"
import UserModel from "../models/user.model.js";
import TodoModel from "../models/todo.model.js";
import SubjectModel from "../models/subject.model.js";
const sequelize = new Sequelize(
String(dbConfig.database),
......@@ -19,8 +21,14 @@ const sequelize = new Sequelize(
);
const User = UserModel(sequelize)
const Todo = TodoModel(sequelize)
const Subject = SubjectModel(sequelize)
Subject.belongsTo(User)
export {
sequelize,
User,
Todo,
Subject
}
\ No newline at end of file
import Sequelize from "sequelize";
const { DataTypes } = Sequelize;
const SubjectModel = (sequelize) => {
const Subject = sequelize.define(
"subject",
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
name: {
type: DataTypes.STRING
},
prof: {
type: DataTypes.STRING
},
room: {
type: DataTypes.STRING
}
},
{
timestamps: true,
freezeTableName: true,
tableName: "subjects",
}
);
return Subject
};
export default SubjectModel;
\ No newline at end of file
import Sequelize from "sequelize";
const { DataTypes } = Sequelize;
const TodoModel = (sequelize) => {
const Todo = sequelize.define(
"todo",
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
title: {
type: DataTypes.STRING
},
date: {
type: DataTypes.STRING
},
done: {
type: DataTypes.BOOLEAN,
defaultValue: false
}
},
{
timestamps: true,
freezeTableName: true,
tableName: "todos",
}
);
return Todo
};
export default TodoModel;
\ No newline at end of file
......@@ -7,6 +7,11 @@ const UserModel = (sequelize) => {
const User = sequelize.define(
"user",
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
userID: {
type: DataTypes.STRING
},
......@@ -18,6 +23,9 @@ const UserModel = (sequelize) => {
},
studNum: {
type: DataTypes.STRING
},
role: {
type: DataTypes.STRING
}
},
{
......
import express from "express";
import userRouter from './user.route.js';
import subjectRouter from './subject.route.js';
const router = express.Router();
router.use('/auth', userRouter)
router.use('/subject', subjectRouter)
export default router;
\ No newline at end of file
import express from 'express';
import subjectCtrl from '../controllers/subject.controller.js';
const router = express.Router();
router
.route("/addsubject")
.post(subjectCtrl.addsubject)
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