diff --git a/app/Http/Controllers/Admin/APIs/Customer_API/RestaurantControllerApi.php b/app/Http/Controllers/Admin/APIs/Customer_API/RestaurantControllerApi.php index fe59c4a..916f542 100644 --- a/app/Http/Controllers/Admin/APIs/Customer_API/RestaurantControllerApi.php +++ b/app/Http/Controllers/Admin/APIs/Customer_API/RestaurantControllerApi.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin\APIs\Customer_API; use App\Http\Controllers\Controller; use App\Services\APIs\CustomerAPIs\RestaurantApiServices; +use Illuminate\Support\Facades\Validator; use Illuminate\Http\Request; use Illuminate\Support\Facades\Log; @@ -38,4 +39,34 @@ class RestaurantControllerApi extends Controller return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500); } } + + /** + * Created By : Sayli Raut + * Created at : 28 May 2024 + * 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); + } + } } diff --git a/app/Models/ManageRestaurant.php b/app/Models/ManageRestaurant.php index 2f2a876..dc51ee6 100644 --- a/app/Models/ManageRestaurant.php +++ b/app/Models/ManageRestaurant.php @@ -4,6 +4,8 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\SoftDeletes; +use Illuminate\Support\Str; + use Illuminate\Database\Eloquent\Model; @@ -13,29 +15,28 @@ class ManageRestaurant extends Model use HasFactory; protected $table = 'manage_restaurants'; protected $fillable = [ - 'id', - 'name', - 'description', - 'restaurant_id', - 'address', - 'image', - 'bio', - 'try_on_1', - 'try_on_2', - 'try_on_3', - 'try_on_4', - 'exclusion', - 'latitude', - 'longtitude', - 'is_active', - 'created_by', - 'modified_by', - 'created_at', - 'updated_at' - + 'short_id', 'name', 'description', 'restaurant_id', 'address', 'image', 'bio', + 'try_on_1', 'try_on_2', 'try_on_3', 'try_on_4', 'exclusion', 'latitude', 'longitude', + 'is_active', 'created_by', 'modified_by' ]; - public function operatingHours() + + protected static function boot() { - return $this->hasMany(OperatingHour::class, 'manage_restaurant_xid'); + parent::boot(); + + static::creating(function ($model) { + if (empty($model->short_id)) { + $model->short_id = static::generateUniqueShortId(); + } + }); + } + + protected static function generateUniqueShortId() + { + do { + $shortId = Str::random(4); + } while (static::where('short_id', $shortId)->exists()); + + return $shortId; } } diff --git a/app/Services/APIs/CustomerAPIs/RestaurantApiServices.php b/app/Services/APIs/CustomerAPIs/RestaurantApiServices.php index 6b0df00..38af1d1 100644 --- a/app/Services/APIs/CustomerAPIs/RestaurantApiServices.php +++ b/app/Services/APIs/CustomerAPIs/RestaurantApiServices.php @@ -14,11 +14,11 @@ class RestaurantApiServices public function getCoordinates($customerIamId) { try { - $restaurant = ManageRestaurant:: - select( + $restaurant = ManageRestaurant::select( 'id', 'name', 'image', + 'short_id', 'latitude', 'longtitude' ) @@ -31,7 +31,20 @@ class RestaurantApiServices } return jsonResponseWithSuccessMessage(__('auth.data_fetched_successfully'), $restaurant, 200); + } catch (Exception $ex) { + Log::error('Restaurant Get service failed : ' . $ex->getMessage()); + return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500); + } + } + public function addToFavourite($customerIamId, $request) + { + try { + dd($request); + + + + return jsonResponseWithSuccessMessage(__('auth.data_fetched_successfully'), 200); } catch (Exception $ex) { Log::error('Restaurant Get service failed : ' . $ex->getMessage()); return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500); diff --git a/database/migrations/2024_05_28_095429_create_manage_restaurants_table.php b/database/migrations/2024_05_28_095429_create_manage_restaurants_table.php index 0dfa1ec..57a3573 100644 --- a/database/migrations/2024_05_28_095429_create_manage_restaurants_table.php +++ b/database/migrations/2024_05_28_095429_create_manage_restaurants_table.php @@ -14,6 +14,7 @@ return new class extends Migration Schema::create('manage_restaurants', function (Blueprint $table) { $table->id(); + $table->string('short_id')->unique(); $table->string('name',255)->nullable(); $table->longText('description')->nullable(); $table->string('restaurant_id')->nullable(); diff --git a/routes/customer_api.php b/routes/customer_api.php index 81da7e4..3977481 100644 --- a/routes/customer_api.php +++ b/routes/customer_api.php @@ -47,6 +47,7 @@ Route::post('/v1/delete_account', [CustomerControllerApi::class, 'destroyAccount //*******************************************************Restaurant******************************************************** Route::get('/v1/list-of-coordinates', [RestaurantControllerApi::class, 'getCoordinates']); +Route::post('/v1/add-to-favourite', [RestaurantControllerApi::class, 'addToFavourite']);