public static function getWishlist() { $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']; $wishlists = Wishlist::where('user_id', $user_id)->with('wine')->forPage($page, $limit)->get(); if (count($wishlists) == 0) { $data = array(); } else { foreach ($wishlists as $wishlist) { $wishlist->winery = Winery::where('id', $wishlist->wine->winery_id)->first(); if ($wishlist->wine->image_url != null) { $wishlist->wine->image_url = URL::asset($wishlist->wine->image_url); } if ($wishlist->wine->wine_flag != null) { $wishlist->wine->wine_flag = URL::asset($wishlist->wine->wine_flag); } } $data = $wishlists->toArray(); } } return array("code" => $error_code, "data" => $data); }
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)); }
public function testGetListWishlistSuccess() { $response = $this->call('GET', 'api/wishlist'); $wishlist_infor = Wishlist::all(); $pagination = ApiResponse::pagination(); $page = $pagination['page']; $limit = $pagination['limit']; $wishlist_infor = Wishlist::where('user_id', $this->_user_id)->with('wine')->forPage($page, $limit)->get(); foreach ($wishlist_infor as $wishlists) { $wishlists->winery = Winery::where('id', $wishlists->wine->winery_id)->first()->toArray(); if ($wishlists->wine->image_url != null) { $wishlists->wine->image_url = URL::asset($wishlists->wine->image_url); } if ($wishlists->wine->wine_flag != null) { $wishlists->wine->wine_flag = URL::asset($wishlists->wine->wine_flag); } } $this->assertEquals(array("code" => ApiResponse::OK, "data" => $wishlist_infor->toArray()), json_decode($response->getContent(), true)); }
public static function getListRatingMyWine() { $user_id = Session::get('user_id'); $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']; $ratings = Rating::where('user_id', $user_id)->where('is_my_wine', 1)->with('wine')->orderBy('updated_at', 'desc')->forPage($page, $limit)->get(); $error_code = ApiResponse::OK; if (count($ratings) == 0) { $data = array(); } else { foreach ($ratings as $rating) { $rating->winery = Winery::where('id', $rating->wine->winery_id)->first(); $rating->wine->image_url = Wine::getImageWineFromServer($user_id, $rating->wine->wine_unique_id, $rating->wine->image_url); if ($rating->wine->wine_flag != null) { $rating->wine->wine_flag = URL::asset($rating->wine->wine_flag); } } $data = $ratings->toArray(); } } return array("code" => $error_code, "data" => $data); }
public static function getProfieLastRate($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']; if (User::where('user_id', $user_id)->first()) { $last_rates = Rating::where('user_id', $user_id)->orderBy('updated_at', 'desc')->with('wine')->forPage($page, $limit)->get(); foreach ($last_rates as $last_rate) { $last_rate->winery = Winery::where('id', $last_rate->wine->winery_id)->first(); if ($last_rate->wine->image_url != null) { $last_rate->wine->image_url = URL::asset($last_rate->wine->image_url); } if ($last_rate->wine->wine_flag != null) { $last_rate->wine->wine_flag = URL::asset($last_rate->wine->wine_flag); } } $data = $last_rates->toArray(); } else { $error_code = ApiResponse::UNAVAILABLE_USER; $data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_USER); } } return array("code" => $error_code, "data" => $data); }
public static function getWineRelated($input) { $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']; if (!empty($input['wine_id'])) { $wine_id = $input['wine_id']; $wine = Wine::where('wine_id', $wine_id)->first(); if ($wine) { $wine_related = Wine::where('winery_id', $wine->winery_id)->whereNotIn('wine_id', [$wine_id])->forPage($page, $limit)->get(); $data = $wine_related->toArray(); } else { $error_code = ApiResponse::UNAVAILABLE_WINE; $data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_WINE); } } else { $error_code = ApiResponse::MISSING_PARAMS; $data = $input; } } return array("code" => $error_code, "data" => $data); }
public static function getListFollowing($user_id) { $error_code = ApiResponse::OK; $data = array(); if (User::where('user_id', $user_id)) { $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']; $users_followers = Follow::where('from_id', $user_id)->forPage($page, $limit)->get(); if ($users_followers) { foreach ($users_followers as $user_follower) { $user = Profile::where('user_id', $user_follower->to_id)->first(); if ($user) { if ($user->image != null) { $user->image = URL::asset($user->image); } $user_follower = $user; $data[] = $user_follower; } } } } } else { $error_code = ApiResponse::UNAVAILABLE_USER; $data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_USER); } return array("code" => $error_code, "data" => $data); }
public static function ranking() { $user_id = Session::get('user_id'); $error_code = ApiResponse::OK; $data = array(); $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']; $users = Profile::orderBy('rate_count', 'desc')->forPage($page, $limit)->get(); if (count($users) != 0) { foreach ($users as $user) { $follow = Follow::where('from_id', $user_id)->where('to_id', $user->user_id)->first(); if ($follow) { $user->is_follow = true; } else { if ($user->user_id != $user_id) { $user->is_follow = false; } } if ($user->image != null) { $user->image = URL::asset($user->image); } } $data = $users->toArray(); } } return array("code" => $error_code, "data" => $data); }