Exemplo n.º 1
0
 public function testCreateRatingErrorWrongIsMyWine()
 {
     $_params = $this->_params;
     $_params['is_my_wine'] = 'wrong_is_my_wine';
     $response = $this->_getAuth($_params);
     $this->assertEquals(json_encode(array("code" => ApiResponse::UNAVAILABLE_RATING, "data" => ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_RATING))), $response->getContent());
 }
 public function testRegisterDeviceExisted()
 {
     Device::create($this->_params);
     $response = $this->_getResponse();
     $this->assertTrue($this->client->getResponse()->isOk());
     $this->assertEquals(json_encode(array("code" => ApiResponse::EXISTED_DEVICE, "data" => ApiResponse::getErrorContent(ApiResponse::EXISTED_DEVICE))), $response->getContent());
 }
Exemplo n.º 3
0
 public static function deleteLike($rating_id)
 {
     $error_code = ApiResponse::OK;
     $user_id = Session::get('user_id');
     if (Rating::where('id', $rating_id)->first()) {
         $like = Like::where('rating_id', $rating_id)->where('user_id', $user_id)->first();
         if ($like) {
             //update like_count on rating
             $like_rating = Rating::where('id', $like->rating_id)->first();
             if ($like_rating != null) {
                 $like_rating->like_count = $like_rating->like_count - 1;
                 $like_rating->save();
             }
             $like->delete();
             $data = 'Like deleted';
         } else {
             $error_code = ApiResponse::NOT_EXISTED_LIKE;
             $data = ApiResponse::getErrorContent(ApiResponse::NOT_EXISTED_LIKE);
         }
     } else {
         $error_code = ApiResponse::UNAVAILABLE_RATING;
         $data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_RATING);
     }
     return array("code" => $error_code, "data" => $data);
 }
Exemplo n.º 4
0
 public function testLogoutErrorInvalidSession()
 {
     $params = $this->_params;
     $params['session_id'] = "123456";
     $response = $this->_getResponse($params);
     $this->assertEquals(json_encode(array("code" => ApiResponse::SESSION_INVALID, "data" => ApiResponse::getErrorContent(ApiResponse::SESSION_INVALID))), $response->getContent());
 }
Exemplo n.º 5
0
 public function testLoginByEmailErrorWrongEmail()
 {
     $_params = $this->_params;
     $_params['email'] = '*****@*****.**';
     $response = $this->_getResponse($_params);
     $this->assertTrue($this->client->getResponse()->isOk());
     $this->assertEquals(json_encode(array("code" => ApiResponse::WRONG_AUTH, "data" => ApiResponse::getErrorContent(ApiResponse::WRONG_AUTH))), $response->getContent());
 }
Exemplo n.º 6
0
 public function testUpdateRatingErrorWrongIsMyWine()
 {
     $this->setUpRating();
     $_params = $this->_params;
     $_params['is_my_wine'] = 'wrong_is_my_wine';
     $response = $this->action('POST', 'RatingController@update', array('id' => 1), array('data' => json_encode($_params), '_method' => 'PUT'));
     $this->assertEquals(json_encode(array("code" => ApiResponse::UNAVAILABLE_RATING, "data" => ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_RATING))), $response->getContent());
 }
Exemplo n.º 7
0
 public function testRegisterErrorExistedEmail()
 {
     $user = new User();
     $user->email = $this->_params['email'];
     $user->password = $this->_params['password'];
     $user->device_id = $this->_params['device_id'];
     $user->save();
     $response = $this->_getResponse();
     $this->assertEquals(json_encode(array("code" => ApiResponse::EXISTED_EMAIL, "data" => ApiResponse::getErrorContent(ApiResponse::EXISTED_EMAIL))), $response->getContent());
 }
Exemplo n.º 8
0
 public static function deleteWishlist($wine_unique_id)
 {
     $user_id = Session::get('user_id');
     $error_code = ApiResponse::OK;
     $wishlist = Wishlist::where('user_id', $user_id)->where('wine_unique_id', $wine_unique_id)->first();
     if ($wishlist) {
         $wishlist->delete();
         $data = 'wine in wishlist is deleted';
     } else {
         $error_code = ApiResponse::NOT_EXISTED_WINE_WISHLIST;
         $data = ApiResponse::getErrorContent(ApiResponse::NOT_EXISTED_WINE_WISHLIST);
     }
     return array("code" => $error_code, "data" => $data);
 }
Exemplo n.º 9
0
 public static function logout($input)
 {
     $error_code = ApiResponse::OK;
     //validate params
     if (!array_key_exists('session_id', $input)) {
         $error_code = ApiResponse::MISSING_PARAMS;
         $data = $input;
     } else {
         //check email existed
         $login_information = self::where('session_id', $input['session_id'])->first();
         if ($login_information == null) {
             $error_code = ApiResponse::SESSION_INVALID;
             $data = ApiResponse::getErrorContent(ApiResponse::SESSION_INVALID);
         } else {
             $login_information->delete();
             $data = "ok";
         }
     }
     return array("code" => $error_code, "data" => $data);
 }
