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 run() { DB::table('wineries')->delete(); Winery::create(array('id' => '1', 'brand_name' => 'Gnarly Head', 'country_id' => '1', 'region' => 'Dutch', 'description' => 'des')); Winery::create(array('id' => '2', 'brand_name' => 'Pinot Gris/Grigio', 'country_id' => '2', 'region' => 'Alsace', 'description' => 'des')); Winery::create(array('id' => '3', 'brand_name' => 'Stadlmann', 'country_id' => '3', 'region' => 'Austrian', 'description' => 'des')); Winery::create(array('id' => '4', 'brand_name' => 'Chenin Blanc', 'country_id' => '4', 'region' => 'California', 'description' => 'des')); Winery::create(array('id' => '5', 'brand_name' => 'Frescobaldi', 'country_id' => '5', 'region' => 'Chile', 'description' => 'des')); Winery::create(array('id' => '6', 'brand_name' => 'Rice', 'country_id' => '6', 'region' => 'VietNam', 'description' => 'des')); Winery::create(array('id' => '7', 'brand_name' => 'ComerSir', 'country_id' => '7', 'region' => 'Brazil', 'description' => 'des')); Winery::create(array('id' => '8', 'brand_name' => 'Sweet Lips', 'country_id' => '8', 'region' => 'France', 'description' => 'des')); Winery::create(array('id' => '9', 'brand_name' => 'Roney Worker', 'country_id' => '9', 'region' => 'USA', 'description' => 'des')); Winery::create(array('id' => '10', 'brand_name' => 'Rum', 'country_id' => '10', 'region' => 'UK', 'description' => 'des')); }
public function setUpData() { $user = new User(); $user->email = '*****@*****.**'; $user->password = '******'; $user->fb_id = '123456'; $user->save(); $this->_user_id = User::where('email', '*****@*****.**')->first()->user_id; $login = new Login(); $login->id = 1; $login->user_id = $this->_user_id; $login->session_id = '3f9a362bb40714f77cadfd9f5b9d801b'; $login->expired_at = '2019-07-30'; $login->save(); $this->_session = '3f9a362bb40714f77cadfd9f5b9d801b'; $this->_user_id = Login::where('session_id', $this->_session)->first()->user_id; $winery = new Winery(); $winery->id = 1; $winery->brand_name = 'Winery 1'; $winery->country_id = '1'; $winery->region = 'Abkhazia'; $winery->save(); $wine = new Wine(); $wine->wine_id = 1; $wine->name = 'Wine_1'; $wine->rakuten_id = 'rakuten_drinkshop_10508227'; $wine->original_name = "this is wine_1"; $wine->original_name_2 = "wine_1"; $wine->winery_id = 1; $wine->year = '2009'; $wine->wine_unique_id = '1_2009'; $wine->average_price = "2200.00"; $wine->average_rate = "3.5"; $wine->rate_count = "3"; $wine->save(); $this->session(array('user_id' => $this->_user_id)); }
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 function testGetListRatingMyWineSuccess() { $this->setUpRating(); $response = $this->call('GET', 'api/rating'); $page = 1; $limit = 10; $rating = Rating::where('user_id', $this->_user_id)->where('is_my_wine', 1)->with('wine')->orderBy('updated_at', 'desc')->forPage($page, $limit)->get(); foreach ($rating as $ratings) { $ratings->winery = Winery::where('id', $ratings->wine->winery_id)->first()->toArray(); if ($ratings->wine->image_url != null) { $ratings->wine->image_url = URL::asset($ratings->wine->image_url); } if ($ratings->wine->wine_flag != null) { $ratings->wine->wine_flag = URL::asset($ratings->wine->wine_flag); } } $data = $rating; $this->assertEquals(array("code" => ApiResponse::OK, "data" => $data->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 function testUpdateWinerySuccessWrongCountryId() { $_params = $this->_params; $_params['country_id'] = "wrong_country_id"; $response = $this->action('POST', 'WineryController@update', array('id' => 1), array('data' => json_encode($_params), '_method' => 'PUT')); //get created login information $winery_infor = Winery::where('id', 1)->first(); $this->assertEquals(array("code" => ApiResponse::OK, "data" => $winery_infor->toArray()), json_decode($response->getContent(), true)); }
public function run() { DB::table('wines')->truncate(); DB::table('wineries')->truncate(); DB::connection()->disableQueryLog(); set_time_limit(3600); $c = 0; $i = 1; $count = 1; $winery_id = 1; try { $file = app_path() . '/rakuten_wine_data_20140905.csv'; //$file = app_path() . '/testcsv.csv'; $i = 1; $country_name_on_wines = Wine::take(300)->get(array('country_name')); $country_name_ja_list = Country::get(array('country_name_ja')); foreach ($country_name_ja_list as $country_name) { if ($country_name->country_name_ja != null) { if ($i == 1) { $re = $country_name->country_name_ja; $i++; } else { $re = $re . "|" . $country_name->country_name_ja; } } } $re_country_name = "'/" . $re . "/'"; $parser = \KzykHys\CsvParser\CsvParser::fromFile($file, array("encoding" => "UTF-8")); foreach ($parser as $column_wine) { echo $c++ . "\n"; if (count($column_wine) == 33) { $validator = Validator::make(array('rakuten_id' => $column_wine[0]), array('rakuten_id' => 'exists:wines2,rakuten_id')); if ($validator->passes()) { if ($column_wine[13] == 'NA' && $column_wine[14] !== 'NA') { $column_wine[13] = $column_wine[14]; } if ($column_wine[9] == 'NA' && $column_wine[10] !== 'NA') { $column_wine[9] = $column_wine[10]; } for ($j = 0; $j < 33; $j++) { if ($column_wine[$j] == 'NA') { $column_wine[$j] = ''; } } if ($column_wine[3] == '') { $column_wine[3] = $column_wine[1]; } if ($column_wine[9] != null) { $in_string = preg_match($re_country_name, $column_wine[9], $matches); if ($in_string == true) { //$country = explode('・', $country_name->country_name, -1); $country = Country::where('country_name_ja', $matches[0])->first(); if ($country) { $flag = $country->flag_url; } else { $flag = null; } } } $winery = Winery::where('brand_name', $column_wine[16])->first(); if ($winery == null) { $winery_data = array('id' => $winery_id, 'brand_name' => $column_wine[16], 'country_id' => '', 'country_name' => $column_wine[10], 'year' => $column_wine[14], 'winery_url' => $column_wine[18], 'region' => $column_wine[11], 'description' => ''); Winery::create($winery_data); $winery = $winery_id; $winery_id++; } else { $winery = $winery->id; } $wine = array('name' => $column_wine[3], 'name_en' => $column_wine[4], 'sub_name' => $column_wine[5], 'sub_name_en' => $column_wine[6], 'year' => $column_wine[13], 'winery_id' => $winery, 'rakuten_id' => $column_wine[0], 'original_name' => $column_wine[1], 'original_name_2' => $column_wine[2], 'country_name' => $column_wine[9], 'image_url' => $column_wine[27], 'wine_flag' => $flag, 'imformation_image' => $column_wine[21] . ',' . $column_wine[22] . ',' . $column_wine[23] . ',' . $column_wine[24] . ',' . $column_wine[25] . ',' . $column_wine[26], 'rakuten_url' => $column_wine[17], 'wine_unique_id' => $i . '_' . $column_wine[13], 'color' => $column_wine[12], 'average_price' => $column_wine[15], 'average_rate' => 0, 'rate_count' => 0, 'wine_type' => $column_wine[7], 'folder_code' => $column_wine[20]); if ($wine['year'] == '' || $wine['year'] == 0) { $wine['wine_unique_id'] = $i . '_' . $i; } Wine::create($wine); $i++; } } else { $error = implode(",", $column_wine); $file_error = app_path() . "/error.txt"; file_put_contents($file_error, $error . "\n", FILE_APPEND | LOCK_EX); } } } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; } }
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 updateWineDetail($wine_id, $input) { $error_code = ApiResponse::OK; $wine = Wine::where('wine_id', $wine_id)->first(); if ($wine) { if (!empty($input)) { if (!empty($input['name'])) { $wine->name = $input['name']; } if (!empty($input['year'])) { $wine->year = $input['year']; } if (!empty($input['winery_id'])) { $wine->winery_id = $input['winery_id']; } if (!empty($input['image_url'])) { $wine->image_url = $input['image_url']; } if (!empty($input['average_price'])) { $wine->average_price = $input['average_price']; } if (!empty($input['average_rate'])) { $wine->average_rate = $input['average_rate']; } if (!empty($input['wine_type'])) { $wine->wine_type = $input['wine_type']; } $wine->wine_unique_id = $wine->wine_id . '_' . $wine->year; if (Winery::where('id', $wine->winery_id)->first()) { $wine->save(); $data = $wine; } else { $error_code = ApiResponse::UNAVAILABLE_WINERY; $data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_WINERY); } } else { $error_code = ApiResponse::MISSING_PARAMS; $data = $input; } } else { $error_code = ApiResponse::UNAVAILABLE_WINE; $data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_WINE); } return array("code" => $error_code, "data" => $data); }
public function run() { DB::table('wines')->delete(); Wine::create(array('wine_id' => '1', 'name' => 'Gnarly Head Authentic White', 'year' => '2011', 'winery_id' => '1', 'image_url' => 'wines/1.jpg', 'wine_unique_id' => '1_2011', 'average_price' => '1200', 'average_rate' => '3.0', 'wine_type' => '2')); Wine::create(array('wine_id' => '2', 'name' => 'Trimbach Riesling', 'year' => '2010', 'winery_id' => '2', 'image_url' => 'wines/2.png', 'wine_unique_id' => '2_2010', 'average_price' => '1700', 'average_rate' => '4.0', 'wine_type' => '2')); Wine::create(array('wine_id' => '3', 'name' => 'Gruner Love Featuring the Stadlmann Gruner Veltliner ', 'year' => '2011', 'winery_id' => '3', 'image_url' => 'wines/3.png', 'wine_unique_id' => '3_2011', 'average_price' => '1600', 'average_rate' => '2.5', 'wine_type' => '1')); Wine::create(array('wine_id' => '4', 'name' => 'Pine Ridge Chenin Blanc + Viognier ', 'year' => '2013', 'winery_id' => '4', 'image_url' => 'wines/4.png', 'wine_unique_id' => '4_2013', 'average_price' => '1200', 'average_rate' => '2.0', 'wine_type' => '3')); Wine::create(array('wine_id' => '5', 'name' => 'Frescobaldi Nipozzano Chianti Rufina Riserva', 'year' => '2009', 'winery_id' => '5', 'image_url' => 'wines/5.png', 'wine_unique_id' => '5_2009', 'average_price' => '2200', 'average_rate' => '4.5', 'wine_type' => '1')); for ($i = 6; $i < 11; $i++) { $data = array('wine_id' => "{$i}", 'name' => "Wine_{$i}", 'year' => '2009', 'winery_id' => "1", 'wine_flag' => '', 'image_url' => 'wines/' . $i . '.png', 'wine_unique_id' => $i . "_2009", 'average_price' => '2200', 'average_rate' => '4.5', 'wine_type' => '1', 'rate_count' => '3'); $winery_id = $data['winery_id']; $winery = Winery::where('id', $winery_id)->with('country')->first(); if ($winery) { $data['wine_flag'] = $winery->country->flag_url; } else { $data['wine_flag'] = ''; } Wine::create($data); } // Wine::create(array( // 'name' => 'カベルネ・ソーヴィニヨン',s // 'year' => '1990', // 'winery_id' => '1', // 'image_url' => public_path() . '/images/1', // 'wine_unique_id' => '1_1990', // 'average_price' => '0.0', // 'average_rate' => '0.0', // 'wine_type' => '赤', // )); // Wine::create(array( // 'name' => 'メルロー ', // 'year' => '1990', // 'winery_id' => '1', // 'image_url' => public_path() . '/images/2', // 'wine_unique_id' => '2_1990', // 'average_price' => '0.0', // 'average_rate' => '0.0', // 'wine_type' => '赤', // )); // Wine::create(array( // 'name' => 'カルメネール', // 'year' => '1993', // 'winery_id' => '1', // 'image_url' => public_path() . '/images/3', // 'wine_unique_id' => '3_1993', // 'average_price' => '0.0', // 'average_rate' => '0.0', // 'wine_type' => '赤', // )); // Wine::create(array( // 'name' => 'シラー', // 'year' => '1993', // 'winery_id' => '1', // 'image_url' => public_path() . '/images/4', // 'wine_unique_id' => '4_1993', // 'average_price' => '0.0', // 'average_rate' => '0.0', // 'wine_type' => '赤', // )); // Wine::create(array( // 'name' => 'ピノ・ノワール', // 'year' => '1990', // 'winery_id' => '1', // 'image_url' => public_path() . '/images/5', // 'wine_unique_id' => '5_1990', // 'average_price' => '0.0', // 'average_rate' => '0.0', // 'wine_type' => '赤', // )); // Wine::create(array( // 'name' => 'ピノノワール・ロゼ ', // 'year' => '1993', // 'winery_id' => '1', // 'image_url' => public_path() . '/images/6', // 'wine_unique_id' => '6_1993', // 'average_price' => '0.0', // 'average_rate' => '0.0', // 'wine_type' => 'ロゼ', // )); // Wine::create(array( // 'name' => 'シャルドネ', // 'year' => '1990', // 'winery_id' => '1', // 'image_url' => public_path() . '/images/7', // 'wine_unique_id' => '7_1990', // 'average_price' => '0.0', // 'average_rate' => '0.0', // 'wine_type' => '白', // )); // Wine::create(array( // 'name' => 'ゲヴュルツトラミネール ', // 'year' => '1990', // 'winery_id' => '1', // 'image_url' => public_path() . '/images/8', // 'wine_unique_id' => '8_1990', // 'average_price' => '0.0', // 'average_rate' => '0.0', // 'wine_type' => '白', // )); // Wine::create(array( // 'name' => 'リースリング ', // 'year' => '1990', // 'winery_id' => '1', // 'image_url' => public_path() . '/images/9', // 'wine_unique_id' => '9_1990', // 'average_price' => '0.0', // 'average_rate' => '0.0', // 'wine_type' => '白', // )); // Wine::create(array( // 'name' => 'ソーヴィニヨン・ブラン ', // 'year' => '1993', // 'winery_id' => '1', // 'image_url' => public_path() . '/images/10', // 'wine_unique_id' => '10_1993', // 'average_price' => '0.0', // 'average_rate' => '0.0', // 'wine_type' => '白', // )); // Wine::create(array( // 'name' => 'ヴィオニエ', // 'year' => '1993', // 'winery_id' => '1', // 'image_url' => public_path() . '/images/11', // 'wine_unique_id' => '11_1993', // 'average_price' => '0.0', // 'average_rate' => '0.0', // 'wine_type' => '白', // )); }
public static function deleteWinery($id) { $winery = Winery::where('id', $id)->first(); $error_code = ApiResponse::OK; if ($winery) { $winery->delete(); $data = 'Winery deleted'; } else { $error_code = ApiResponse::UNAVAILABLE_WINERY; $data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_WINERY); } return array("code" => $error_code, "data" => $data); }
public function testGetProfileLastRateSucess() { $this->setUpRating(); $user_id = $this->_user_id; $per_page = 10; $page = 1; $response = $this->action('GET', 'ProfileController@get_profile_Last_rate', array('user_id' => $user_id)); $last_rate = Rating::where('user_id', $user_id)->orderBy('updated_at', 'desc')->with('wine')->forPage($page, $per_page)->get(); foreach ($last_rate as $last_rates) { $last_rates->winery = Winery::where('id', $last_rates->wine->winery_id)->first()->toArray(); if ($last_rates->wine->image_url != null) { $last_rates->wine->image_url = URL::asset($last_rates->wine->image_url); } if ($last_rates->wine->wine_flag != null) { $last_rates->wine->wine_flag = URL::asset($last_rates->wine->wine_flag); } } $data = $last_rate; $this->assertEquals(array("code" => ApiResponse::OK, "data" => $data->toArray()), json_decode($response->getContent(), true)); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $result = Winery::deleteWinery($id); return Response::json($result); }