public function testGetCourseById() { for ($i = 1; $i <= $this->seedRowNumber; ++$i) { $course = $this->repository->getCourseById($i); $this->assertEquals($course->id, $i); } }
protected function notify(Request $request) { $this->dataRule = ['type' => 'between:1,2', 'course_id' => 'numeric']; if (($valid = $this->vaild_data_format($request->all(), ['type', 'course_id'])) !== true) { $this->responseCode = 400; $this->responseData['error'] = $valid; return $this->send_response(); } $type = $request->get('type'); $course_id = $request->get('course_id'); $course = $this->courseRepository->getCourseById($course_id); $user = \Auth::user(); $now = \Carbon\Carbon::now(); if ($type === "1") { $content = "點名通知:(" . $this->weekMap[$now->format("l")] . ")" . $now->format("H:i") . " " . $user->real_name . " 在" . $course->course_nameCH . "發出了點名通知!"; } else { $content = "考試通知:(" . $this->weekMap[$now->format("l")] . ")" . $now->format("H:i") . " " . $user->real_name . " 在" . $course->course_nameCH . "發出了考試通知!"; } try { $this->facebookService->sendNotification($user, $course, $content, $type); $this->responseCode = 200; $this->responseData['status'] = "success"; } catch (\Exception $e) { $this->responseCode = 403; $this->responseData['error'] = $e->getMessage(); } finally { return $this->send_response(); } }