@@ -170,4 +170,32 @@ class RestaurantControllerApi extends Controller
|
||||
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
27
app/Models/RedeemRestaurant.php
Normal file
27
app/Models/RedeemRestaurant.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class RedeemRestaurant extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
protected $table = 'redeem_restaurant';
|
||||
|
||||
protected $fillable = [
|
||||
'iam_principal_xid',
|
||||
'manage_restaurants_xid',
|
||||
'is_active',
|
||||
'is_redeem',
|
||||
'count',
|
||||
'redeem_date',
|
||||
'is_redeemption_undone',
|
||||
'redeemption_undone_date',
|
||||
'created_at',
|
||||
'updated_at'
|
||||
];
|
||||
|
||||
|
||||
}
|
||||
@@ -6,6 +6,7 @@ namespace App\Services\APIs\CustomerAPIs;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Models\CustomerFavouriteRestaurant;
|
||||
use App\Models\ManageRestaurant;
|
||||
use App\Models\RedeemRestaurant;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
@@ -136,9 +137,9 @@ class RestaurantApiServices
|
||||
$existingFavourite = CustomerFavouriteRestaurant::where('principal_xid', $customerIamId)
|
||||
->where('restaurant_xid', $restaurant->id)
|
||||
->first();
|
||||
if (!$existingFavourite) {
|
||||
return jsonResponseWithErrorMessage(__('auth.data_not_found'), 404);
|
||||
}
|
||||
if (!$existingFavourite) {
|
||||
return jsonResponseWithErrorMessage(__('auth.data_not_found'), 404);
|
||||
}
|
||||
if ($existingFavourite) {
|
||||
$existingFavourite->delete();
|
||||
}
|
||||
@@ -181,7 +182,6 @@ class RestaurantApiServices
|
||||
|
||||
|
||||
return jsonResponseWithSuccessMessageApi(__('auth.restaurant_search'), $restaurants, 200);
|
||||
|
||||
} catch (Exception $ex) {
|
||||
Log::error('Search from favourite restaurant service failed: ' . $ex->getMessage());
|
||||
return response()->json([
|
||||
@@ -190,4 +190,30 @@ class RestaurantApiServices
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function redeemRestaurant($customerIamId, $request)
|
||||
{
|
||||
try {
|
||||
$restaurantId = $request->id;
|
||||
|
||||
$restaurant = ManageRestaurant::with('operatingHours')->where('short_id', $restaurantId)->first();
|
||||
|
||||
if ($restaurant) {
|
||||
$redeemRestaurant = new RedeemRestaurant();
|
||||
$redeemRestaurant->iam_principal_xid = $customerIamId;
|
||||
$redeemRestaurant->manage_restaurants_xid = $restaurant->id;
|
||||
$redeemRestaurant->is_redeem = 1; // Redeem restaurant
|
||||
$redeemRestaurant->redeem_date = now();
|
||||
$redeemRestaurant->is_redeemption_undone = 0;
|
||||
$redeemRestaurant->redeemption_undone_date = null;
|
||||
$redeemRestaurant->save();
|
||||
} else {
|
||||
return jsonResponseWithErrorMessageApi(__('auth.restaurant_not_found'), 404);
|
||||
}
|
||||
return jsonResponseWithSuccessMessageApi(__('success.redeem_voucher'), $redeemRestaurant, 200);
|
||||
} catch (Exception $ex) {
|
||||
Log::error('Restaurant Reedem service failed: ' . $ex->getMessage());
|
||||
return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
<?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('redeem_restaurant', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('iam_principal_xid');
|
||||
$table->foreign('iam_principal_xid')->references('id')->on('iam_principal')->onDelete('cascade');
|
||||
$table->unsignedBigInteger('manage_restaurants_xid');
|
||||
$table->foreign('manage_restaurants_xid')->references('id')->on('manage_restaurants')->onDelete('cascade');
|
||||
$table->boolean('is_active')->default(1)->comment('1=Active, 0=Expired');
|
||||
$table->boolean('is_redeem')->default(0)->comment('1=Redeem, 0=Not Redeem');
|
||||
$table->integer('count')->default(0);
|
||||
$table->timestamp('redeem_date')->nullable();
|
||||
$table->boolean('is_redeemption_undone')->default(0);
|
||||
$table->timestamp('redeemption_undone_date')->nullable();
|
||||
$table->integer('created_by')->nullable();
|
||||
$table->integer('modified_by')->nullable();
|
||||
$table->softDeletes();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('redeem_restaurant');
|
||||
}
|
||||
};
|
||||
@@ -52,6 +52,7 @@ Route::middleware(['customerApiBasicAuth'])->group(function () {
|
||||
Route::get('/v1/list-of-coordinates', [RestaurantControllerApi::class, 'getCoordinates']);
|
||||
Route::post('/v1/remove-from-favourite', [RestaurantControllerApi::class, 'removeFromFavourite']);
|
||||
Route::post('/v1/search-from-favourite', [RestaurantControllerApi::class, 'searchFromFavourite']);
|
||||
Route::post('/v1/redeem-restaurant', [RestaurantControllerApi::class, 'redeemRestaurant']);
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user