@@ -69,4 +69,27 @@ class RestaurantControllerApi extends Controller
|
||||
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Created By : Sayli Raut
|
||||
* Created at : 28 May 2024
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
22
app/Models/CustomerFavouriteRestaurant.php
Normal file
22
app/Models/CustomerFavouriteRestaurant.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CustomerFavouriteRestaurant extends Model
|
||||
{
|
||||
protected $table = 'customer_favourite_restaurants';
|
||||
|
||||
use HasFactory;
|
||||
|
||||
|
||||
protected $fillable = [
|
||||
'principal_xid',
|
||||
'restaurant_xid',
|
||||
'created_by',
|
||||
'modified_by',
|
||||
'deleted_at',
|
||||
];
|
||||
}
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
namespace App\Services\APIs\CustomerAPIs;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Models\CustomerFavouriteRestaurant;
|
||||
use App\Models\ManageRestaurant;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
@@ -15,13 +17,13 @@ class RestaurantApiServices
|
||||
{
|
||||
try {
|
||||
$restaurant = ManageRestaurant::select(
|
||||
'id',
|
||||
'name',
|
||||
'image',
|
||||
'short_id',
|
||||
'latitude',
|
||||
'longtitude'
|
||||
)
|
||||
'id',
|
||||
'name',
|
||||
'image',
|
||||
'short_id',
|
||||
'latitude',
|
||||
'longtitude'
|
||||
)
|
||||
->where('is_active', '1')
|
||||
->get()
|
||||
->toArray();
|
||||
@@ -40,13 +42,45 @@ class RestaurantApiServices
|
||||
public function addToFavourite($customerIamId, $request)
|
||||
{
|
||||
try {
|
||||
dd($request);
|
||||
DB::beginTransaction();
|
||||
|
||||
$restaurant = ManageRestaurant::where('short_id', $request->id)->first();
|
||||
if (!$restaurant) {
|
||||
return jsonResponseWithErrorMessage(__('auth.restaurant_data_not_found'), 404);
|
||||
}
|
||||
$favRestaurant = new CustomerFavouriteRestaurant();
|
||||
$favRestaurant->principal_xid = $customerIamId;
|
||||
$favRestaurant->restaurant_xid = $restaurant->id;
|
||||
$favRestaurant->save();
|
||||
DB::commit();
|
||||
Log::info("details" . $favRestaurant);
|
||||
|
||||
|
||||
return jsonResponseWithSuccessMessage(__('auth.data_fetched_successfully'), 200);
|
||||
return jsonResponseWithSuccessMessage(__('auth.data_updated_successfully'), 200);
|
||||
} catch (Exception $ex) {
|
||||
Log::error('Restaurant Get service failed : ' . $ex->getMessage());
|
||||
DB::rollBack();
|
||||
Log::error('Favourite Restaurant service failed : ' . $ex->getMessage());
|
||||
return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function listFavRestaurant($customerIamId)
|
||||
{
|
||||
try {
|
||||
$list = CustomerFavouriteRestaurant::where('principal_xid', $customerIamId)->get()->toArray();
|
||||
$customerFavouriteRestaurants = CustomerFavouriteRestaurant::where('principal_xid', $customerIamId)
|
||||
->pluck('restaurant_xid')
|
||||
->toArray();
|
||||
|
||||
$restaurants = ManageRestaurant::whereIn('id', $customerFavouriteRestaurants)->get();
|
||||
|
||||
foreach ($restaurants as &$res) {
|
||||
$res['image'] = ListingImageUrl('restaurant_images', $res['image']);
|
||||
}
|
||||
|
||||
return jsonResponseWithSuccessMessage(__('auth.data_updated_successfully'), $restaurants ,200);
|
||||
} catch (Exception $ex) {
|
||||
Log::error('List of Favourite Restaurant service failed : ' . $ex->getMessage());
|
||||
return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('customer_favourite_restaurants', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('principal_xid');
|
||||
$table->foreign('principal_xid')->references('id')->on('iam_principal')->onDelete('cascade');
|
||||
$table->unsignedBigInteger('restaurant_xid');
|
||||
$table->foreign('restaurant_xid')->references('id')->on('manage_restaurants')->onDelete('cascade');
|
||||
$table->integer('created_by')->nullable();
|
||||
$table->integer('modified_by')->nullable();
|
||||
$table->softDeletes();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('customer_favourite_restaurants');
|
||||
}
|
||||
};
|
||||
@@ -48,9 +48,7 @@ Route::post('/v1/delete_account', [CustomerControllerApi::class, 'destroyAccount
|
||||
|
||||
Route::get('/v1/list-of-coordinates', [RestaurantControllerApi::class, 'getCoordinates']);
|
||||
Route::post('/v1/add-to-favourite', [RestaurantControllerApi::class, 'addToFavourite']);
|
||||
|
||||
|
||||
Route::get('/v1/list-of-fav-restaurant', [RestaurantControllerApi::class, 'listFavRestaurant']);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user