Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
Today KU
Commits
671bf731
Commit
671bf731
authored
Nov 01, 2021
by
Choi Ga Young
Browse files
subject관련 DB, server 연결 작업중
parent
58e8f781
Changes
9
Show whitespace changes
Inline
Side-by-side
client/src/App.js
View file @
671bf731
...
...
@@ -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
}
/
>
...
...
client/src/apis/subject.api.js
0 → 100644
View file @
671bf731
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
client/src/components/Buttons/BtnGroup.js
View file @
671bf731
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
=
"
s
ubmit
"
disabled
=
{
disabled
}
>
등록
<
/button
>
<
button
className
=
{
`btn btn-crimson col-5
${
styles
.
disabledBtn
}
`
}
type
=
"
button
"
onClick
=
{
handleS
ubmit
}
disabled
=
{
disabled
}
>
등록
<
/button
>
<
/div
>
)
}
...
...
client/src/components/Form/SubjectForm.js
View file @
671bf731
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
>
<
/
>
...
...
server/controllers/subject.controller.js
0 → 100644
View file @
671bf731
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
server/db/index.js
View file @
671bf731
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
server/models/subject.model.js
0 → 100644
View file @
671bf731
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
server/routes/index.js
View file @
671bf731
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
server/routes/subject.route.js
0 → 100644
View file @
671bf731
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment