/**
  * @param $token
  * @param $food_data
  * @param transpo
  * @return reponse json
  */
 public static function addSpot($token, $food_data, $transpo)
 {
     //todo
     $response = self::resolveNewSegmentFromActivity($token, $transpo, $food_data);
     if ($response['err code'] == '403') {
         return $response;
     }
     $current_iterinary = self::getUserCurrentIterinary($token);
     if ($current_iterinary['err'] == 'err') {
         return response()->json($current_iterinary, 403);
     }
     $day = self::getDiffInDays($token, $current_iterinary->id);
     $activity = new Activity();
     $activity->start_time = Carbon::now()->toTimeString();
     $activity->iterinary_id = $current_iterinary->id;
     $activity->day = $day;
     $eat = new Spot();
     $eat->place_name = $food_data['place_name'];
     $eat->lng = $food_data['lng'];
     $eat->lat = $food_data['lat'];
     $eat->tips = $food_data['review'];
     $eat->price = $food_data['price'];
     $eat->foursquare_id = !$food_data['foursquare_id'] == "" ? null : $food_data['foursquare_id'];
     $spotcategory = FoursquareHelper::resolveSpotCategory($food_data['category']['cat_id']);
     //        return $foodcategory;
     //        return response()->json($foodcategory['main_cat']);
     $eat->main_category_id = $spotcategory['main_cat'];
     $eat->sub_category_id = $spotcategory['sub_cat'];
     $pic = $food_data['category'];
     $eat->pic_url = $pic['prefix'] . 'bg_64' . $pic['suffix'];
     //        return response()->json($eat);
     $eat->save();
     $eat->activity()->save($activity);
     self::updateIterinary($token);
     $iterinary = Iterinary::findOrFail($current_iterinary->id)->with('activities.typable')->first();
     return response()->json($eat, 200);
     //        $current_iterinary = self::getUserCurrentIterinary($token);
     //        $day = self::getDiffInDays($token, $current_iterinary->id);
     //        $activity = new Activity();
     //        $activity->start_time = Carbon::now()->toTimeString();
     //        $activity->iterinary_id = $current_iterinary->id;
     //        $activity->day = $day;
     //        $eat = new Spot();
     //        $eat->place_name = $spot_data['place_name'];
     //
     //        $eat->lng = $spot_data['lng'];
     //        $eat->lat = $spot_data['lat'];
     //        $eat->tips = $spot_data['review'];
     //        $eat->price = $spot_data['price'];
     //
     //        $spot_category = FoursquareHelper::resolveSpotCategory($spot_data['category']['cat_id']);
     //
     ////        return response()->json($foodcategory['main_cat']);
     //        $eat->main_category_id = $spot_category['main_cat'];
     //        $eat->sub_category_id = $spot_category['sub_cat'];
     //        $pic = $spot_data['category'];
     //        $eat->pic_url = $pic['prefix'] . '64' . $pic['suffix'];
     //
     ////        return response()->json($spot_category, 200);
     //        self::resolveSegmentFromActivity($token);
     //
     ////        return response()->json($eat);
     //        $eat->save();
     //        $eat->activity()->save($activity);
     //
     //
     //        $iterinary = Iterinary::findOrFail($current_iterinary->id)
     //            ->with('activities.typable')
     //            ->first();
     //        return response()->json($iterinary, 200);
     //        return response()->json($eat);
 }
 public function addSpotTest(Request $request)
 {
     $request = $request->all();
     $food_data = $request['spot'];
     $token = $request['token'];
     $transpo = $request['transpo'];
     $response = UserSessionHandler::resolveNewSegmentFromActivity($token, $transpo, $food_data);
     //        return response()->json($response);
     $current_iterinary = UserSessionHandler::getUserCurrentIterinary($token);
     $day = UserSessionHandler::getDiffInDays($token, $current_iterinary->id);
     $activity = new Activity();
     $activity->start_time = Carbon::now()->toTimeString();
     $activity->iterinary_id = $current_iterinary->id;
     $activity->day = $day;
     $eat = new Spot();
     $eat->place_name = $food_data['place_name'];
     $eat->lng = $food_data['lng'];
     $eat->lat = $food_data['lat'];
     $eat->tips = $food_data['review'];
     $eat->price = $food_data['price'];
     $foodcategory = Foursquare::resolveSpotCategory($food_data['category']['cat_id']);
     //        return response()->json($foodcategory['main_cat']);
     $eat->main_category_id = $foodcategory['main_cat'];
     $eat->sub_category_id = $foodcategory['sub_cat'];
     $pic = $food_data['category'];
     $eat->pic_url = $pic['prefix'] . '64' . $pic['suffix'];
     //        return response()->json($eat);
     $eat->save();
     $eat->activity()->save($activity);
     $iterinary = Iterinary::findOrFail($current_iterinary->id)->with('activities.typable')->first();
     return response()->json($iterinary, 200);
     //        return response()->json($eat);
 }