|
@@ -67,32 +67,35 @@ class GiftController extends Controller
|
|
|
return ApiResponse::success('Gift card added successfully');
|
|
return ApiResponse::success('Gift card added successfully');
|
|
|
}
|
|
}
|
|
|
/**
|
|
/**
|
|
|
- * Get customer's gift cards list
|
|
|
|
|
|
|
+ * Get customer's gift cards list (with pagination)
|
|
|
*/
|
|
*/
|
|
|
- public function getCustomerGiftCards(): JsonResponse
|
|
|
|
|
|
|
+ public function getCustomerGiftCards(Request $request): JsonResponse
|
|
|
{
|
|
{
|
|
|
try {
|
|
try {
|
|
|
$customerId = auth()->user()->id;
|
|
$customerId = auth()->user()->id;
|
|
|
|
|
+ $perPage = (int) $request->input('per_page', 10);
|
|
|
|
|
|
|
|
- $giftCards = GiftCards::where('customer_id', $customerId)
|
|
|
|
|
|
|
+ $paginator = GiftCards::where('customer_id', $customerId)
|
|
|
->where('remaining_giftcard_amount', '>', 0)
|
|
->where('remaining_giftcard_amount', '>', 0)
|
|
|
->where('expirationdate', '>=', now())
|
|
->where('expirationdate', '>=', now())
|
|
|
->orderBy('created_at', 'desc')
|
|
->orderBy('created_at', 'desc')
|
|
|
- ->get();
|
|
|
|
|
- return ApiResponse::success(
|
|
|
|
|
- $giftCards->map(function ($giftCard) {
|
|
|
|
|
- return [
|
|
|
|
|
- 'id' => $giftCard->id,
|
|
|
|
|
- 'giftcard_number' => $giftCard->giftcard_number,
|
|
|
|
|
- 'giftcard_amount' => $giftCard->giftcard_amount,
|
|
|
|
|
- 'remaining_giftcard_amount' => $giftCard->remaining_giftcard_amount,
|
|
|
|
|
- 'formatted_remaining_giftcard_amount' => core()->formatPrice(core()->convertPrice($giftCard->remaining_giftcard_amount)),
|
|
|
|
|
- 'used_giftcard_amount' => $giftCard->used_giftcard_amount,
|
|
|
|
|
- 'expirationdate' => $giftCard->expirationdate->format('Y-m-d'),
|
|
|
|
|
- 'giftcard_status' => $giftCard->giftcard_status
|
|
|
|
|
- ];
|
|
|
|
|
- })
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ ->paginate($perPage);
|
|
|
|
|
+
|
|
|
|
|
+ $data = $paginator->map(function ($giftCard) {
|
|
|
|
|
+ return [
|
|
|
|
|
+ 'id' => $giftCard->id,
|
|
|
|
|
+ 'giftcard_number' => $giftCard->giftcard_number,
|
|
|
|
|
+ 'giftcard_amount' => $giftCard->giftcard_amount,
|
|
|
|
|
+ 'remaining_giftcard_amount' => $giftCard->remaining_giftcard_amount,
|
|
|
|
|
+ 'formatted_remaining_giftcard_amount' => core()->formatPrice(core()->convertPrice($giftCard->remaining_giftcard_amount)),
|
|
|
|
|
+ 'used_giftcard_amount' => $giftCard->used_giftcard_amount,
|
|
|
|
|
+ 'expirationdate' => $giftCard->expirationdate->format('Y-m-d'),
|
|
|
|
|
+ 'giftcard_status' => $giftCard->giftcard_status
|
|
|
|
|
+ ];
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ return ApiResponse::paginated($data, $paginator);
|
|
|
|
|
+
|
|
|
} catch (\Exception $e) {
|
|
} catch (\Exception $e) {
|
|
|
return ApiResponse::error($e->getMessage());
|
|
return ApiResponse::error($e->getMessage());
|
|
|
}
|
|
}
|