Exemplo n.º 10
0
 public static function push_notification($input)
 {
     $error_code = ApiResponse::OK;
     $validator = Validator::make($input, array('auth_key' => 'required', 'device_id' => 'required', 'platform' => 'required'));
     //validate params
     if ($validator->fails()) {
         $error_code = ApiResponse::MISSING_PARAMS;
         $data = $input;
     } else {
         //check device existed
         if (Device::where('auth_key', $input['auth_key'])->first() != null) {
             $error_code = ApiResponse::EXISTED_DEVICE;
             $data = ApiResponse::getErrorContent(ApiResponse::EXISTED_DEVICE);
         } else {
             $device = Device::create($input);
             if ($device) {
                 $data = "ok";
             }
         }
     }
     return array("code" => $error_code, "data" => $data);
 }
Exemplo n.º 11
0
 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);
 }
Exemplo n.º 12
0
 public function display_error($id)
 {
     return Response::json(array("code" => ApiResponse::URL_NOT_EXIST, "data" => array("message" => ApiResponse::getErrorContent(ApiResponse::URL_NOT_EXIST), "url" => Request::fullUrl())));
 }
Exemplo n.º 13
0
 public static function uploadImageWineScan($wine_unique_id)
 {
     $error_code = ApiResponse::OK;
     $user_id = Session::get('user_id');
     $wine = Wine::where('wine_unique_id', $wine_unique_id)->first();
     if ($wine) {
         if (Input::hasFile('file')) {
             $file = Input::file('file');
             $destinationPath = public_path() . '/images/' . $user_id . '/wine/' . $wine->wine_unique_id;
             $filename = date('YmdHis') . '_' . $file->getClientOriginalName();
             $extension = $file->getClientOriginalExtension();
             if (!File::isDirectory($destinationPath)) {
                 File::makeDirectory($destinationPath, $mode = 0777, true, true);
             } else {
                 File::cleanDirectory($destinationPath);
             }
             $upload_success = $file->move($destinationPath, $filename);
             $data = URL::asset('images/' . $user_id . '/wine/' . $wine_unique_id . '/' . $filename);
         } else {
             $error_code = ApiResponse::MISSING_PARAMS;
             $data = null;
         }
     } else {
         $error_code = ApiResponse::UNAVAILABLE_WINE;
         $data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_WINE);
     }
     return array("code" => $error_code, "data" => $data);
 }
Exemplo n.º 14
0
 public function testDeleteWineNoWine()
 {
     $wine_infor = Wine::destroy(1);
     $wine = Wine::where('wine_id', 1)->first();
     $response = $this->action('delete', 'WineController@destroy', array('wine_id' => 1));
     $this->assertEquals(array("code" => ApiResponse::UNAVAILABLE_WINE, "data" => ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_WINE)), json_decode($response->getContent(), true));
 }
Exemplo n.º 15
0
 public function testForgotPasswordErrorEmailNotExisted()
 {
     $response = $this->_getResponse(array('email' => '*****@*****.**'));
     $this->assertEquals(json_encode(array("code" => ApiResponse::NOT_EXISTED_EMAIL, "data" => ApiResponse::getErrorContent(ApiResponse::NOT_EXISTED_EMAIL))), $response->getContent());
 }
Exemplo n.º 16
0
 public function testDeleteLikeErrorNoLike()
 {
     $like = Like::destroy(1);
     $response = $this->action('delete', 'LikeController@destroy', array('rating_id' => 1));
     $this->assertEquals(array("code" => ApiResponse::NOT_EXISTED_LIKE, "data" => ApiResponse::getErrorContent(ApiResponse::NOT_EXISTED_LIKE)), json_decode($response->getContent(), true));
 }
Exemplo n.º 17
0
 public function testDeleteWineryErrorNoWinery()
 {
     $response = $this->action('delete', 'WineryController@destroy', array('id' => 2));
     //get created login information
     $this->assertEquals(array("code" => ApiResponse::UNAVAILABLE_WINERY, "data" => ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_WINERY)), json_decode($response->getContent(), true));
 }
Exemplo n.º 18
0
 public function testDeleteWishlistErrorNoWishlist()
 {
     $wishlist = Wishlist::destroy(1);
     $response = $this->action('delete', 'WishlistController@destroy', array('wine_unique_id' => "1_2009"));
     $this->assertEquals(array("code" => ApiResponse::NOT_EXISTED_WINE_WISHLIST, "data" => ApiResponse::getErrorContent(ApiResponse::NOT_EXISTED_WINE_WISHLIST)), json_decode($response->getContent(), true));
 }
