feat(api): expose notification endpoints for customer dashboard
Implement backend support for the user notification system by adding endpoints to retrieve and manage notifications. - Add `notifications` and `markNotificationRead` methods to `CustomerOrderController` - Register notification routes under the `v1` API prefix - Update `IFNEX_User_Bridge` in WordPress to support fetching notifications and marking them as read via API calls
This commit is contained in:
parent
fc1c2f023d
commit
98181abc45
@ -308,7 +308,7 @@ class IFNEX_User_Bridge {
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* لغو سفارش
|
||||
*/
|
||||
public function cancel_customer_order($user_id, $shipment_id) {
|
||||
@ -320,7 +320,6 @@ class IFNEX_User_Bridge {
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* دریافت نوتیفیکیشنهای کاربر
|
||||
@ -344,6 +343,7 @@ class IFNEX_User_Bridge {
|
||||
$result = $this->authenticated_request($user_id, "/customer/notifications/{$notification_id}/read", 'POST');
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
// ══════════════════════════════════════════════════════════════
|
||||
// AJAX Handler برای لغو سفارش
|
||||
|
||||
@ -464,6 +464,62 @@ class CustomerOrderController extends Controller
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* نوتیفیکیشنهای کاربر
|
||||
* GET /api/v1/customer/notifications
|
||||
*/
|
||||
public function notifications(Request $request): JsonResponse
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
$notifications = $user->notifications()
|
||||
->orderBy('created_at', 'desc')
|
||||
->paginate($request->per_page ?? 20);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => collect($notifications->items())->map(function ($notification) {
|
||||
$data = $notification->data;
|
||||
return [
|
||||
'id' => $notification->id,
|
||||
'type' => $notification->type,
|
||||
'title' => $data['title'] ?? 'اعلان',
|
||||
'body' => $data['message'] ?? '',
|
||||
'data' => $data,
|
||||
'read_at' => $notification->read_at?->toIso8601String(),
|
||||
'created_at' => $notification->created_at->toIso8601String(),
|
||||
'created_at_jalali' => $this->toJalali($notification->created_at),
|
||||
];
|
||||
}),
|
||||
'unread_count' => $user->unreadNotifications()->count(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* خواندن نوتیفیکیشن
|
||||
* POST /api/v1/customer/notifications/{notification}/read
|
||||
*/
|
||||
public function markNotificationRead(Request $request, $notification): JsonResponse
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
$notif = $user->notifications()->where('id', $notification)->first();
|
||||
|
||||
if (!$notif) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'نوتیفیکیشن یافت نشد.',
|
||||
], 404);
|
||||
}
|
||||
|
||||
$notif->markAsRead();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'خوانده شد.',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* تولید شماره AWB
|
||||
*/
|
||||
|
||||
@ -65,6 +65,11 @@ Route::middleware(['auth:sanctum'])->prefix('v1')->group(function () {
|
||||
Route::get('/orders/{shipment}', [CustomerOrderController::class, 'show']);
|
||||
Route::post('/orders/{shipment}/cancel', [CustomerOrderController::class, 'cancel']);
|
||||
|
||||
|
||||
// نوتیفیکیشنها
|
||||
Route::get('/notifications', [CustomerOrderController::class, 'notifications']);
|
||||
Route::post('/notifications/{notification}/read', [CustomerOrderController::class, 'markNotificationRead']);
|
||||
|
||||
|
||||
// پرداخت سفارش
|
||||
Route::post('/orders/{shipment}/pay-wallet', [CustomerOrderController::class, 'payFromWallet']);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user