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
8165ef72
Commit
8165ef72
authored
Nov 04, 2021
by
Kim, Subin
Browse files
Merge remote-tracking branch 'origin/kimpen'
parents
fd8277ba
519d8e15
Changes
17
Show whitespace changes
Inline
Side-by-side
client/src/App.js
View file @
8165ef72
...
...
@@ -10,39 +10,39 @@ import StudyPlanPage from "./pages/StudyPlanPage";
import
StudyPlanEditPage
from
"
./pages/StudyPlanEditPage
"
;
import
SubjectEditPage
from
"
./pages/SubjectEditPage
"
;
import
AdminPage
from
"
./pages/Admin/AdminPage
"
;
import
{
AuthProvider
}
from
"
./utils/context
.js
"
;
import
{
AuthProvider
}
from
"
./utils/context
"
;
import
PrivateRoute
from
"
./components/PrivateRoute
"
;
import
ErrorPage
from
"
./pages/ErrorPage
"
;
function
App
()
{
return
(
<
AuthProvider
>
<
Router
basename
=
{
process
.
env
.
PUBLIC_URL
}
>
<
AuthProvider
>
<
div
id
=
"
box
"
className
=
"
container position-relative vh-100 mx-sm-auto
"
>
<
Switch
>
<
Route
exact
path
=
"
/
"
component
=
{
LoginPage
}
/
>
<
Route
path
=
"
/login
"
component
=
{
LoginPage
}
/
>
<
Route
path
=
"
/signup
"
component
=
{
SignupPage
}
/
>
<
Route
path
=
"
/home
"
component
=
{
HomePage
}
/
>
<
Route
path
=
"
/schedule/edit
"
component
=
{
ScheduleEditPage
}
/
>
<
Route
path
=
"
/schedule/
:date
"
component
=
{
SchedulePage
}
/
>
<
Route
path
=
"
/
todo
/:date
"
component
=
{
ToDo
Page
}
/
>
<
Route
path
=
"
/
studyplan/edit/add/:subjectId
"
component
=
{
StudyPlanEdit
Page
}
/
>
<
Route
path
=
"
/studyplan/edit/
:plan
Id
"
component
=
{
StudyPlanEditPage
}
/
>
<
Route
path
=
"
/studyplan/
:subject
Id
"
component
=
{
StudyPlanPage
}
/
>
<
Route
path
=
"
/studyplan
"
component
=
{
StudyPlan
List
Page
}
/
>
<
Route
path
=
"
/s
ubject/edit/:subjectId
"
component
=
{
S
ubjectEdi
tPage
}
/
>
<
Route
path
=
"
/subject/edit
"
component
=
{
SubjectEditPage
}
/
>
<
Route
path
=
"
/
admin/edit/:scheduleId
"
component
=
{
S
chedule
EditPage
}
/
>
<
Route
path
=
"
/admin/edit
"
component
=
{
ScheduleEditPage
}
/
>
<
Route
path
=
"
/admin
"
component
=
{
AdminPage
}
/
>
{
/*
<PrivateRoute path="/admin" component={AdminPage} role="admin" />
*/
}
<
Private
Route
path
=
"
/home
"
component
=
{
HomePage
}
/
>
<
Private
Route
path
=
"
/schedule/edit
/:scheduleId
"
component
=
{
ScheduleEditPage
}
/
>
<
Private
Route
path
=
"
/schedule/
edit
"
component
=
{
Schedule
Edit
Page
}
/
>
<
Private
Route
path
=
"
/
schedule
/:date
"
component
=
{
Schedule
Page
}
/
>
<
Private
Route
path
=
"
/
todo/:date
"
component
=
{
ToDo
Page
}
/
>
<
Private
Route
path
=
"
/studyplan/edit/
add/:subject
Id
"
component
=
{
StudyPlanEditPage
}
/
>
<
Private
Route
path
=
"
/studyplan/
edit/:plan
Id
"
component
=
{
StudyPlan
Edit
Page
}
/
>
<
Private
Route
path
=
"
/studyplan
/:subjectId
"
component
=
{
StudyPlanPage
}
/
>
<
Private
Route
path
=
"
/s
tudyplan
"
component
=
{
S
tudyPlanLis
tPage
}
/
>
<
Private
Route
path
=
"
/subject/edit
/:subjectId
"
component
=
{
SubjectEditPage
}
/
>
<
Private
Route
path
=
"
/
subject/edit
"
component
=
{
S
ubject
EditPage
}
/
>
<
Private
Route
path
=
"
/admin/edit
/:scheduleId
"
component
=
{
ScheduleEditPage
}
role
=
"
admin
"
/>
<
Private
Route
path
=
"
/admin
/edit
"
component
=
{
ScheduleEditPage
}
role
=
"
admin
"
/>
<
PrivateRoute
path
=
"
/admin
"
component
=
{
AdminPage
}
role
=
"
admin
"
/>
<
Route
component
=
{
ErrorPage
}
/
>
<
/Switch
>
<
/div
>
<
/Router
>
<
/AuthProvider
>
<
/Router
>
);
}
...
...
client/src/apis/auth.api.js
View file @
8165ef72
...
...
@@ -2,15 +2,15 @@ import axios from "axios";
import
baseUrl
from
"
../utils/baseUrl.js
"
;
const
getUser
=
async
()
=>
{
const
url
=
`
${
baseUrl
}
/api/auth
/user
`
const
url
=
`
${
baseUrl
}
/api/auth`
const
{
data
}
=
await
axios
.
get
(
url
)
return
data
}
const
signup
=
async
(
user
)
=>
{
const
url
=
`
${
baseUrl
}
/api/auth/signup`
;
const
{
data
}
=
await
axios
.
post
(
url
,
user
);
return
data
const
{
data
,
status
}
=
await
axios
.
post
(
url
,
user
);
return
{
data
,
status
}
}
const
login
=
async
(
user
)
=>
{
...
...
client/src/components/Calendar/Monthly.js
View file @
8165ef72
...
...
@@ -2,6 +2,9 @@ import { useState, useEffect, useRef } from "react";
import
{
useHistory
}
from
"
react-router-dom
"
;
import
CalendarBtn
from
"
../Buttons/CalendarBtn.js
"
;
import
DatePickerModal
from
"
../Modal/DatePickerModal.js
"
;
import
scheduleApi
from
"
../../apis/schedule.api
"
;
import
{
useAuth
}
from
"
../../utils/context.js
"
;
import
catchErrors
from
"
../../utils/catchErrors.js
"
;
import
moment
from
'
moment
'
;
import
FullCalendar
from
'
@fullcalendar/react
'
;
import
dayGridPlugin
from
'
@fullcalendar/daygrid
'
;
...
...
@@ -10,9 +13,13 @@ import bootstrapPlugin from '@fullcalendar/bootstrap';
import
'
@fortawesome/fontawesome-free/css/all.css
'
;
const
Monthly
=
()
=>
{
const
{
user
}
=
useAuth
()
console
.
log
(
"
msds==
"
,
user
)
const
[
initialDate
,
setInitialDate
]
=
useState
(
moment
().
format
(
'
YYYY-MM-DD
'
))
const
[
changeDate
,
setChangeDate
]
=
useState
(
moment
().
format
(
'
YYYY-MM-DD
'
))
const
[
show
,
setShow
]
=
useState
(
false
)
const
[
scheduleList
,
setScheduleList
]
=
useState
([])
const
[
error
,
setError
]
=
useState
(
""
)
const
calendarRef
=
useRef
(
null
)
const
calenIconRef
=
useRef
(
null
)
let
calendar
=
null
...
...
@@ -45,10 +52,27 @@ const Monthly = () => {
useEffect
(()
=>
{
calendar
.
gotoDate
(
changeDate
)
getAll
()
},
[
changeDate
])
useEffect
(()
=>
{
calendar
.
addEventSource
(
scheduleList
)
},
[
scheduleList
])
async
function
getAll
()
{
try
{
setError
(
""
)
console
.
log
(
"
home user
"
,
user
)
const
resList
=
await
scheduleApi
.
getbyMonth
(
changeDate
,
user
.
id
)
setScheduleList
(
resList
)
}
catch
(
error
)
{
catchErrors
(
error
,
setError
)
}
}
return
(
<>
{
console
.
log
(
"
user scheduleList==
"
,
scheduleList
)}
<
div
ref
=
{
calenIconRef
}
className
=
"
position-absolute
"
style
=
{{
top
:
"
9px
"
,
right
:
"
8px
"
}}
>
<
CalendarBtn
date
=
{
moment
(
initialDate
).
format
(
'
DD
'
)}
/
>
<
/div
>
...
...
@@ -98,7 +122,7 @@ const Monthly = () => {
dateClick
=
{({
dateStr
})
=>
history
.
push
(
`/schedule/
${
dateStr
}
`
)}
timeZone
=
"
local
"
themeSystem
=
'
bootstrap
'
//
eventLimit="
true
"
eventLimit
=
"
3
"
height
=
'
80vh
'
/>
<
DatePickerModal
initialDate
=
{
initialDate
}
changeDate
=
{
changeDate
}
setChangeDate
=
{
setChangeDate
}
show
=
{
show
}
setShow
=
{
setShow
}
/
>
...
...
client/src/components/Form/ScheduleForm.js
View file @
8165ef72
...
...
@@ -2,17 +2,19 @@ import { useState, useEffect } from "react";
import
{
Redirect
,
useParams
}
from
"
react-router-dom
"
;
import
BtnGroup
from
"
../Buttons/BtnGroup.js
"
;
import
scheduleApi
from
"
../../apis/schedule.api
"
;
import
{
useAuth
}
from
"
../../utils/context.js
"
;
import
catchErrors
from
"
../../utils/catchErrors.js
"
;
import
styles
from
"
./form.module.scss
"
;
const
ScheduleForm
=
()
=>
{
const
{
user
}
=
useAuth
()
const
[
schedule
,
setSchedule
]
=
useState
({
title
:
""
,
startDate
:
""
,
endDate
:
""
,
startTime
:
""
,
endTime
:
""
,
allDay
:
""
,
allDay
:
user
.
role
===
"
admin
"
?
"
on
"
:
""
,
location
:
""
,
memo
:
""
})
...
...
@@ -47,7 +49,7 @@ const ScheduleForm = () => {
async
function
getOne
(
id
)
{
try
{
setError
(
""
)
const
resSchedule
=
await
scheduleApi
.
getOne
(
id
)
const
resSchedule
=
await
scheduleApi
.
getOne
(
id
,
user
.
id
)
setSchedule
({
...
schedule
,
...
resSchedule
})
}
catch
(
error
)
{
catchErrors
(
error
,
setError
)
...
...
@@ -70,11 +72,11 @@ const ScheduleForm = () => {
try
{
setError
(
""
)
if
(
scheduleId
)
{
await
scheduleApi
.
edit
(
scheduleId
,
schedule
)
await
scheduleApi
.
edit
(
scheduleId
,
schedule
,
user
.
id
)
alert
(
'
해당 일정이 성공적으로 수정되었습니다.
'
)
}
else
{
await
scheduleApi
.
submit
(
schedule
)
await
scheduleApi
.
submit
(
schedule
,
user
.
id
)
alert
(
'
해당 일정이 성공적으로 등록되었습니다.
'
)
}
setSuccess
(
true
)
...
...
@@ -84,9 +86,8 @@ const ScheduleForm = () => {
}
if
(
success
)
{
// if () return <Redirect to="/admin" />
// else return <Redirect to="/home" />
return
<
Redirect
to
=
"
/admin
"
/>
if
(
user
.
role
===
"
admin
"
)
return
<
Redirect
to
=
"
/admin
"
/>
else
return
<
Redirect
to
=
"
/home
"
/>
}
return
(
...
...
@@ -96,27 +97,27 @@ const ScheduleForm = () => {
<
/div
>
<
div
className
=
"
d-flex mb-4
"
>
<
label
className
=
"
col col-form-label align-self-center py-0
"
>
시작
<
/label
>
<
div
className
=
{
schedule
.
allDay
===
"
on
"
?
"
col-7
"
:
"
col-5
"
}
>
<
div
className
=
{
(
user
.
role
===
"
admin
"
||
schedule
.
allDay
===
"
on
"
)
?
"
col-7
"
:
"
col-5
"
}
>
<
input
className
=
{
`form-control shadow-none
${
styles
.
dateInput
}
`
}
type
=
"
date
"
name
=
"
startDate
"
value
=
{
schedule
.
startDate
}
aria
-
label
=
"
startDate
"
onChange
=
{
handleChange
}
/
>
<
/div
>
<
div
className
=
{
"
col-5
"
+
(
schedule
.
allDay
===
"
on
"
?
"
d-none
"
:
"
d-block
"
)}
>
<
div
className
=
{
"
col-5
"
+
(
(
user
.
role
===
"
admin
"
||
schedule
.
allDay
===
"
on
"
)
?
"
d-none
"
:
"
d-block
"
)}
>
<
input
className
=
{
`form-control shadow-none
${
styles
.
dateInput
}
`
}
type
=
"
time
"
name
=
"
startTime
"
aria
-
label
=
"
startTime
"
onChange
=
{
handleChange
}
/
>
<
/div
>
<
/div
>
<
div
className
=
"
d-flex mb-3
"
>
<
div
className
=
{
"
d-flex
"
+
(
user
.
role
===
"
admin
"
?
"
mb-5
"
:
"
mb-3
"
)}
>
<
label
className
=
"
col col-form-label align-self-center py-0
"
>
종료
<
/label
>
<
div
className
=
{
schedule
.
allDay
===
"
on
"
?
"
col-7
"
:
"
col-5
"
}
>
<
div
className
=
{
(
user
.
role
===
"
admin
"
||
schedule
.
allDay
===
"
on
"
)
?
"
col-7
"
:
"
col-5
"
}
>
<
input
className
=
{
`form-control shadow-none
${
styles
.
dateInput
}
`
}
type
=
"
date
"
name
=
"
endDate
"
value
=
{
schedule
.
endDate
}
aria
-
label
=
"
endDate
"
onChange
=
{
handleChange
}
/
>
<
/div
>
<
div
className
=
{
"
col-5
"
+
(
schedule
.
allDay
===
"
on
"
?
"
d-none
"
:
"
d-block
"
)}
>
<
div
className
=
{
"
col-5
"
+
(
(
user
.
role
===
"
admin
"
||
schedule
.
allDay
===
"
on
"
)
?
"
d-none
"
:
"
d-block
"
)}
>
<
input
className
=
{
`form-control shadow-none
${
styles
.
dateInput
}
`
}
type
=
"
time
"
name
=
"
endTime
"
value
=
{
schedule
.
endTime
}
aria
-
label
=
"
endTime
"
onChange
=
{
handleChange
}
/
>
<
/div
>
<
/div
>
<
div
className
=
"
d-flex justify-content-end form-check mb-4
"
>
<
input
className
=
{
`form-check-input shadow-none
${
styles
.
checkBox
}
`
}
type
=
"
checkbox
"
id
=
"
allDay
"
name
=
"
allDay
"
onChange
=
{
handleChange
}
/
>
<
div
className
=
{
"
d-flex justify-content-end form-check mb-4
"
+
(
user
.
role
===
"
admin
"
?
"
d-none
"
:
"
d-block
"
)}
>
<
input
className
=
{
`form-check-input shadow-none
${
styles
.
checkBox
}
`
}
type
=
"
checkbox
"
id
=
"
allDay
"
name
=
"
allDay
"
onChange
=
{
handleChange
}
checked
=
{
schedule
.
allDay
===
"
on
"
?
true
:
false
}
/
>
<
label
className
=
"
form-check-label ms-2
"
htmlFor
=
"
allDay
"
>
하루
종일
<
/label
>
<
/div
>
<
div
className
=
"
d-flex justify-content-between align-items-center mb-4
"
>
<
/div>
5
2
<
div
className
=
{
"
d-flex justify-content-between align-items-center mb-4
"
+
(
user
.
role
===
"
admin
"
?
"
d-none
"
:
"
d-block
"
)}
>
<
i
className
=
"
col bi bi-geo-alt fs-3
"
><
/i
>
<
div
className
=
"
col-10
"
>
<
input
className
=
{
`form-control shadow-none rounded-0 px-1
${
styles
.
textInput
}
`
}
type
=
"
text
"
name
=
"
location
"
placeholder
=
"
장소
"
aria
-
label
=
"
location
"
onChange
=
{
handleChange
}
/
>
...
...
client/src/components/Menu/Menu.js
View file @
8165ef72
...
...
@@ -4,7 +4,7 @@ import moment from "moment";
import
styles
from
"
./menu.module.scss
"
;
const
Menu
=
()
=>
{
const
{
logout
}
=
useAuth
();
const
{
user
,
logout
}
=
useAuth
();
return
(
<>
...
...
@@ -15,7 +15,7 @@ const Menu = () => {
<
div
className
=
"
d-flex flex-column
"
style
=
{{
transition
:
"
.15s ease
"
,
height
:
"
inherit
"
}}
>
<
button
type
=
"
button
"
className
=
{
`btn-close btn-close-white btn-lg position-absolute
${
styles
.
close
}
`
}
data
-
bs
-
toggle
=
"
collapse
"
data
-
bs
-
target
=
"
#menuContent
"
aria
-
controls
=
"
menuContent
"
aria
-
expanded
=
"
true
"
aria
-
label
=
"
menu
"
><
/button
>
<
div
className
=
"
d-flex flex-column align-items-center text-white py-5
"
style
=
{{
backgroundColor
:
"
crimson
"
}}
>
<
h1
className
=
"
my-3
"
>
김수빈
님
<
/h1
>
<
h1
className
=
"
my-3
"
>
{
user
.
name
}
님
<
/h1
>
<
h2
className
=
"
my-2
"
>
오늘의
목표
95
%
달성
!<
/h2
>
<
/div
>
<
div
className
=
"
d-flex flex-column justify-content-between flex-grow-1 py-4 ps-3 text-dark
"
>
...
...
client/src/components/PrivateRoute.js
View file @
8165ef72
...
...
@@ -4,29 +4,26 @@ import ErrorPage from "../pages/ErrorPage";
const
PrivateRoute
=
({
component
:
Component
,
...
rest
})
=>
{
const
{
user
}
=
useAuth
();
// return (
// <Route
// {...rest}
// render={(props) => {
// if (user) {
// if (rest.role) {
// if (rest.role === user.role) {
// return <Component {...props} />;
// } else {
// return <ErrorPage />
// }
// } else {
// return <Component {...props} />
// }
// } else {
// return <Redirect to="/login" />;
// }
// }}
// />
// );
return
(
<
Route
{...
rest
}
render
=
{(
props
)
=>
<
Component
{...
props
}
/>} /
>
)
<
Route
{...
rest
}
render
=
{(
props
)
=>
{
if
(
user
)
{
if
(
rest
.
role
)
{
if
(
rest
.
role
===
user
.
role
)
{
return
<
Component
{...
props
}
/>
;
}
else
{
return
<
ErrorPage
/>
}
}
else
{
return
<
Component
{...
props
}
/
>
}
}
else
{
return
<
Redirect
to
=
"
/login
"
/>
;
}
}}
/
>
);
};
export
default
PrivateRoute
;
\ No newline at end of file
client/src/components/Schedule/ScheduleItem.js
View file @
8165ef72
import
{
useState
}
from
"
react
"
;
import
{
Link
}
from
"
react-router-dom
"
;
import
catchErrors
from
"
../../utils/catchErrors.js
"
;
import
styles
from
"
./schedule.module.scss
"
;
const
ScheduleItem
=
()
=>
{
const
[
error
,
setError
]
=
useState
(
""
)
async
function
delSchedule
()
{
try
{
setError
(
""
)
alert
(
"
해당 일정을 성공적으로 삭제하였습니다.
"
)
window
.
location
.
reload
()
}
catch
(
error
)
{
catchErrors
(
error
,
setError
)
}
}
const
ScheduleItem
=
({
schedule
,
handleClick
})
=>
{
return
(
<
div
className
=
"
accordion-item border-bottom-0
"
>
<
button
className
=
{
`d-flex flex-column align-items-start accordion-button collapsed bg-white shadow-none px-0
${
styles
.
activeBtn
}
`
}
type
=
"
button
"
data
-
bs
-
toggle
=
"
collapse
"
data
-
bs
-
target
=
"
#flush-collapseOne
"
aria
-
expanded
=
"
false
"
aria
-
controls
=
"
flush-collapseOne
"
>
<
h5
className
=
{
`accordion-header
${
styles
.
title
}
`
}
id
=
"
flush-headingOne
"
>
Accordion0
Item
#
1
sadsadsadasdsadsadasa
sadsadsadasdsadsada
<
/h5
>
<
button
className
=
{
`d-flex flex-column align-items-start accordion-button collapsed bg-white shadow-none px-0
${
styles
.
activeBtn
}
`
}
type
=
"
button
"
data
-
bs
-
toggle
=
"
collapse
"
data
-
bs
-
target
=
{
schedule
.
id
}
aria
-
expanded
=
"
false
"
aria
-
controls
=
{
schedule
.
id
}
>
<
h5
className
=
{
`accordion-header
${
styles
.
title
}
`
}
id
=
{
"
heading
"
+
schedule
.
id
}
>
{
schedule
.
title
}
<
/h5
>
<
p
className
=
{
`text-secondary mb-0
${
styles
.
time
}
`
}
>
sadsadsdsadsadsaf
<
/p
>
<
p
className
=
{
`mb-0
${
styles
.
period
}
`
}
>
2021.01
.
151
~
2021.09
.
35
<
/p
>
<
/button
>
<
div
id
=
"
flush-collapseOne
"
className
=
"
accordion-collapse collapse
"
aria
-
labelledby
=
"
flush-headingOne
"
data
-
bs
-
parent
=
"
#scheduleList
"
>
<
div
id
=
{
schedule
.
id
}
className
=
"
accordion-collapse collapse
"
aria
-
labelledby
=
{
"
heading
"
+
schedule
.
id
}
data
-
bs
-
parent
=
"
#scheduleList
"
>
<
div
className
=
{
`accordion-body px-0 pt-2 pb-0 mb-3
${
styles
.
textBox
}
`
}
>
<
div
className
=
"
d-flex align-items-start
"
>
{
schedule
.
location
?
<
div
className
=
"
d-flex align-items-start
"
>
<
i
className
=
"
col bi bi-geo-alt fs-5
"
><
/i
>
<
div
className
=
"
col-11
"
>
sadsadsadsa
<
/div
>
<
/div
>
dlkasjflsajflasjflsakfjlsajflalsafjsask
<
br
/>
fjlakdjflajflaksj
lksajdlksajs
dslkafjlsakflksjflasjflksjslakjflsakjflsajflsakjlasjflksajlfsja
<
div
className
=
"
col-11
"
>
{
schedule
.
location
}
<
/div
>
<
/div> : null
}
{
schedule
.
memo
}
<
div
className
=
"
d-flex justify-content-end mt-3
"
>
<
Link
className
=
"
btn btn-light btn-sm border-dark
"
to
=
"
/schedule/edit
"
>
수정
<
/Link
>
<
button
type
=
"
button
"
className
=
"
btn btn-crimson btn-sm ms-2
"
onClick
=
{
delSchedule
}
>
삭제
<
/button
>
<
Link
className
=
"
btn btn-light btn-sm border-dark
"
to
=
{
`
/schedule/edit
/
${
schedule
.
id
}
`
}
>
수정
<
/Link
>
<
button
type
=
"
button
"
className
=
"
btn btn-crimson btn-sm ms-2
"
onClick
=
{
handleClick
}
>
삭제
<
/button
>
<
/div
>
<
/div
>
<
/div
>
...
...
client/src/components/Schedule/ScheduleList.js
View file @
8165ef72
import
{
useState
,
useEffect
}
from
"
react
"
;
import
{
useParams
}
from
"
react-router-dom
"
;
import
Item
from
"
./ScheduleItem.js
"
;
import
scheduleApi
from
"
../../apis/schedule.api
"
;
import
{
useAuth
}
from
"
../../utils/context.js
"
;
import
catchErrors
from
"
../../utils/catchErrors.js
"
;
import
styles
from
"
./schedule.module.scss
"
;
const
ScheduleList
=
()
=>
{
const
[
scheduleList
,
setScheduleList
]
=
useState
([])
const
[
error
,
setError
]
=
useState
(
""
)
const
{
date
}
=
useParams
()
const
{
user
}
=
useAuth
()
useEffect
(()
=>
{
getAll
(
date
)
return
()
=>
{
getAll
(
date
)
}
},
[])
useEffect
(()
=>
{
getAll
(
date
)
return
()
=>
{
getAll
(
date
)
}
},
[
date
])
async
function
getAll
(
date
)
{
try
{
setError
(
""
)
const
resList
=
await
scheduleApi
.
getbyDate
(
date
,
user
.
id
)
setScheduleList
(
resList
)
}
catch
(
error
)
{
catchErrors
(
error
,
setError
)
}
}
async
function
delSchedule
(
id
)
{
try
{
setError
(
""
)
await
scheduleApi
.
remove
(
id
,
user
.
id
)
alert
(
"
해당 일정을 성공적으로 삭제하였습니다.
"
)
getAll
(
date
)
}
catch
(
error
)
{
catchErrors
(
error
,
setError
)
}
}
return
(
<
div
className
=
{
styles
.
list
}
>
<
div
className
=
"
accordion accordion-flush
"
id
=
"
scheduleList
"
>
<
Item
/>
<
Item
/>
<
Item
/>
{
scheduleList
.
length
!==
0
?
scheduleList
.
map
((
schedule
,
idx
)
=>
<
Item
key
=
{
idx
}
schedule
=
{
schedule
}
handleClick
=
{
delSchedule
}
/>
)
:
<
div
className
=
"
text-center text-secondary
"
>
오늘
등록된
일정이
없습니다
.
<
/div>
}
<
/div
>
<
/div
>
)
...
...
client/src/pages/Admin/AdminPage.js
View file @
8165ef72
import
Monthly
from
"
../../components/Calendar/AdminMonthly.js
"
;
import
Footer
from
"
../../components/Footer.js
"
;
import
{
useAuth
}
from
"
../../utils/context.js
"
;
import
styles
from
"
./admin.module.scss
"
;
const
AdminPage
=
()
=>
{
const
{
logout
}
=
useAuth
()
return
(
<>
<
p
className
=
{
`position-absolute user-select-none
${
styles
.
status
}
`
}
>
관리자님
,
환영합니다
.
|
<
span
className
=
{
styles
.
cursor
}
>
로그아웃
<
/span></
p
>
<
p
className
=
{
`position-absolute user-select-none
${
styles
.
status
}
`
}
>
관리자님
,
환영합니다
.
|
<
span
className
=
{
styles
.
cursor
}
onClick
=
{
logout
}
>
로그아웃
<
/span></
p
>
<
div
className
=
{
styles
.
body
}
>
<
Monthly
/>
<
/div
>
...
...
client/src/pages/LoginPage.js
View file @
8165ef72
import
{
Link
}
from
'
react-router-dom
'
;
import
LoginForm
from
'
../components/Form/LoginForm
'
;
import
{
useAuth
}
from
"
../utils/context
"
;
function
LoginPage
()
{
const
{
user
}
=
useAuth
()
console
.
log
(
"
LoginPage
"
,
user
)
return
(
<>
<
div
className
=
"
py-5
"
>
...
...
@@ -8,6 +12,7 @@ function LoginPage() {
<
p
className
=
"
ms-4
"
>-
일정관리앱
<
/p
>
<
/div
>
<
LoginForm
/>
<
Link
to
=
"
/home
"
>
asda
<
/Link
>
<
/
>
);
}
...
...
client/src/pages/SignupPage.js
View file @
8165ef72
import
BackBtn
from
"
../components/Buttons/BackBtn.js
"
;
import
SignupForm
from
'
../components/Form/SignupForm
'
;
import
{
useAuth
}
from
"
../utils/context
"
;
function
SingupPage
()
{
const
{
user
}
=
useAuth
()
console
.
log
(
"
Signup user
"
,
user
)
return
(
<>
<
BackBtn
/>
...
...
client/src/utils/auth.js
0 → 100644
View file @
8165ef72
export
function
getLoggedIn
()
{
const
loggedData
=
localStorage
.
getItem
(
"
login
"
);
let
loggedIn
=
null
;
if
(
loggedData
)
{
// loggedIn = JSON.parse(loggedData);
loggedIn
=
loggedData
}
return
loggedIn
;
}
\ No newline at end of file
client/src/utils/context.js
View file @
8165ef72
import
{
createContext
,
useCallback
,
useContext
,
useEffect
,
useState
}
from
'
react
'
;
import
{
Redirect
}
from
'
react-router-dom
'
;
import
{
useHistory
,
useLocation
}
from
"
react-router-dom
"
;
import
authApi
from
"
../apis/auth.api
"
;
import
catchErrors
from
'
./catchErrors
'
;
...
...
@@ -13,13 +13,21 @@ const AuthContext = createContext({
});
const
AuthProvider
=
({
children
})
=>
{
const
[
error
,
setError
]
=
useState
(
""
);
const
[
user
,
setUser
]
=
useState
({
id
:
""
,
role
:
"
user
"
,
name
:
""
});
const
[
error
,
setError
]
=
useState
(
""
);
const
history
=
useHistory
()
const
{
pathname
}
=
useLocation
()
const
getUser
=
async
()
=>
{
const
{
id
,
role
,
userName
}
=
await
authApi
.
getUser
();
const
user
=
{
id
:
id
,
role
:
role
,
name
:
userName
};
setUser
(
user
);
try
{
const
resUser
=
await
authApi
.
getUser
();
setUser
({
...
user
,
...
resUser
});
// console.log("context use")
// if (pathname === "/admin" && user.role !== "admin") history.push('/home')
}
catch
(
error
)
{
catchErrorAuth
(
error
,
setError
);
}
}
useEffect
(()
=>
{
getUser
();
},
[]);
...
...
@@ -84,4 +92,3 @@ const AuthProvider = ({ children }) => {
const
useAuth
=
()
=>
useContext
(
AuthContext
);
export
{
AuthProvider
,
useAuth
};
\ No newline at end of file
server/controllers/schedule.controller.js
View file @
8165ef72
...
...
@@ -6,14 +6,31 @@ const { Op } = sequelize
const
findbyId
=
async
(
req
,
res
,
next
)
=>
{
try
{
const
id
=
req
.
scheduleId
if
(
id
)
{
const
findSchedule
=
await
KU
.
findOne
({
where
:
{
id
:
id
}
})
const
userId
=
req
.
userId
let
findSchedule
=
null
let
startDate
=
null
let
endDate
=
null
if
(
id
&&
userId
)
{
if
(
userId
===
"
ku
"
)
{
findSchedule
=
await
KU
.
findOne
({
where
:
{
id
:
id
}
})
if
(
!
findSchedule
)
throw
new
Error
(
"
해당 일정을 찾지 못했습니다.
"
)
else
{
const
{
title
,
start
,
end
,
memo
}
=
findSchedule
const
startDate
=
dateToString
(
start
,
"
full
"
)
const
endDate
=
dateToString
(
end
,
"
full
"
)
req
.
schedule
=
{
title
,
startDate
:
startDate
,
endDate
:
endDate
,
memo
}
const
{
id
,
title
,
start
,
end
,
memo
}
=
findSchedule
startDate
=
dateToString
(
start
,
"
full
"
)
endDate
=
dateToString
(
end
,
"
full
"
)
req
.
schedule
=
{
id
,
title
,
startDate
:
startDate
,
endDate
:
endDate
,
memo
}
}
}
else
{
findSchedule
=
await
Schedule
.
findOne
({
where
:
{
[
Op
.
and
]:
[{
id
:
id
},
{
userId
:
userId
}]
}
})
if
(
!
findSchedule
)
throw
new
Error
(
"
해당 일정을 찾지 못했습니다.
"
)
else
{
const
{
id
,
title
,
start
,
end
,
location
,
memo
}
=
findSchedule
startDate
=
dateToString
(
start
,
"
full
"
)
endDate
=
dateToString
(
end
,
"
full
"
)
const
startTime
=
dateToString
(
start
,
"
time
"
)
const
endTime
=
dateToString
(
end
,
"
time
"
)
req
.
schedule
=
{
id
,
title
,
startDate
,
endDate
,
startTime
,
endTime
,
location
,
memo
}
}
}
next
()
}
else
next
()
...
...
@@ -26,9 +43,10 @@ const findbyDate = async (req, res, next) => {
try
{
if
(
req
.
date
||
req
.
month
)
{
let
date
=
""
let
findList
=
[]
let
findList
=
null
if
(
req
.
date
)
{
date
=
new
Date
(
req
.
date
)
if
(
req
.
userId
===
"
ku
"
)
{
findList
=
await
KU
.
findAll
({
where
:
{
[
Op
.
and
]:
[
...
...
@@ -48,11 +66,28 @@ const findbyDate = async (req, res, next) => {
schedule
.
dataValues
.
start
=
dateToString
(
schedule
.
start
,
"
twoYear
"
)
schedule
.
dataValues
.
end
=
dateToString
(
schedule
.
end
,
"
twoYear
"
)
})
}
else
{
findList
=
await
Schedule
.
findAll
({
where
:
{
[
Op
.
and
]:
[
{
start
:
{
[
Op
.
lte
]:
date
}
},
{
end
:
{
[
Op
.
gte
]:
date
}
}
]
},
order
:
[[
'
updatedAt
'
,
'
DESC
'
]]
})
}
}
else
{
date
=
new
Date
(
req
.
month
)
const
year
=
dateToString
(
date
,
"
year
"
)
const
month
=
dateToString
(
date
,
"
month
"
)
findList
=
await
KU
.
findAll
({
const
find
KU
List
=
await
KU
.
findAll
({
where
:
{
[
Op
.
or
]:
[
{
...
...
@@ -70,8 +105,9 @@ const findbyDate = async (req, res, next) => {
},
attributes
:
[
'
id
'
,
'
title
'
,
'
start
'
,
'
end
'
]
,
order
:
[[
'
start
'
]]
})
if
(
req
.
userId
===
"
ku
"
)
{
// console.log("list==",findList)
findList
.
forEach
(
schedule
=>
{
find
KU
List
.
forEach
(
schedule
=>
{
// const find = findList.find(el => {
// if (el.dataValues.start <= schedule.dataValues.start) {
// if (el.dataValues.end >= schedule.dataValues.start) return el
...
...
@@ -82,6 +118,29 @@ const findbyDate = async (req, res, next) => {
schedule
.
dataValues
.
allDay
=
true
schedule
.
dataValues
.
className
=
'
text
'
})
findList
=
findKUList
}
else
{
const
findIndividualList
=
await
Schedule
.
findAll
({
where
:
{
[
Op
.
or
]:
[
{
[
Op
.
and
]:
[
sequelize
.
where
(
sequelize
.
fn
(
'
date_part
'
,
'
year
'
,
sequelize
.
col
(
'
start
'
)),
year
),
sequelize
.
where
(
sequelize
.
fn
(
'
date_part
'
,
'
month
'
,
sequelize
.
col
(
'
start
'
)),
month
)
]
},
{
[
Op
.
and
]:
[
sequelize
.
where
(
sequelize
.
fn
(
'
date_part
'
,
'
year
'
,
sequelize
.
col
(
'
end
'
)),
year
),
sequelize
.
where
(
sequelize
.
fn
(
'
date_part
'
,
'
month
'
,
sequelize
.
col
(
'
end
'
)),
month
)
]
}
]
},
attributes
:
[
'
id
'
,
'
title
'
,
'
start
'
,
'
end
'
]
,
order
:
[[
'
start
'
]]
})
console
.
log
(
"
개인 일정 찾기
"
,
findIndividualList
)
findList
=
{
KU
:
findKUList
,
individual
:
findIndividualList
}
}
}
req
.
scheduleList
=
findList
next
()
...
...
@@ -94,15 +153,24 @@ const findbyDate = async (req, res, next) => {
const
create
=
async
(
req
,
res
)
=>
{
try
{
let
newSchedule
=
null
let
start
=
null
let
end
=
null
const
userId
=
req
.
userId
if
(
userId
===
"
ku
"
)
{
const
{
title
,
startDate
,
endDate
,
memo
}
=
req
.
body
const
start
=
new
Date
(
startDate
)
const
end
=
new
Date
(
endDate
)
start
=
new
Date
(
startDate
)
end
=
new
Date
(
endDate
)
newSchedule
=
await
KU
.
create
({
title
:
title
,
start
:
start
,
end
:
end
,
memo
:
memo
})
}
else
{
const
{
title
,
startDate
,
endDate
,
startTime
,
endTime
,
allDay
,
location
,
memo
}
=
req
.
body
newSchedule
=
await
Schedule
.
create
({
title
:
title
,
location
:
location
,
memo
:
memo
})
if
(
allDay
===
"
on
"
)
{
start
=
new
Date
(
startDate
)
end
=
new
Date
(
endDate
)
}
else
{
start
=
new
Date
(
startDate
+
"
"
+
startTime
)
end
=
new
Date
(
endDate
+
"
"
+
endTime
)
}
newSchedule
=
await
Schedule
.
create
({
title
:
title
,
start
:
start
,
end
:
end
,
location
:
location
,
memo
:
memo
,
userId
:
userId
})
}
return
res
.
json
(
newSchedule
)
}
catch
(
error
)
{
...
...
@@ -113,14 +181,26 @@ const create = async (req, res) => {
const
edit
=
async
(
req
,
res
)
=>
{
try
{
let
updated
=
null
let
start
=
null
let
end
=
null
const
userId
=
req
.
userId
const
{
scheduleId
}
=
req
.
query
if
(
userId
===
"
ku
"
)
{
const
{
title
,
startDate
,
endDate
,
memo
}
=
req
.
body
updated
=
await
KU
.
update
({
title
:
title
,
start
:
startDate
,
end
:
endDate
,
memo
:
memo
},
{
where
:
{
id
:
scheduleId
}
})
start
=
new
Date
(
startDate
)
end
=
new
Date
(
endDate
)
updated
=
await
KU
.
update
({
title
:
title
,
start
:
start
,
end
:
end
,
memo
:
memo
},
{
where
:
{
id
:
scheduleId
}
})
}
else
{
const
{
title
,
startDate
,
endDate
,
startTime
,
endTime
,
allDay
,
location
,
memo
}
=
req
.
body
updated
=
await
Schedule
.
update
({
title
:
title
,
memo
:
memo
},
{
where
:
{
id
:
scheduleId
}
})
if
(
allDay
===
"
on
"
)
{
start
=
new
Date
(
startDate
)
end
=
new
Date
(
endDate
)
}
else
{
start
=
new
Date
(
startDate
+
"
"
+
startTime
)
end
=
new
Date
(
endDate
+
"
"
+
endTime
)
}
updated
=
await
Schedule
.
update
({
title
:
title
,
start
:
start
,
end
:
end
,
location
:
location
,
memo
:
memo
},
{
where
:
{
[
Op
.
and
]:
[{
id
:
scheduleId
},
{
userId
:
userId
}]
}
})
}
if
(
!
updated
)
throw
new
Error
(
"
해당 일정의 일부 정보를 수정하는데 실패하였습니다.
"
)
else
return
res
.
send
(
200
)
...
...
@@ -135,7 +215,7 @@ const remove = async (req, res) => {
const
userId
=
req
.
userId
const
{
scheduleId
}
=
req
.
query
if
(
userId
===
"
ku
"
)
deleted
=
await
KU
.
destroy
({
where
:
{
id
:
scheduleId
}
})
else
deleted
=
await
Schedule
.
destroy
({
where
:
{
id
:
scheduleId
}
})
else
deleted
=
await
Schedule
.
destroy
({
where
:
{
[
Op
.
and
]:
[{
id
:
scheduleId
},
{
userId
:
userId
}]
}
})
if
(
!
deleted
)
throw
new
Error
(
"
해당 일정을 삭제하는데 실패하였습니다.
"
)
else
return
res
.
send
(
200
)
}
catch
(
error
)
{
...
...
@@ -180,11 +260,23 @@ function dateToString(dateObj, method) {
const
year_disit
=
String
(
year
).
substring
(
2
,
4
)
const
month
=
dateObj
.
getMonth
()
+
1
const
date
=
dateObj
.
getDate
()
const
hour
=
dateObj
.
getHours
()
const
minute
=
dateObj
.
getMinutes
()
if
(
method
===
"
full
"
)
return
[
year
,
(
month
>
9
?
""
:
"
0
"
)
+
month
,
(
date
>
9
?
""
:
"
0
"
)
+
date
].
join
(
"
-
"
)
else
if
(
method
===
"
twoYear
"
)
return
[
year_disit
,
(
month
>
9
?
""
:
"
0
"
)
+
month
,
(
date
>
9
?
""
:
"
0
"
)
+
date
].
join
(
"
-
"
)
else
if
(
method
===
"
year
"
)
return
year
else
return
month
switch
(
method
)
{
case
"
full
"
:
return
[
year
,
(
month
>
9
?
""
:
"
0
"
)
+
month
,
(
date
>
9
?
""
:
"
0
"
)
+
date
].
join
(
"
-
"
)
case
"
twoYear
"
:
return
[
year_disit
,
(
month
>
9
?
""
:
"
0
"
)
+
month
,
(
date
>
9
?
""
:
"
0
"
)
+
date
].
join
(
"
-
"
)
// case "dateTime":
// return [year, (month > 9 ? "" : "0") + month, (date > 9 ? "" : "0") + date, ].join("-")
case
"
time
"
:
return
[(
hour
>
9
?
""
:
"
0
"
)
+
hour
,
(
minute
>
9
?
""
:
"
0
"
)
+
minute
].
join
(
"
:
"
)
case
"
year
"
:
return
year
case
"
month
"
:
return
month
}
}
export
default
{
...
...
server/controllers/user.controller.js
View file @
8165ef72
...
...
@@ -4,20 +4,19 @@ import config from "../config/app.config.js";
const
getUser
=
async
(
req
,
res
)
=>
{
try
{
if
(
req
.
cookies
.
todayku
)
{
const
token
=
req
.
cookies
.
todayku
;
if
(
req
.
cookies
[
config
.
cookieName
]
)
{
const
token
=
req
.
cookies
[
config
.
cookieName
]
;
const
{
id
,
role
,
name
}
=
jwt
.
verify
(
token
,
config
.
jwtSecret
);
res
.
json
({
id
,
role
,
name
});
return
res
.
json
({
id
,
role
,
name
});
}
else
{
res
.
json
({
id
:
""
,
role
:
"
user
"
,
name
:
""
});
// res.json({ id: "", role: "user", name: "" });
throw
new
Error
(
"
유효기간이 만료되었습니다. 다시 로그인해주세요.
"
)
}
}
catch
(
error
)
{
console
.
error
(
error
);
return
res
.
status
(
500
).
send
(
"
유저를 가져오지 못했습니다.
"
);
return
res
.
status
(
500
).
send
(
error
.
message
||
"
사용자 정보 가져오는 중 에러 발생
"
);
}
}
const
signup
=
async
(
req
,
res
)
=>
{
console
.
log
(
'
server/signup req.body
'
,
req
.
body
)
const
{
userId
,
password
,
userName
,
userStudNum
}
=
req
.
body
;
...
...
@@ -33,7 +32,7 @@ const signup = async (req, res) => {
studNum
:
userStudNum
,
role
:
"
user
"
});
res
.
status
(
201
).
json
(
"
success
"
)
return
res
.
status
(
201
).
json
(
"
success
"
)
}
catch
(
error
)
{
console
.
log
(
error
)
return
res
.
status
(
500
).
send
(
error
.
message
||
"
회원가입 에러발생
"
)
...
...
@@ -54,7 +53,7 @@ const login = async (req, res) => {
const
signData
=
{
id
:
user
.
id
,
role
:
"
user
"
,
role
:
user
.
role
,
name
:
user
.
userName
,
};
...
...
@@ -83,7 +82,7 @@ const login = async (req, res) => {
const
logout
=
async
(
req
,
res
)
=>
{
try
{
res
.
clearCookie
(
config
.
cookieName
);
res
.
json
({
return
res
.
json
({
id
:
""
,
role
:
"
user
"
,
name
:
""
...
...
server/models/schedule.model.js
View file @
8165ef72
...
...
@@ -22,6 +22,9 @@ const ScheduleModel = (sequelize) => {
end
:
{
type
:
DataTypes
.
DATE
},
allDay
:
{
type
:
DataTypes
.
BOOLEAN
,
},
location
:
{
type
:
DataTypes
.
STRING
,
defaultValue
:
""
...
...
server/routes/user.route.js
View file @
8165ef72
...
...
@@ -13,5 +13,10 @@ router
router
.
route
(
"
/logout
"
)
.
get
(
userCtrl
.
logout
)
.
get
(
userCtrl
.
logout
)
router
.
route
(
"
/
"
)
.
get
(
userCtrl
.
getUser
)
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