Exemplo n.º 19
0
 public function testDeleteCommentErrorNoComment()
 {
     $comment = Comment::destroy(1);
     $response = $this->action('delete', 'CommentController@destroy', array('rating_id' => 1, 'id' => 1));
     $this->assertEquals(array("code" => ApiResponse::UNAVAILABLE_COMMENT, "data" => ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_COMMENT)), json_decode($response->getContent(), true));
 }
Exemplo n.º 20
0
 public static function deleteComment($rating_id, $id)
 {
     $comment = Comment::where('id', '=', $id)->first();
     $error_code = ApiResponse::OK;
     if (Rating::where('id', $rating_id)->first()) {
         if ($comment) {
             $comment_profile = Profile::where('user_id', $comment->user_id)->first();
             if ($comment_profile != null) {
                 $comment_profile->comment_count = $comment_profile->comment_count - 1;
                 $comment_profile->save();
             }
             //update comment_count on rating
             $comment_rating = Rating::where('id', $comment->rating_id)->first();
             if ($comment_rating != null) {
                 $comment_rating->comment_count = $comment_rating->comment_count - 1;
                 $comment_rating->save();
                 $comment->delete();
             }
             $data = 'Comment deleted';
         } else {
             $error_code = ApiResponse::UNAVAILABLE_COMMENT;
             $data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_COMMENT);
         }
     } else {
         $error_code = ApiResponse::UNAVAILABLE_RATING;
         $data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_RATING);
     }
     return array("code" => $error_code, "data" => $data);
 }
Exemplo n.º 21
0
 public function testRemoveNoRating()
 {
     $response = $this->action('delete', 'RatingController@remove', array('id' => 1));
     $this->assertEquals(array("code" => ApiResponse::UNAVAILABLE_RATING, "data" => ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_RATING)), json_decode($response->getContent(), true));
 }
Exemplo n.º 22
0
|--------------------------------------------------------------------------
|
| The CSRF filter is responsible for protecting your application against
| cross-site request forgery attacks. If this special token in a user
| session does not match the one given in this request, we'll bail.
|
*/
Route::filter('csrf', function () {
    if (Session::token() != Input::get('_token')) {
        throw new Illuminate\Session\TokenMismatchException();
    }
});
Route::filter('session', function () {
    $session = Request::header('session');
    $error_code = ApiResponse::SESSION_INVALID;
    $data = ApiResponse::getErrorContent(ApiResponse::SESSION_INVALID);
    if (empty($session)) {
        return array("code" => $error_code, "data" => $data);
    } else {
        $login = Login::where('session_id', $session)->first();
        $date = Carbon::now()->format('Y-m-d H:i:s');
        if ($date > $login["expired_at"]) {
            return array("code" => $error_code, "data" => $data);
        }
        $user = User::where('user_id', $login->user_id)->first();
        if ($user) {
            Session::put('user_id', $login->user_id);
        } else {
            return array("code" => $error_code, "data" => $data);
        }
    }
Exemplo n.º 23
0
 public function testDeleteWinenoteErrorWrongWine()
 {
     $response = $this->action('delete', 'WinenoteController@destroy', array('wine_unique_id' => "wrong_wine_unique_id"));
     $this->assertEquals(array("code" => ApiResponse::UNAVAILABLE_WINE, "data" => ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_WINE)), json_decode($response->getContent(), true));
 }
Exemplo n.º 24
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);
 }
Exemplo n.º 25
0
 public function testDeleteFollowErrorNoFollow()
 {
     $follow = Follow::destroy(1);
     $follow_id = User::where('email', '*****@*****.**')->first()->user_id;
     $response = $this->action('delete', 'FollowController@destroy', array('follow_id' => $follow_id));
     $this->assertEquals(array("code" => ApiResponse::NOT_EXISTED_FOLLOW, "data" => ApiResponse::getErrorContent(ApiResponse::NOT_EXISTED_FOLLOW)), json_decode($response->getContent(), true));
 }
Exemplo n.º 26
0
 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);
 }
Exemplo n.º 27
0
 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);
 }
Exemplo n.º 28
0
 public function testGetProfileLastRateErrorWrongUserId()
 {
     $this->setUpRating();
     $user_id = "wrong_user_id";
     $per_page = 10;
     $page = 1;
     $response = $this->action('GET', 'ProfileController@get_profile_Last_rate', array('user_id' => $user_id));
     $this->assertEquals(array("code" => ApiResponse::UNAVAILABLE_USER, "data" => ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_USER)), json_decode($response->getContent(), true));
 }
Exemplo n.º 29
0
 public static function removeWineFromMyWine($id)
 {
     $rating = Rating::where('id', $id)->first();
     $error_code = ApiResponse::OK;
     if ($rating) {
         $rating->is_my_wine = 0;
         $rating->save();
         $data = 'Rating is removed from my wine';
     } else {
         $error_code = ApiResponse::UNAVAILABLE_RATING;
         $data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_RATING);
     }
     return array("code" => $error_code, "data" => $data);
 }
Exemplo n.º 30
0
 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);
 }