Ejemplo n.º 1
0
 public static function getListWine()
 {
     $user_id = Session::get('user_id');
     $error_code = ApiResponse::OK;
     $pagination = ApiResponse::pagination();
     if ($pagination == false) {
         $error_code = ApiResponse::URL_NOT_EXIST;
         $data = ApiResponse::getErrorContent(ApiResponse::URL_NOT_EXIST);
     } else {
         $page = $pagination['page'];
         $limit = $pagination['limit'];
         $wines = Wine::with('winery')->forPage($page, $limit)->get();
         if (count($wines) == 0) {
             $data = array();
         } else {
             foreach ($wines as $wine) {
                 $wine->winery_id = $wine->winery->brand_name;
                 $wine->image_url = Wine::getImageWineFromServer($user_id, $wine->wine_unique_id, $wine->image_url);
                 if ($wine->wine_flag != null) {
                     $wine->wine_flag = URL::asset($wine->wine_flag);
                 }
             }
             $data = $wines->toArray();
         }
     }
     return array("code" => $error_code, "data" => $data);
 }
Ejemplo n.º 2
0
 public function testGetTimelineSuccess()
 {
     $this->setUpRating();
     $this->setUpCountry();
     $this->setUpWineNote();
     $this->setUpProfile();
     $_params = $this->_params;
     $_params['user_id'] = "user_id";
     $response = $this->_getAuth($_params);
     $error_code = ApiResponse::OK;
     $user_timeline = array();
     $user_timeline[] = $this->_user_id;
     $user_follow = Follow::where('from_id', $this->_user_id)->orderBy('updated_at', 'asc')->get();
     if (isset($user_follow)) {
         foreach ($user_follow as $user) {
             $user_timeline[] = $user->to_id;
         }
     }
     $pagination = ApiResponse::pagination();
     $page = $pagination['page'];
     $limit = $pagination['limit'];
     $wine = Wine::with('winery')->forPage($page, $limit)->get();
     $ratings = Rating::whereIn('user_id', $user_timeline)->whereNotNull('wine_unique_id')->with('profile')->with('wine')->forPage($page, $limit)->get();
     foreach ($ratings as $rating) {
         $winery = Winery::where('id', $rating->wine->winery_id)->first();
         $rating->winery = $winery;
         $country = Country::where('id', $rating->winery->country_id)->first();
         $rating->winery->country_name = $country->country_name;
         $like = Like::where('user_id', $this->_user_id)->where('rating_id', $rating->id)->first();
         if ($like) {
             $rating->liked = true;
         } else {
             $rating->liked = false;
         }
         $wishlist = Wishlist::where('user_id', $this->_user_id)->where('wine_unique_id', $rating->wine_unique_id)->first();
         if ($wishlist) {
             $rating->wishlist = true;
         } else {
             $rating->wishlist = false;
         }
         if ($rating->wine->image_url != null) {
             $rating->wine->image_url = URL::asset($rating->wine->image_url);
         }
         if ($rating->wine->wine_flag != null) {
             $rating->wine->wine_flag = URL::asset($rating->wine->wine_flag);
         }
         if ($rating->profile->image != null) {
             $rating->profile->image = URL::asset($rating->profile->image);
         }
         $rating->winery = $rating->winery->toArray();
     }
     $data = $ratings;
     $this->assertEquals(array("code" => ApiResponse::OK, "data" => $ratings->toArray()), json_decode($response->getContent(), true));
 }
Ejemplo n.º 3
0
 public function testGetListWineWrongPage()
 {
     $response = $this->call('GET', 'api/wine?page=2');
     $page = 2;
     $limit = 10;
     $wine_infor = Wine::with('winery')->forPage($page, $limit)->get()->toArray();
     $this->assertEquals(array("code" => ApiResponse::OK, "data" => $wine_infor), json_decode($response->getContent(), true));
 }