validate([ 'start_date' => 'nullable|date_format:Y-m-d', 'end_date' => 'nullable|date_format:Y-m-d|after_or_equal:start_date', 'type' => 'nullable|in:schedule,order,construction,other', 'department_filter' => 'nullable|in:all,department,personal', ]); // 기본값 설정: 이번 달 전체 $today = Carbon::today(); $startDate = $validated['start_date'] ?? $today->copy()->startOfMonth()->format('Y-m-d'); $endDate = $validated['end_date'] ?? $today->copy()->endOfMonth()->format('Y-m-d'); $type = $validated['type'] ?? null; $departmentFilter = $validated['department_filter'] ?? 'all'; return ApiResponse::handle(function () use ($startDate, $endDate, $type, $departmentFilter) { return $this->calendarService->getSchedules( $startDate, $endDate, $type, $departmentFilter ); }, __('message.fetched')); } /** * 일정 등록 */ public function store(Request $request) { $validated = $request->validate([ 'title' => 'required|string|max:200', 'description' => 'nullable|string|max:1000', 'start_date' => 'required|date_format:Y-m-d', 'end_date' => 'required|date_format:Y-m-d|after_or_equal:start_date', 'start_time' => 'nullable|date_format:H:i', 'end_time' => 'nullable|date_format:H:i', 'is_all_day' => 'boolean', 'color' => 'nullable|string|max:20', ]); return ApiResponse::handle(function () use ($validated) { return $this->calendarService->createSchedule($validated); }, __('message.created')); } /** * 일정 수정 */ public function update(Request $request, int $id) { $validated = $request->validate([ 'title' => 'required|string|max:200', 'description' => 'nullable|string|max:1000', 'start_date' => 'required|date_format:Y-m-d', 'end_date' => 'required|date_format:Y-m-d|after_or_equal:start_date', 'start_time' => 'nullable|date_format:H:i', 'end_time' => 'nullable|date_format:H:i', 'is_all_day' => 'boolean', 'color' => 'nullable|string|max:20', ]); return ApiResponse::handle(function () use ($id, $validated) { return $this->calendarService->updateSchedule($id, $validated); }, __('message.updated')); } /** * 일정 삭제 */ public function destroy(int $id) { return ApiResponse::handle(function () use ($id) { return $this->calendarService->deleteSchedule($id); }, __('message.deleted')); } }