Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
WebBack
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
websystem
WebBack
Merge requests
!7
[
#6
] Schedule 컨트롤러, 라우터, 로직 개발
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
[
#6
] Schedule 컨트롤러, 라우터, 로직 개발
feature/#6
into
develop
Overview
0
Commits
12
Pipelines
0
Changes
6
Merged
조대희
requested to merge
feature/#6
into
develop
3 months ago
Overview
0
Commits
12
Pipelines
0
Changes
6
Expand
컨트롤러 생성
라우터 생성
유틸 함수 생성
Schedule 모델 컬럼 추가
Schedule 서비스 버그 수정
0
0
Merge request reports
Compare
develop
version 1
f997bd99
3 months ago
develop (base)
and
latest version
latest version
f997bd99
12 commits,
3 months ago
version 1
f997bd99
24 commits,
3 months ago
6 files
+
271
−
13
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
6
Search (e.g. *.vue) (Ctrl+P)
controllers/scheduleController.js
+
169
−
0
Options
const
ScheduleService
=
require
(
'
../services/scheduleService
'
);
class
scheduleController
{
/**
* 스케줄 생성
* POST /api/schedule
* 해당 사용자 id는 auth 미들웨어에서 설정된 사용자 정보 이용
* req.user = User 모델의 인스턴스
*/
async
createSchedule
(
req
,
res
)
{
try
{
const
userId
=
req
.
user
.
id
;
const
{
title
,
start_time
,
end_time
,
is_fixed
}
=
req
.
body
;
const
schedule
=
await
ScheduleService
.
createSchedule
({
userId
,
title
,
start_time
,
end_time
,
is_fixed
});
return
res
.
status
(
201
).
json
({
success
:
true
,
data
:
{
schedule
}
});
}
catch
(
error
)
{
return
res
.
status
(
400
).
json
({
success
:
false
,
error
:
{
message
:
error
.
message
,
code
:
'
SCHEDULE_CREATE_ERROR
'
}
});
}
}
/**
* 스케줄 수정
* PUT /api/schedule/:id
*/
async
updateSchedule
(
req
,
res
)
{
try
{
const
{
id
}
=
req
.
params
;
const
{
title
,
start_time
,
end_time
}
=
req
.
body
;
const
userId
=
req
.
user
.
id
;
const
schedule
=
await
ScheduleService
.
updateSchedule
(
id
,
userId
,
{
title
,
start_time
,
end_time
});
return
res
.
status
(
200
).
json
({
success
:
true
,
data
:
schedule
});
}
catch
(
error
)
{
if
(
error
.
message
===
'
Schedule not found
'
)
{
return
res
.
status
(
404
).
json
({
success
:
false
,
error
:
{
message
:
error
.
message
,
code
:
'
SCHEDULE_NOT_FOUND
'
}
});
}
return
res
.
status
(
400
).
json
({
success
:
false
,
error
:
{
message
:
error
.
message
,
code
:
'
SCHEDULE_UPDATE_ERROR
'
}
});
}
}
/**
* 스케줄 삭제
* DELETE /api/schedule/:id
*/
async
deleteSchedule
(
req
,
res
)
{
try
{
const
{
id
}
=
req
.
params
;
const
userId
=
req
.
user
.
id
;
await
ScheduleService
.
deleteSchedule
(
id
,
userId
);
return
res
.
status
(
200
).
json
({
success
:
true
,
data
:
{
message
:
'
Schedule successfully deleted
'
}
});
}
catch
(
error
)
{
return
res
.
status
(
404
).
json
({
success
:
false
,
error
:
{
message
:
error
.
message
,
code
:
'
SCHEDULE_NOT_FOUND
'
}
});
}
}
/**
* 해당 사용자 전체 스케줄 조회
* GET /api/schedule/all
*/
async
getAllSchedules
(
req
,
res
)
{
try
{
const
userId
=
req
.
user
.
id
;
const
schedules
=
await
ScheduleService
.
getAllSchedules
(
userId
);
return
res
.
status
(
200
).
json
({
success
:
true
,
data
:
schedules
});
}
catch
(
error
)
{
return
res
.
status
(
500
).
json
({
success
:
false
,
error
:
{
message
:
'
Failed to fetch schedules
'
,
code
:
'
FETCH_ERROR
'
}
});
}
}
/**
* 해당 사용자 특정 스케줄 조회
* GET /api/schedule/:id
*/
async
getScheduleById
(
req
,
res
)
{
try
{
const
{
id
}
=
req
.
params
;
const
userId
=
req
.
user
.
id
;
const
schedule
=
await
ScheduleService
.
getScheduleById
(
id
,
userId
);
return
res
.
status
(
200
).
json
({
success
:
true
,
data
:
schedule
});
}
catch
(
error
)
{
if
(
error
.
message
===
'
Schedule not found
'
)
{
return
res
.
status
(
404
).
json
({
success
:
false
,
error
:
{
message
:
error
.
message
,
code
:
'
SCHEDULE_NOT_FOUND
'
}
});
}
return
res
.
status
(
500
).
json
({
success
:
false
,
error
:
{
message
:
'
Failed to fetch schedule
'
,
code
:
'
FETCH_ERROR
'
}
});
}
}
}
module
.
exports
=
new
scheduleController
();
\ No newline at end of file
Loading