Example #1
0
 public function setUp()
 {
     parent::setUp();
     $this->setUpData();
     $wine_note = new Winenote();
     $wine_note->wine_unique_id = "1_2009";
     $wine_note->user_id = $this->_user_id;
     $wine_note->note = "this is note test";
     $wine_note->save();
     $follow = new Follow();
     $follow->from_id = $this->_user_id;
     $follow->to_id = "3620a42d-fcbb-45eb-b3a5-36cada1b77b7";
     $follow->save();
 }
 public function run()
 {
     DB::table('wine_notes')->delete();
     $user_id = User::where('email', '*****@*****.**')->first()->user_id;
     $user_1 = User::where('email', '*****@*****.**')->first()->user_id;
     $user_2 = User::where('email', '*****@*****.**')->first()->user_id;
     $wine_1 = Wine::where('wine_id', 1)->first()->wine_unique_id;
     $wine_2 = Wine::where('wine_id', 2)->first()->wine_unique_id;
     $wine_3 = Wine::where('wine_id', 3)->first()->wine_unique_id;
     Winenote::create($data = array('id' => 1, 'wine_unique_id' => $wine_1, 'user_id' => $user_id, 'note' => 'This is note 1'));
     Winenote::create($data = array('id' => 2, 'wine_unique_id' => $wine_2, 'user_id' => $user_1, 'note' => 'This is note 2'));
     Winenote::create($data = array('id' => 3, 'wine_unique_id' => $wine_3, 'user_id' => $user_2, 'note' => 'This is note 3'));
 }
Example #3
0
 public static function getWineDetail($wine_id)
 {
     $user_id = Session::get('user_id');
     $wine = Wine::where('wine_id', $wine_id)->with('winery')->first();
     $error_code = ApiResponse::OK;
     if ($wine) {
         if ($wine->wine_type != null) {
             $wine->wine_type = Wine::getWineType($wine->wine_type);
         }
         $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);
         }
         $country = Country::where('id', $wine->winery->country_id)->first();
         if ($country) {
             $wine->winery->country_id = $country->country_name;
         } else {
             $wine->winery->country_id = null;
         }
         $wine_note = Winenote::where('wine_unique_id', $wine->wine_unique_id)->where('user_id', $user_id)->first();
         if ($wine_note) {
             $wine->winenote = $wine_note->note;
         } else {
             $wine->winenote = null;
         }
         $wishlist = Wishlist::where('user_id', $user_id)->where('wine_unique_id', $wine->wine_unique_id)->first();
         if ($wishlist) {
             $wine->is_wishlist = true;
         } else {
             $wine->is_wishlist = false;
         }
         $all_wines_winery = Wine::where('winery_id', $wine->winery_id)->whereNotIn('wine_id', [$wine_id])->where('year', '>', 0)->where('average_rate', '>', 0)->orderBy('year', 'desc')->take(10)->get();
         $wine->winery->count_wine = count($all_wines_winery) + 1;
         $rate_winery = $wine->rate_count;
         if (count($all_wines_winery) !== 0) {
             $sum_rate_winery = $wine->average_rate;
             foreach ($all_wines_winery as $wine_winery) {
                 $wine_on_winery = Wine::where('wine_id', $wine_winery->wine_id)->first();
                 $wine_on_winery->image_url = Wine::getImageWineFromServer($user_id, $wine_on_winery->wine_unique_id, $wine_on_winery->image_url);
                 $rate_count = $wine_on_winery->rate_count;
                 $rate_winery = $rate_winery + $rate_count;
                 $average_rate = $wine_on_winery->average_rate;
                 $sum_rate_winery = $sum_rate_winery + $average_rate;
             }
             $wine->winery->total_rate = $rate_winery;
             $wine->winery->average_rate_winery = $sum_rate_winery / count($all_wines_winery);
         } else {
             $wine->winery->total_rate = $rate_winery;
             $wine->winery->average_rate_winery = $wine->average_rate;
         }
         $wine->total_like = 0;
         $rating_user = Rating::where('wine_unique_id', $wine->wine_unique_id)->where('user_id', $user_id)->with('profile')->first();
         if (count($rating_user) == 0) {
             $rating_user = null;
         } else {
             if ($rating_user->profile->image != null) {
                 $rating_user->profile->image = URL::asset($rating_user->profile->image);
             }
             $wine->total_like = $wine->total_like + $rating_user->like_count;
         }
         $ratings = Rating::where('wine_unique_id', $wine->wine_unique_id)->whereNotIn('user_id', [$user_id])->with('profile')->get();
         if (count($ratings) == 0) {
             $ratings = array();
         } else {
             foreach ($ratings as $rating) {
                 if ($rating->profile->image != null) {
                     $rating->profile->image = URL::asset($rating->profile->image);
                 }
                 $follow = Follow::where('from_id', $user_id)->where('to_id', $rating->user_id)->first();
                 if ($follow) {
                     $rating->is_follow = true;
                 } else {
                     $rating->is_follow = false;
                 }
                 $wine->total_like = $wine->total_like + $rating->like_count;
             }
         }
         $data = array('wine' => $wine, 'rate_user' => $rating_user, 'rate' => $ratings, 'wine_related' => $all_wines_winery);
     } else {
         $error_code = ApiResponse::UNAVAILABLE_WINE;
         $data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_WINE);
     }
     return array("code" => $error_code, "data" => $data);
 }
