2024-05-28 18:52:27 +05:30
|
|
|
<?php
|
|
|
|
|
|
2024-06-30 21:11:10 +05:30
|
|
|
namespace App\Http\Controllers\APIs\Customer_API;
|
2024-05-28 18:52:27 +05:30
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use App\Services\APIs\CustomerAPIs\RestaurantApiServices;
|
2024-05-30 17:05:09 +05:30
|
|
|
use Illuminate\Support\Facades\Validator;
|
2024-05-28 18:52:27 +05:30
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
|
|
|
|
class RestaurantControllerApi extends Controller
|
|
|
|
|
{
|
|
|
|
|
protected $RestaurantApiServices;
|
|
|
|
|
|
|
|
|
|
public function __construct(RestaurantApiServices $RestaurantApiServices)
|
|
|
|
|
{
|
|
|
|
|
$this->RestaurantApiServices = $RestaurantApiServices;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-04 15:51:08 +05:30
|
|
|
/**
|
2024-05-28 18:52:27 +05:30
|
|
|
* Created By : Sayli Raut
|
2024-05-31 12:35:52 +05:30
|
|
|
* Created at : 30 May 2024
|
2024-05-28 18:52:27 +05:30
|
|
|
* Use : To get restaurant.
|
|
|
|
|
*/
|
2024-05-30 15:56:56 +05:30
|
|
|
public function getCoordinates()
|
2024-05-28 18:52:27 +05:30
|
|
|
{
|
|
|
|
|
try {
|
2024-05-31 17:25:56 +05:30
|
|
|
$token = readHeaderToken();
|
2024-05-28 18:52:27 +05:30
|
|
|
|
2024-05-31 17:25:56 +05:30
|
|
|
if ($token) {
|
|
|
|
|
$customerIamId = $token['sub'];
|
|
|
|
|
$response = $this->RestaurantApiServices->getCoordinates($customerIamId);
|
2024-05-28 18:52:27 +05:30
|
|
|
return $response;
|
2024-05-31 17:25:56 +05:30
|
|
|
} else {
|
|
|
|
|
return jsonResponseWithErrorMessageApi(__('auth.user_deleted'), 409);
|
|
|
|
|
}
|
2024-05-28 18:52:27 +05:30
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
Log::error('Passport function failed: ' . $e->getMessage());
|
|
|
|
|
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-30 17:05:09 +05:30
|
|
|
|
2024-06-04 15:51:08 +05:30
|
|
|
/**
|
2024-05-30 17:05:09 +05:30
|
|
|
* Created By : Sayli Raut
|
2024-05-31 12:35:52 +05:30
|
|
|
* Created at : 30 May 2024
|
2024-05-30 17:05:09 +05:30
|
|
|
* Use : To add favourite.
|
|
|
|
|
*/
|
|
|
|
|
public function addToFavourite(Request $request)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$token = readHeaderToken();
|
|
|
|
|
|
|
|
|
|
if ($token) {
|
|
|
|
|
$customerIamId = $token['sub'];
|
|
|
|
|
$validator = Validator::make($request->all(), [
|
|
|
|
|
'id' => 'required',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
if ($validator->fails()) {
|
|
|
|
|
return jsonResponseWithErrorMessageApi($validator->errors()->first(), 400);
|
|
|
|
|
}
|
|
|
|
|
$response = $this->RestaurantApiServices->addToFavourite($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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-30 19:42:40 +05:30
|
|
|
|
2024-06-04 15:51:08 +05:30
|
|
|
/**
|
2024-05-30 19:42:40 +05:30
|
|
|
* Created By : Sayli Raut
|
2024-05-31 12:35:52 +05:30
|
|
|
* Created at : 30 May 2024
|
2024-05-30 19:42:40 +05:30
|
|
|
* Use : To list of fav restaurant.
|
|
|
|
|
*/
|
|
|
|
|
public function listFavRestaurant()
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$token = readHeaderToken();
|
|
|
|
|
|
|
|
|
|
if ($token) {
|
|
|
|
|
$customerIamId = $token['sub'];
|
|
|
|
|
$response = $this->RestaurantApiServices->listFavRestaurant($customerIamId);
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-31 12:35:52 +05:30
|
|
|
|
2024-06-04 15:51:08 +05:30
|
|
|
/**
|
2024-05-31 12:35:52 +05:30
|
|
|
* Created By : Sayli Raut
|
|
|
|
|
* Created at : 31 May 2024
|
2024-05-31 16:28:50 +05:30
|
|
|
* Use : To detail of specific restaurant.
|
2024-05-31 12:35:52 +05:30
|
|
|
*/
|
2024-05-31 16:28:50 +05:30
|
|
|
public function DetailRestaurant($id)
|
2024-05-31 12:35:52 +05:30
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$token = readHeaderToken();
|
|
|
|
|
|
|
|
|
|
if ($token) {
|
|
|
|
|
$customerIamId = $token['sub'];
|
2024-05-31 16:28:50 +05:30
|
|
|
$response = $this->RestaurantApiServices->DetailRestaurant($customerIamId, $id);
|
2024-05-31 12:35:52 +05:30
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-31 16:28:50 +05:30
|
|
|
|
2024-06-04 15:51:08 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Created By : Sayli Raut
|
|
|
|
|
* Created at : 04 June 2024
|
|
|
|
|
* Use : To remove from favourite.
|
|
|
|
|
*/
|
|
|
|
|
public function removeFromFavourite(Request $request)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$token = readHeaderToken();
|
|
|
|
|
|
|
|
|
|
if ($token) {
|
|
|
|
|
$customerIamId = $token['sub'];
|
|
|
|
|
$validator = Validator::make($request->all(), [
|
|
|
|
|
'id' => 'required',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
if ($validator->fails()) {
|
|
|
|
|
return jsonResponseWithErrorMessageApi($validator->errors()->first(), 400);
|
|
|
|
|
}
|
|
|
|
|
$response = $this->RestaurantApiServices->removeFromFavourite($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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-04 16:50:19 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Created By : Sayli Raut
|
|
|
|
|
* Created at : 04 June 2024
|
|
|
|
|
* Use : To search from favourite.
|
|
|
|
|
*/
|
|
|
|
|
public function searchFromFavourite(Request $request)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$token = readHeaderToken();
|
|
|
|
|
if ($token) {
|
|
|
|
|
$customerIamId = $token['sub'];
|
|
|
|
|
return $this->RestaurantApiServices->searchFromFavourite($customerIamId, $request);
|
|
|
|
|
} else {
|
|
|
|
|
return jsonResponseWithErrorMessageApi(__('auth.user_deleted'), 409);
|
|
|
|
|
}
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
Log::error("An error occurred in " . __METHOD__ . ": " . $e->getMessage(), ['exception' => $e]);
|
|
|
|
|
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-04 19:33:03 +05:30
|
|
|
|
2024-06-20 13:05:03 +05:30
|
|
|
/**
|
2024-06-04 19:33:03 +05:30
|
|
|
* Created By : Sayli Raut
|
|
|
|
|
* Created at : 04 June 2024
|
|
|
|
|
* Use : To redeem restaurant.
|
|
|
|
|
*/
|
|
|
|
|
public function redeemRestaurant(Request $request)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$token = readHeaderToken();
|
|
|
|
|
if ($token) {
|
|
|
|
|
$customerIamId = $token['sub'];
|
|
|
|
|
$validator = Validator::make($request->all(), [
|
|
|
|
|
'id' => 'required',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
if ($validator->fails()) {
|
|
|
|
|
return jsonResponseWithErrorMessageApi($validator->errors()->first(), 400);
|
|
|
|
|
}
|
|
|
|
|
return $this->RestaurantApiServices->redeemRestaurant($customerIamId, $request);
|
|
|
|
|
} else {
|
|
|
|
|
return jsonResponseWithErrorMessageApi(__('auth.user_deleted'), 409);
|
|
|
|
|
}
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
Log::error('Passport function failed: ' . $e->getMessage());
|
|
|
|
|
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-20 13:05:03 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Created By : Sayli Raut
|
|
|
|
|
* Created at : 20 June 2024
|
|
|
|
|
* Use : To search from restaurant.
|
|
|
|
|
*/
|
|
|
|
|
public function searchRestaurant(Request $request)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$token = readHeaderToken();
|
|
|
|
|
if ($token) {
|
|
|
|
|
$customerIamId = $token['sub'];
|
|
|
|
|
return $this->RestaurantApiServices->searchRestaurant($customerIamId, $request);
|
|
|
|
|
} else {
|
|
|
|
|
return jsonResponseWithErrorMessageApi(__('auth.user_deleted'), 409);
|
|
|
|
|
}
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
Log::error("An error occurred in " . __METHOD__ . ": " . $e->getMessage(), ['exception' => $e]);
|
|
|
|
|
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-28 18:52:27 +05:30
|
|
|
}
|