Merge pull request #56 from WDI-Ideas/sayli

Sayli
This commit is contained in:
Sayli Raut
2024-05-31 17:26:41 +05:30
committed by GitHub
3 changed files with 20 additions and 72 deletions

View File

@@ -25,15 +25,15 @@ class RestaurantControllerApi extends Controller
public function getCoordinates()
{
try {
// $token = readHeaderToken();
$token = readHeaderToken();
// if ($token) {
// $customerIamId = $token['sub'];
$response = $this->RestaurantApiServices->getCoordinates();
if ($token) {
$customerIamId = $token['sub'];
$response = $this->RestaurantApiServices->getCoordinates($customerIamId);
return $response;
// } else {
// return jsonResponseWithErrorMessageApi(__('auth.user_deleted'), 409);
// }
} else {
return jsonResponseWithErrorMessageApi(__('auth.user_deleted'), 409);
}
} catch (\Exception $e) {
Log::error('Passport function failed: ' . $e->getMessage());
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
@@ -116,34 +116,4 @@ class RestaurantControllerApi extends Controller
}
}
/**
* Created By : Sayli Raut
* Created at : 31 May 2024
* Use : To list of fav restaurant.
*/
// public function DetailRestaurant(Request $request)
// {
// try {
// $token = readHeaderToken();
// if ($token) {
// $customerIamId = $token['sub'];
// $validator = Validator::make($request->all(), [
// 'ids' => 'required',
// ]);
// if ($validator->fails()) {
// return jsonResponseWithErrorMessageApi($validator->errors()->first(), 400);
// }
// $response = $this->RestaurantApiServices->DetailRestaurant($customerIamId, $request);
// return $response;
// } else {
// return jsonResponseWithErrorMessageApi(__('auth.user_deleted'), 409);
// }
// } catch (\Exception $e) {
// Log::error('Passport function failed: ' . $e->getMessage());
// return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
// }
// }
}

View File

@@ -13,10 +13,10 @@ use Illuminate\Support\Facades\Log;
class RestaurantApiServices
{
public function getCoordinates()
public function getCoordinates($customerIamId)
{
try {
$restaurant = ManageRestaurant::with('operatingHours')->select(
$restaurants = ManageRestaurant::with('operatingHours')->select(
'id',
'name',
'image',
@@ -29,11 +29,16 @@ class RestaurantApiServices
->get()
->toArray();
foreach ($restaurant as &$res) {
$res['image'] = ListingImageUrl('restaurant_images', $res['image']);
foreach ($restaurants as &$restaurant) {
$restaurant['image'] = ListingImageUrl('restaurant_images', $restaurant['image']);
$isFavourite = CustomerFavouriteRestaurant::where('principal_xid', $customerIamId)
->where('restaurant_xid', $restaurant['id'])
->exists();
$restaurant['is_favourite'] = $isFavourite;
}
return jsonResponseWithSuccessMessage(__('auth.data_fetched_successfully'), $restaurant, 200);
return jsonResponseWithSuccessMessage(__('auth.data_fetched_successfully'), $restaurants, 200);
} catch (Exception $ex) {
Log::error('Restaurant Get service failed : ' . $ex->getMessage());
return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500);
@@ -97,32 +102,6 @@ class RestaurantApiServices
}
// public function DetailRestaurant($customerIamId, $request)
// {
// try {
// $rawIds = $request->input('ids');
// Log::info('Raw ids: ' . $rawIds);
// $ids = json_decode($rawIds, true);
// if (json_last_error() !== JSON_ERROR_NONE) {
// $rawIds = trim($rawIds, '[]');
// $ids = array_map('trim', explode(',', $rawIds));
// }
// $restaurants = ManageRestaurant::with('operatingHours')->whereIn('short_id', $ids)->get();
// foreach ($restaurants as &$res) {
// $res['image'] = ListingImageUrl('restaurant_images', $res['image']);
// }
// return jsonResponseWithSuccessMessage(__('auth.data_fetched_successfully'), $restaurants, 200);
// } catch (\Exception $ex) {
// Log::error('DetailRestaurant service failed: ' . $ex->getMessage());
// return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500);
// }
// }
public function DetailRestaurant($customerIamId, $id)
{
try {
@@ -130,8 +109,8 @@ class RestaurantApiServices
if ($rest) {
$rest->image = ListingImageUrl('restaurant_images', $rest->image);
$isFavourite = CustomerFavouriteRestaurant::where('principal_xid', $customerIamId)
->where('restaurant_xid', $rest->id)
->exists();
->where('restaurant_xid', $rest->id)
->exists();
$rest->is_favourite = $isFavourite;
}
if (!$rest) {

View File

@@ -9,7 +9,6 @@ use App\Http\Controllers\Admin\APIs\Customer_API\RestaurantControllerApi;
use Illuminate\Support\Facades\Route;
Route::get('/v1/list-of-coordinates', [RestaurantControllerApi::class, 'getCoordinates']);
Route::middleware(['customerApiBasicAuth'])->group(function () {
@@ -50,7 +49,7 @@ Route::middleware(['customerApiBasicAuth'])->group(function () {
Route::get('/v1/detail-of-restaurant/{id}', [RestaurantControllerApi::class, 'DetailRestaurant']);
Route::post('/v1/add-to-favourite', [RestaurantControllerApi::class, 'addToFavourite']);
Route::get('/v1/list-of-fav-restaurant', [RestaurantControllerApi::class, 'listFavRestaurant']);
// Route::post('/v1/detail-of-restaurant', [RestaurantControllerApi::class, 'DetailRestaurant']);
Route::get('/v1/list-of-coordinates', [RestaurantControllerApi::class, 'getCoordinates']);
//*******************************************************notification********************************************************