Esempio n. 1
0
 public function generalInformation(UserService $user, GoogleApiService $google, $user_id)
 {
     $retrieve = ['first_name', 'last_name', 'gender', 'birth_date', 'birth_month', 'birth_year', 'street_name', 'street_number', 'building_name', 'building_floor', 'building_room', 'city_town', 'province', 'region_state', 'zip_code', 'country', 'image_upload', 'status_message', 'description'];
     try {
         $input = Request::only($retrieve);
         $validation = $user->validateUpdateUser($input);
         if (!$validation->fails()) {
             $address = $input['street_name'] . ', ' . $input['city_town'] . ', ' . $input['zip_code'] . ', ' . $input['country'];
             $geocode = $google->geoCoding($address);
             if ($geocode['status'] !== 'OK') {
                 return $this->json_response->error(['validation_message' => $geocode['status']]);
             }
             $user_information = $user->getUserById($user_id);
             if ($user_information['lat'] != $geocode['lat'] || $user_information['lng'] != $geocode['lng']) {
                 $input['lat'] = $geocode['lat'];
                 $input['lng'] = $geocode['lng'];
             } else {
                 $input['lat'] = $user_information['lat'];
                 $input['lng'] = $user_information['lng'];
             }
             $response = $user->updateUser($user_id, $input);
             if (!empty($response)) {
                 return $this->json_response->success($response);
             }
             return $this->json_response->error($response);
         } else {
             return $this->json_response->error(['validation_message' => $validation->messages()]);
         }
     } catch (Exception $e) {
         return $this->json_response->error(['error' => $e->getMessage()]);
     }
 }