Exemplo n.º 1
0
 /**
  * get notification
  *
  * default => the newset 10
  *
  * @param Request $request
  * @return Response
  */
 protected function show(Request $request)
 {
     $user = \Auth::User();
     if ($this->vaild_data_format($request->all(), ['range', 'item_id']) === true) {
         $item_id = $request->get("item_id");
         $range = $request->get("range");
         if ($range > 0) {
             $notis = $this->notificationRepository->getNotificationBack($user->stu_id, $item_id, $range);
         } else {
             $notis = $this->notificationRepository->getNotificationFront($user->stu_id, $item_id, $range * -1);
         }
     } else {
         $notis = $this->notificationRepository->getLatest10Notification($user->stu_id);
     }
     $this->responseData['status'] = "success";
     $this->responseData['data'] = NotificationPresenter::db2api($notis->toArray());
     $this->responseCode = 200;
     return $this->send_response();
 }
 public function testGetNotificationById()
 {
     $user = $this->users->random();
     $stu_id = $user->stu_id;
     // default case
     $result = $this->repository->getLatest10Notification($stu_id);
     $this->assertEquals(10, $result->count());
     $first_id = $result->sortByDesc('id')->first()->id;
     $this->assertEquals($result->first()->id, $first_id);
     // id = 10 range = 5
     $result = $this->repository->getNotificationBack($stu_id, 10, 5);
     $this->assertEquals(5, $result->count());
     $first_id = $result->sortBy('id')->first()->id;
     $this->assertEquals($result->first()->id, $first_id);
     // id = 20 range = -7
     $result = $this->repository->getNotificationFront($stu_id, 20, 7);
     $this->assertEquals(7, $result->count());
     $first_id = $result->sortByDesc('id')->first()->id;
     $this->assertEquals($result->first()->id, $first_id);
 }