diff --git a/controllers/scheduleController.js b/controllers/scheduleController.js index 4d43ee118a980c6ddf536eff25592f0cf734a66c..e2c7122dfc0eb40b8d395a6003cad9845bc6fa6c 100644 --- a/controllers/scheduleController.js +++ b/controllers/scheduleController.js @@ -22,22 +22,19 @@ class scheduleController { async createSchedule(req, res) { try { const userId = req.user.id; - const scheduleRequestDTO = new ScheduleRequestDTO(req.body); - const validatedData = scheduleRequestDTO.validate('create'); // 'create' 타입 검증 + const { title, is_fixed, time_indices } = req.body; - const { title, is_fixed, events } = validatedData; - - const schedules = await ScheduleService.createSchedules({ + const schedule = await ScheduleService.createSchedules({ userId, title, is_fixed, - events + time_indices }); return res.status(201).json({ success: true, data: { - schedules + schedule } }); } catch (error) { @@ -49,7 +46,7 @@ class scheduleController { } }); } - } + } /** * 스케줄 수정 @@ -57,31 +54,32 @@ class scheduleController { * Bulk update 지원 * 요청 본문 예시: * { - * updates: [ - * { time_idx: 36, title: 'New Title', is_fixed: true }, - * { time_idx: 44, title: 'Another Title' }, - * // ... - * ] + * "originalTitle": "알고리즘 스터디", // 기존 스케줄의 제목 + * "title": "알고리즘 스터디 2.0", // 변경할 제목 (제목 변경 안할거면 기존 제목을 넣어야함 * -> title로 동일 스케줄을 찾아서) + * "is_fixed": true, + * "time_indices": [36, 37, 38, 40] // 변경할 time_indices 배열 * } */ async updateSchedules(req, res) { try { const userId = req.user.id; - const scheduleRequestDTO = new ScheduleRequestDTO(req.body); - const validatedData = scheduleRequestDTO.validate('bulk_update'); // 'bulk_update' 타입 검증 - - const { updates } = validatedData; + const { originalTitle, title, is_fixed, time_indices } = req.body; - const updatedSchedules = await ScheduleService.updateSchedules(userId, updates); + const updatedSchedule = await ScheduleService.updateSchedules(userId, { + originalTitle, + title, + is_fixed, + time_indices + }); return res.status(200).json({ success: true, data: { - schedules: updatedSchedules + schedule: updatedSchedule } }); } catch (error) { - if (error.code === 'SCHEDULE_NOT_FOUND') { + if (error.message === 'Schedule not found') { return res.status(404).json({ success: false, error: { @@ -106,24 +104,21 @@ class scheduleController { * Bulk delete 지원 * 요청 본문 예시: * { - * time_idxs: [36, 44, ...] + * "title": "알고리즘 스터디" * } */ async deleteSchedules(req, res) { try { const userId = req.user.id; - const scheduleRequestDTO = new ScheduleRequestDTO(req.body); - const validatedData = scheduleRequestDTO.validate('bulk_delete'); // 'bulk_delete' 타입 검증 - - const { time_idxs } = validatedData; + const { title } = req.body; - const result = await ScheduleService.deleteSchedules(userId, time_idxs); + const result = await ScheduleService.deleteSchedules(userId, title); return res.status(200).json({ success: true, data: { - message: 'Schedules successfully deleted', - deleted_time_idxs: result.deleted_time_idxs + message: 'Schedule successfully deleted', + deletedCount: result.deletedCount } }); } catch (error) { @@ -136,7 +131,6 @@ class scheduleController { }); } } - /** * 해당 사용자 전체 스케줄 조회 * GET /api/schedule/all @@ -148,7 +142,9 @@ class scheduleController { return res.status(200).json({ success: true, - data: schedules + data: { + schedules + } }); } catch (error) { return res.status(500).json({ @@ -175,7 +171,9 @@ class scheduleController { return res.status(200).json({ success: true, - data: schedule + data: { + schedule + } }); } catch (error) { if (error.message === 'Schedule not found') { diff --git a/services/meetingService.js b/services/meetingService.js index 24b9e67f94799975c8826f442002783b51c8360b..746597dcf5123cc7802ae8087e763a028b3d34cc 100644 --- a/services/meetingService.js +++ b/services/meetingService.js @@ -118,20 +118,16 @@ class MeetingService { { transaction } ); - // 스케줄 생성 (모임 시간 범위 내 모든 time_idx에 대해 생성) - const events = []; - for (let idx = time_idx_start; idx <= time_idx_end; idx++) { - events.push({ time_idx: idx }); - } - await ScheduleService.createSchedules( - { - userId: created_by, - title: `번개 모임: ${title}`, - is_fixed: false, - events: events, - }, - transaction + const time_indices = Array.from( + { length: time_idx_end - time_idx_start + 1 }, + (_, i) => time_idx_start + i ); + await ScheduleService.createSchedules({ + userId: created_by, + title: `번개 모임: ${title}`, + is_fixed: false, + time_indices: time_indices, + }, transaction); // 친구 초대 로직 호출 const invitedFriendIds = await this.sendInvites({ @@ -264,24 +260,17 @@ class MeetingService { { transaction } ); - // 스케줄 생성 (모임 시간 범위 내 모든 time_idx에 대해 생성) - const events = []; - for ( - let idx = meeting.time_idx_start; - idx <= meeting.time_idx_end; - idx++ - ) { - events.push({ time_idx: idx }); - } - await ScheduleService.createSchedules( - { - userId: userId, - title: `번개 모임: ${meeting.title}`, - is_fixed: false, - events: events, - }, - transaction - ); + const time_indices = Array.from( + { length: meeting.time_idx_end - meeting.time_idx_start + 1 }, + (_, i) => meeting.time_idx_start + i + ); + + await ScheduleService.createSchedules({ + userId: userId, + title: `번개 모임: ${meeting.title}`, + is_fixed: false, + time_indices: time_indices, + }, transaction); // 채팅방 참가 (MongoDB) const user = await User.findOne({