Merge pull request #432 from WDI-Ideas/HritikCheers

Hritik cheers
This commit is contained in:
Hritikkk9
2024-08-07 11:46:05 +05:30
committed by GitHub

View File

@@ -54,8 +54,12 @@ class RestaurantApiServices
$restaurant['is_favourite'] = $isFavourite;
$cacheKey = 'restaurant_hours_' . $restaurant['name'];
$cacheKeyIsRestaurantOpen = 'is_restaurant_open_now_' . $restaurant['name'];
if (Cache::has($cacheKey)) {
$restaurant['operating_hours'] = Cache::get($cacheKey);
$restaurant['is_restaurant_open_now_as_per_google'] = Cache::get($cacheKeyIsRestaurantOpen);
} else {
// Prepare the first request to get the place_id
$promises[$restaurant['name']] = $client->getAsync('https://maps.googleapis.com/maps/api/place/findplacefromtext/json', [
@@ -85,12 +89,14 @@ class RestaurantApiServices
$detailPromises[$restaurant['name']] = $client->getAsync('https://maps.googleapis.com/maps/api/place/details/json', [
'query' => [
'fields' => 'opening_hours',
'open_now',
'place_id' => $placeId,
'key' => $googlePlaceApiKey
]
]);
} else {
$restaurant['operating_hours'] = "N/A";
$restaurant['is_restaurant_open_now_as_per_google'] = false;
}
}
}
@@ -102,12 +108,19 @@ class RestaurantApiServices
if (isset($detailResults[$restaurant['name']]['value'])) {
$response = $detailResults[$restaurant['name']]['value'];
$data = json_decode($response->getBody(), true);
if (isset($data['result']['opening_hours']['weekday_text'])) {
if (isset($data['result']['opening_hours']['weekday_text']) && isset($data['result']['opening_hours']['open_now'])) {
$hours = $data['result']['opening_hours']['weekday_text'];
Cache::put('restaurant_hours_' . $restaurant['name'], $hours, now()->addHours(24));
$isOpenNow = $data['result']['opening_hours']['open_now'];
Cache::put('restaurant_hours_' . $restaurant['name'], $hours, now()->addHours(2));
Cache::put('is_restaurant_open_now_' . $restaurant['name'], $isOpenNow, now()->addHours(2));
$restaurant['operating_hours'] = $hours;
$restaurant['is_restaurant_open_now_as_per_google'] = $isOpenNow;
} else {
$restaurant['operating_hours'] = "N/A";
$restaurant['is_restaurant_open_now_as_per_google'] = false;
}
}
@@ -227,8 +240,10 @@ class RestaurantApiServices
$res['image'] = ListingImageUrl('restaurant_images', $res['image']);
$cacheKey = 'restaurant_hours_' . $res->name;
$cacheKeyIsRestaurantOpen = 'is_restaurant_open_now_' . $res->name;
if (Cache::has($cacheKey)) {
$res['operating_hours'] = Cache::get($cacheKey);
$res['is_restaurant_open_now_as_per_google'] = Cache::get($cacheKeyIsRestaurantOpen);
} else {
// Prepare the first request to get the place_id
$promises[$res->name] = $client->getAsync('https://maps.googleapis.com/maps/api/place/findplacefromtext/json', [
@@ -264,6 +279,7 @@ class RestaurantApiServices
]);
} else {
$res['operating_hours'] = "N/A";
$res['is_restaurant_open_now_as_per_google'] = false;
}
}
}
@@ -277,10 +293,18 @@ class RestaurantApiServices
$data = json_decode($response->getBody(), true);
if (isset($data['result']['opening_hours']['weekday_text'])) {
$hours = $data['result']['opening_hours']['weekday_text'];
Cache::put('restaurant_hours_' . $res->name, $hours, now()->addHours(24));
$isOpenNow = $data['result']['opening_hours']['open_now'];
Cache::put('restaurant_hours_' . $res->name, $hours, now()->addHours(2));
Cache::put('is_restaurant_open_now_' . $res->name, $isOpenNow, now()->addHours(2));
$res['operating_hours'] = $hours;
$res['is_restaurant_open_now_as_per_google'] = $isOpenNow;
} else {
$res['operating_hours'] = "N/A";
$res['is_restaurant_open_now_as_per_google'] = false;
}
}
}
@@ -325,8 +349,11 @@ class RestaurantApiServices
// Cache key for operating hours
$cacheKey = 'restaurant_hours_' . $rest->name;
$cacheKeyIsRestaurantOpen = 'is_restaurant_open_now_' . $rest->name;
if (Cache::has($cacheKey)) {
$rest->operating_hours = Cache::get($cacheKey);
$rest->is_restaurant_open_now_as_per_google = Cache::get($cacheKeyIsRestaurantOpen);
} else {
// Prepare the first request to get the place_id
$placeResponse = $client->get('https://maps.googleapis.com/maps/api/place/findplacefromtext/json', [
@@ -354,13 +381,22 @@ class RestaurantApiServices
if (isset($detailData['result']['opening_hours']['weekday_text'])) {
$hours = $detailData['result']['opening_hours']['weekday_text'];
Cache::put($cacheKey, $hours, now()->addHours(24));
$isOpenNow = $detailData['result']['opening_hours']['open_now'];
Cache::put($cacheKey, $hours, now()->addHours(2));
Cache::put($cacheKeyIsRestaurantOpen, $isOpenNow, now()->addHours(2));
$rest->operating_hours = $hours;
$rest->is_restaurant_open_now_as_per_google = $isOpenNow;
} else {
$rest->operating_hours = "N/A";
$rest->is_restaurant_open_now_as_per_google = false;
}
} else {
$rest->operating_hours = "N/A";
$rest->is_restaurant_open_now_as_per_google = false;
}
}
@@ -497,8 +533,12 @@ class RestaurantApiServices
$res['image'] = ListingImageUrl('restaurant_images', $res['image']);
$cacheKey = 'restaurant_hours_' . $res->name;
$cacheKeyIsRestaurantOpen = 'is_restaurant_open_now_' . $res->name;
if (Cache::has($cacheKey)) {
$res['operating_hours'] = Cache::get($cacheKey);
$res['is_restaurant_open_now_as_per_google'] = Cache::get($cacheKeyIsRestaurantOpen);
} else {
// Prepare the first request to get the place_id
$promises[$res->name] = $client->getAsync('https://maps.googleapis.com/maps/api/place/findplacefromtext/json', [
@@ -534,6 +574,8 @@ class RestaurantApiServices
]);
} else {
$res['operating_hours'] = "N/A";
$res['is_restaurant_open_now_as_per_google'] = false;
}
}
}
@@ -547,10 +589,17 @@ class RestaurantApiServices
$data = json_decode($response->getBody(), true);
if (isset($data['result']['opening_hours']['weekday_text'])) {
$hours = $data['result']['opening_hours']['weekday_text'];
Cache::put('restaurant_hours_' . $res->name, $hours, now()->addHours(24));
$isOpenNow = $data['result']['opening_hours']['open_now'];
Cache::put('restaurant_hours_' . $res->name, $hours, now()->addHours(2));
Cache::put('is_restaurant_open_now_' . $res->name, $isOpenNow, now()->addHours(2));
$res['operating_hours'] = $hours;
$res['is_restaurant_open_now_as_per_google'] = $isOpenNow;
} else {
$res['operating_hours'] = "N/A";
$res['is_restaurant_open_now_as_per_google'] = false;
}
}
}
@@ -640,21 +689,9 @@ class RestaurantApiServices
$lastRedeemTime = Carbon::parse($lastRedeem->redeem_date);
$currentTime = Carbon::now();
Log::info("stateTimeHours");
Log::info("restTimeHours");
Log::info($stateTimeHours);
Log::info($restTimeHours);
$stateAllowedRedeemTime = $lastRedeemTime->copy()->addHours(intval($stateTimeHours));
$restAllowedRedeemTime = $lastRedeemTime->copy()->addHours(intval($restTimeHours));
Log::info("stateAllowedRedeemTime");
Log::info("restAllowedRedeemTime");
Log::info($stateAllowedRedeemTime);
Log::info($restAllowedRedeemTime);
if ($currentTime < $stateAllowedRedeemTime) {
$remainingTime = $currentTime->diff($stateAllowedRedeemTime);
$hours = $remainingTime->h;
@@ -795,8 +832,12 @@ class RestaurantApiServices
$restaurant['is_favourite'] = $isFavourite;
$cacheKey = 'restaurant_hours_' . $restaurant['name'];
$cacheKeyIsRestaurantOpen = 'is_restaurant_open_now_' . $restaurant['name'];
if (Cache::has($cacheKey)) {
$restaurant['operating_hours'] = Cache::get($cacheKey);
$restaurant['is_restaurant_open_now_as_per_google'] = Cache::get($cacheKeyIsRestaurantOpen);
} else {
// Prepare the first request to get the place_id
$promises[$restaurant['name']] = $client->getAsync('https://maps.googleapis.com/maps/api/place/findplacefromtext/json', [
@@ -832,6 +873,9 @@ class RestaurantApiServices
]);
} else {
$restaurant['operating_hours'] = "N/A";
$restaurant['is_restaurant_open_now_as_per_google'] = false;
}
}
}
@@ -845,10 +889,18 @@ class RestaurantApiServices
$data = json_decode($response->getBody(), true);
if (isset($data['result']['opening_hours']['weekday_text'])) {
$hours = $data['result']['opening_hours']['weekday_text'];
Cache::put('restaurant_hours_' . $restaurant['name'], $hours, now()->addHours(24));
$isOpenNow = $data['result']['opening_hours']['open_now'];
Cache::put('restaurant_hours_' . $restaurant['name'], $hours, now()->addHours(2));
Cache::put('is_restaurant_open_now_' . $restaurant['name'], $isOpenNow, now()->addHours(2));
$restaurant['operating_hours'] = $hours;
$restaurant['is_restaurant_open_now_as_per_google'] = $isOpenNow;
} else {
$restaurant['operating_hours'] = "N/A";
$restaurant['is_restaurant_open_now_as_per_google'] = false;
}
}
}