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
Commits
04fd4e44
Commit
04fd4e44
authored
4 months ago
by
조대희
Browse files
Options
Downloads
Patches
Plain Diff
refactor: 스케줄 컨트롤러에 성능 측정 모니터 추가 (
#23
)
parent
205af153
Branches
Branches containing commit
No related tags found
2 merge requests
!42
[#25] 배포코드 master브랜치로 이동
,
!36
[#23] 스케줄 로직 리팩토링
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
controllers/scheduleController.js
+64
-51
64 additions, 51 deletions
controllers/scheduleController.js
with
64 additions
and
51 deletions
controllers/scheduleController.js
+
64
−
51
View file @
04fd4e44
// controllers/scheduleController.js
const
ScheduleService
=
require
(
'
../services/scheduleService
'
);
const
ScheduleRequestDTO
=
require
(
'
../dtos/ScheduleRequestDTO
'
);
const
performanceMonitor
=
require
(
'
../utils/performanceMonitor
'
);
class
scheduleController
{
/**
...
...
@@ -21,20 +22,21 @@ class scheduleController {
*/
async
createSchedule
(
req
,
res
)
{
try
{
const
userId
=
req
.
user
.
id
;
const
scheduleRequestDTO
=
new
ScheduleRequestDTO
(
req
.
body
);
const
validatedData
=
scheduleRequestDTO
.
validate
(
'
create
'
);
return
await
performanceMonitor
.
measureAsync
(
'
createSchedule
'
,
async
()
=>
{
const
userId
=
49
;
// const userId = req.user.id;
const
scheduleRequestDTO
=
new
ScheduleRequestDTO
(
req
.
body
);
const
validatedData
=
scheduleRequestDTO
.
validate
(
'
create
'
);
const
schedule
=
await
ScheduleService
.
createSchedules
({
userId
,
...
validatedData
});
const
schedule
=
await
ScheduleService
.
createSchedules
({
userId
,
...
validatedData
});
return
res
.
status
(
201
).
json
({
success
:
true
,
data
:
{
schedule
}
return
res
.
status
(
201
).
json
({
success
:
true
,
data
:
{
schedule
}
});
});
}
catch
(
error
)
{
return
res
.
status
(
400
).
json
({
...
...
@@ -61,17 +63,18 @@ class scheduleController {
*/
async
updateSchedules
(
req
,
res
)
{
try
{
const
userId
=
req
.
user
.
id
;
const
scheduleRequestDTO
=
new
ScheduleRequestDTO
(
req
.
body
);
const
validatedData
=
scheduleRequestDTO
.
validate
(
'
bulk_update
'
);
const
updatedSchedule
=
await
ScheduleService
.
updateSchedules
(
userId
,
validatedData
);
return
res
.
status
(
200
).
json
({
success
:
true
,
data
:
{
schedule
:
updatedSchedule
}
return
await
performanceMonitor
.
measureAsync
(
'
updateSchedules
'
,
async
()
=>
{
// const userId = req.user.id;
const
userId
=
49
;
const
scheduleRequestDTO
=
new
ScheduleRequestDTO
(
req
.
body
);
const
validatedData
=
scheduleRequestDTO
.
validate
(
'
bulk_update
'
);
const
updatedSchedule
=
await
ScheduleService
.
updateSchedules
(
userId
,
validatedData
);
return
res
.
status
(
200
).
json
({
success
:
true
,
data
:
{
schedule
:
updatedSchedule
}
});
});
}
catch
(
error
)
{
if
(
error
.
message
===
'
Schedule not found
'
)
{
...
...
@@ -104,17 +107,22 @@ class scheduleController {
*/
async
deleteSchedules
(
req
,
res
)
{
try
{
const
userId
=
req
.
user
.
id
;
const
scheduleRequestDTO
=
new
ScheduleRequestDTO
(
req
.
body
);
const
validatedData
=
scheduleRequestDTO
.
validate
(
'
bulk_delete
'
);
const
result
=
await
ScheduleService
.
deleteSchedules
(
userId
,
validatedData
.
title
);
return
res
.
status
(
200
).
json
({
success
:
true
,
data
:
{
message
:
'
Schedule successfully deleted
'
,
deletedCount
:
result
.
deletedCount
}
return
await
performanceMonitor
.
measureAsync
(
'
deleteSchedules
'
,
async
()
=>
{
// const userId = req.user.id;
const
userId
=
49
;
const
scheduleRequestDTO
=
new
ScheduleRequestDTO
(
req
.
body
);
const
validatedData
=
scheduleRequestDTO
.
validate
(
'
bulk_delete
'
);
const
result
=
await
ScheduleService
.
deleteSchedules
(
userId
,
validatedData
.
title
);
return
res
.
status
(
200
).
json
({
success
:
true
,
data
:
{
message
:
'
Schedule successfully deleted
'
,
deletedCount
:
result
.
deletedCount
}
});
});
}
catch
(
error
)
{
return
res
.
status
(
404
).
json
({
...
...
@@ -132,14 +140,16 @@ class scheduleController {
*/
async
getAllSchedules
(
req
,
res
)
{
try
{
const
userId
=
req
.
user
.
id
;
const
schedules
=
await
ScheduleService
.
getAllSchedules
(
userId
);
return
await
performanceMonitor
.
measureAsync
(
'
getAllSchedules
'
,
async
()
=>
{
// const userId = req.user.id;
const
userId
=
49
;
return
res
.
status
(
200
).
json
({
success
:
true
,
data
:
{
schedules
}
const
schedules
=
await
ScheduleService
.
getAllSchedules
(
userId
);
return
res
.
status
(
200
).
json
({
success
:
true
,
data
:
{
schedules
}
});
});
}
catch
(
error
)
{
return
res
.
status
(
500
).
json
({
...
...
@@ -159,18 +169,21 @@ class scheduleController {
*/
async
getScheduleByTimeIdx
(
req
,
res
)
{
try
{
const
{
time_idx
}
=
req
.
params
;
const
userId
=
req
.
user
.
id
;
return
await
performanceMonitor
.
measureAsync
(
'
getScheduleByTimeIdx
'
,
async
()
=>
{
const
{
time_idx
}
=
req
.
params
;
// const userId = req.user.id;
const
userId
=
49
;
const
scheduleRequestDTO
=
new
ScheduleRequestDTO
({
time_idx
:
parseInt
(
time_idx
,
10
)
});
const
validatedData
=
scheduleRequestDTO
.
validate
(
'
get_by_
time_idx
'
);
const
schedule
=
await
ScheduleService
.
getScheduleByTimeIdx
(
userId
,
validatedData
.
time_idx
);
const
scheduleRequestDTO
=
new
ScheduleRequestDTO
({
time_idx
:
parseInt
(
time_idx
,
10
)
}
);
const
validatedData
=
scheduleRequestDTO
.
validate
(
'
get_by_
time_idx
'
);
return
res
.
status
(
200
).
json
({
success
:
true
,
data
:
{
schedule
}
const
schedule
=
await
ScheduleService
.
getScheduleByTimeIdx
(
userId
,
validatedData
.
time_idx
);
return
res
.
status
(
200
).
json
({
success
:
true
,
data
:
{
schedule
}
});
});
}
catch
(
error
)
{
if
(
error
.
message
===
'
Schedule not found
'
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment