Select Git revision
scheduleController.js
scheduleController.js 6.62 KiB
// controllers/scheduleController.js
const ScheduleService = require('../services/scheduleService');
const ScheduleRequestDTO = require('../dtos/ScheduleRequestDTO');
const performanceMonitor = require('../utils/performanceMonitor');
class scheduleController {
/**
* 스케줄 생성
* POST /api/schedule
* 해당 사용자 id는 auth 미들웨어에서 설정된 사용자 정보 이용
* req.user = User 모델의 인스턴스
* 요청 본문 예시:
* {
* title: 'Schedule Title',
* is_fixed: true,
* events: [
* { time_idx: 36 },
* { time_idx: 37 },
* // ...
* ]
* }
*/
async createSchedule(req, res) {
try {
return await performanceMonitor.measureAsync('createSchedule', async () => {
const userId = req.user.id;
const scheduleRequestDTO = new ScheduleRequestDTO(req.body);
const validatedData = scheduleRequestDTO.validate('create');
const schedule = await ScheduleService.createSchedules({
userId,
...validatedData
});
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
* Bulk update 지원
* 요청 본문 예시:
* {
* "originalTitle": "알고리즘 스터디", // 기존 스케줄의 제목
* "title": "알고리즘 스터디 2.0", // 변경할 제목 (제목 변경 안할거면 기존 제목을 넣어야함 * -> title로 동일 스케줄을 찾아서)
* "is_fixed": true,
* "time_indices": [36, 37, 38, 40] // 변경할 time_indices 배열
* }
*/
async updateSchedules(req, res) {
try {
return await performanceMonitor.measureAsync('updateSchedules', async () => {
const userId = req.user.id;
const scheduleRequestDTO = new ScheduleRequestDTO(req.body);
const validatedData = scheduleRequestDTO.validate('bulk_update');
const updatedSchedule = await ScheduleService.updateSchedules(userId, validatedData);