Example #4
0
 public static function deleteWinenote($wine_unique_id)
 {
     $user_id = Session::get('user_id');
     $winenote = Winenote::where('user_id', $user_id)->where('wine_unique_id', $wine_unique_id)->first();
     $error_code = ApiResponse::OK;
     if (Wine::where('wine_unique_id', $wine_unique_id)->first()) {
         if ($winenote) {
             $winenote->delete();
             $data = 'Wine note is deleted';
         } else {
             $error_code = ApiResponse::UNAVAILABLE_WINE_NOTE;
             $data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_WINE_NOTE);
         }
     } else {
         $error_code = ApiResponse::UNAVAILABLE_WINE;
         $data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_WINE);
     }
     return array("code" => $error_code, "data" => $data);
 }
Example #5
0
 public function setUpWineNote()
 {
     $winenote = new Winenote();
     $winenote->wine_unique_id = '1_2009';
     $winenote->note = 'this is note test';
     $winenote->user_id = $this->_user_id;
     $winenote->save();
 }
Example #6
0
 public function testGetWineDetailNoWineNote()
 {
     $this->setUpRating();
     $this->setUpCountry();
     $this->setUpProfile();
     $wine_note = Winenote::destroy(1);
     $response = $this->call('GET', 'api/wine/1');
     $wine_infor = Wine::where('wine_id', 1)->with('winery')->first();
     $wine_infor->total_like = 0;
     $country_name = Country::where('id', $wine_infor->winery->country_id)->first()->country_name;
     $wine_infor->winenote = null;
     $wine_infor->winery->country_id = $country_name;
     if ($wine_infor->wine_type != null) {
         $wine_infor->wine_type = Wine::getWineType($wine_infor->wine_type);
     }
     $wishlist = Wishlist::where('user_id', $this->_user_id)->where('wine_unique_id', $wine_infor->wine_unique_id)->first();
     if ($wishlist) {
         $wine_infor->is_wishlist = true;
     } else {
         $wine_infor->is_wishlist = false;
     }
     $all_wines_winery = Wine::where('winery_id', $wine_infor->winery_id)->whereNotIn('wine_id', [1])->take(10)->get();
     $wine_infor->winery->count_wine = count($all_wines_winery) + 1;
     $rate_winery = $wine_infor->rate_count;
     if (count($all_wines_winery) !== 0) {
         $sum_rate_winery = $wine_infor->average_rate;
         foreach ($all_wines_winery as $wine_winery) {
             $wine_on_winery = Wine::where('wine_id', $wine_winery->wine_id)->first();
             $rate_count = $wine_on_winery->rate_count;
             $rate_winery = $rate_winery + $rate_count;
             $average_rate = $wine_on_winery->average_rate;
             $sum_rate_winery = $sum_rate_winery + $average_rate;
         }
         $wine_infor->winery->total_rate = $rate_winery;
         $wine_inforine->winery->average_rate_winery = $sum_rate_winery / count($all_wines_winery);
     } else {
         $wine_infor->winery->total_rate = $rate_winery;
         $wine_infor->winery->average_rate_winery = $wine_infor->average_rate;
     }
     $rating_user = Rating::where('wine_unique_id', $wine_infor->wine_unique_id)->where('user_id', $this->_user_id)->with('profile')->first();
     if ($rating_user->profile->image != null) {
         $rating_user->profile->image = URL::asset($rating_user->profile->image);
     }
     $wine_infor->total_like = $wine_infor->total_like + $rating_user->like_count;
     $rating = Rating::where('wine_unique_id', $wine_infor->wine_unique_id)->whereNotIn('user_id', [$this->_user_id])->with('profile')->get();
     if (count($rating) == 0) {
         $rating = array();
     } else {
         foreach ($rating as $ratings) {
             if ($ratings->profile->image != null) {
                 $ratings->profile->image = URL::asset($ratings->profile->image);
             }
             $follow = Follow::where('from_id', $this->_user_id)->where('to_id', $ratings->user_id)->first();
             if ($follow) {
                 $ratings->is_follow = true;
             } else {
                 $ratings->is_follow = false;
             }
             $wine_infor->total_like = $wine_infor->total_like + $ratings->like_count;
         }
     }
     if ($wine_infor->image_url != null) {
         $wine_infor->image_url = URL::asset($wine_infor->image_url);
     }
     if ($wine_infor->wine_flag != null) {
         $wine_infor->wine_flag = URL::asset($wine_infor->wine_flag);
     }
     $data = array('wine' => $wine_infor->toArray(), 'rate_user' => $rating_user->toArray(), 'rate' => $rating->toArray(), 'wine_related' => $all_wines_winery->toArray());
     $this->assertEquals(array("code" => ApiResponse::OK, "data" => $data), json_decode($response->getContent(), true));
 }
Example #7
0
 public function testDeleteWinenoteErrorNoWinenote()
 {
     $winenote = Winenote::destroy(1);
     $response = $this->action('delete', 'WinenoteController@destroy', array('wine_unique_id' => "1_2009"));
     $this->assertEquals(array("code" => ApiResponse::UNAVAILABLE_WINE_NOTE, "data" => ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_WINE_NOTE)), json_decode($response->getContent(), true));
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($wine_unique_id)
 {
     $result = Winenote::deleteWinenote($wine_unique_id);
     return Response::json($result);
 }