This commit is contained in:
sayliraut
2024-05-30 17:05:09 +05:30
parent 7dfd6088a3
commit dff7e97057
5 changed files with 71 additions and 24 deletions

View File

@@ -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);
}
}
}

View File

@@ -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;
}
}

View File

@@ -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);

View File

@@ -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();

View File

@@ -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']);