llp пре 4 дана
родитељ
комит
03689a6ca4

+ 5 - 16
packages/Longyi/Gift/src/Http/Controllers/Shop/GiftController.php

@@ -11,6 +11,7 @@ use Webkul\Shop\Http\Controllers\Controller;
 use Longyi\Gift\Repositories\GiftCardsRepository;
 use Longyi\Gift\Models\GiftCards;
 use Longyi\Gift\Http\Resources\CustomCartResource;
+use Longyi\RewardPoints\Helpers\ApiResponse;
 
 class GiftController extends Controller
 {
@@ -29,34 +30,22 @@ class GiftController extends Controller
     public function lists(): JsonResponse
     {
         $gifts = $this->giftCardsModel->giftcards();
-        return response()->json([
-            'success' => true,
-            'data' => $gifts,
-        ]);
+        return ApiResponse::success($gifts);
     }
 
     public function add($request): JsonResponse
     {
         $id = $request->input('id');
         if (!$id) {
-            return response()->json([
-                'success' => false,
-                'message' => 'Gift card not found',
-            ]);
+            return ApiResponse::error('Gift card not found');
         }
         $customerId = auth()->user()->id;
         try {
             $this->giftCardsModel->add($id, $customerId);
         } catch (\Exception $e) {
-            return response()->json([
-                'success' => false,
-                'message' => $e->getMessage(),
-            ]);
+            return ApiResponse::error($e->getMessage());
         }
-        return response()->json([
-            'success' => true,
-            'message' => 'Gift card added successfully',
-        ]);
+        return ApiResponse::success('Gift card added successfully');
     }
     /**
      * Get customer's gift cards list

+ 14 - 10
packages/Longyi/Gift/src/Routes/shop-routes.php

@@ -2,15 +2,19 @@
 
 use Illuminate\Support\Facades\Route;
 use Longyi\Gift\Http\Controllers\Shop\GiftController;
+use Longyi\RewardPoints\Http\Middleware\ApiCustomerAuthenticate;
 
-Route::group(['middleware' => ['web', 'theme', 'locale', 'currency'], 'prefix' => 'gift'], function () {
-    Route::get('/index', [GiftController::class, 'index'])->name('shop.gift.index');
-    Route::get('/lists', [GiftController::class, 'lists'])->name('shop.gift.lists');
-});
-Route::group(['middleware' => ['web', 'theme', 'locale', 'currency', 'customer'], 'prefix' => 'gift'], function () {
-    Route::get('/my-gift-cards', [GiftController::class, 'getCustomerGiftCards'])->name('shop.api.checkout.cart.giftcard.list');
-    Route::post('/activate', [GiftController::class, 'activateGiftCard'])->name('shop.api.checkout.cart.giftcard.activate');
-    Route::delete('/remove', [GiftController::class, 'destroyGiftCard'])->name('shop.api.checkout.cart.giftcard.remove');
-    Route::post('/auto-apply-expiring', [GiftController::class, 'autoApplyExpiringGiftCard'])->name('shop.api.checkout.cart.giftcard.auto-apply');
-    Route::post('/add', [GiftController::class, 'add'])->name('shop.gift.add');
+Route::group(['prefix' => 'api'], function () {
+    Route::group(['prefix' => 'gift'], function () {
+        Route::get('/index', [GiftController::class, 'index'])->name('shop.gift.index');
+        Route::get('/lists', [GiftController::class, 'lists'])->name('shop.gift.lists');
+    });
+    Route::group(['middleware' => ['api', ApiCustomerAuthenticate::class], 'prefix' => 'gift'], function () {
+        Route::post('/add', [GiftController::class, 'add'])->name('shop.gift.add');
+        Route::get('/my-gift-cards', [GiftController::class, 'getCustomerGiftCards'])->name('shop.api.checkout.cart.giftcard.list');
+        Route::post('/activate', [GiftController::class, 'activateGiftCard'])->name('shop.api.checkout.cart.giftcard.activate');
+        Route::delete('/remove', [GiftController::class, 'destroyGiftCard'])->name('shop.api.checkout.cart.giftcard.remove');
+        Route::post('/auto-apply-expiring', [GiftController::class, 'autoApplyExpiringGiftCard'])->name('shop.api.checkout.cart.giftcard.auto-apply');
+    });
 });
+