46 lines
1.8 KiB
PHP
46 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin\APIs\RestaurantApi;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\Request;
|
|
|
|
class RestNotificationController extends Controller
|
|
{
|
|
public function getRestNotificationApi(Request $request)
|
|
{
|
|
try {
|
|
|
|
$token = readRestHeaderToken();
|
|
|
|
if ($token) {
|
|
$customerIamId = $token['sub'];
|
|
$perPage = $request->query('per_page', 10); // Default to 10 items per page
|
|
$page = $request->query('page', 1); // Default to page 1
|
|
|
|
if ($customerIamId) {
|
|
$notificationsData = NotificationDetails::where('principal_xid', $customerIamId)->orderBy('id', 'Desc')->get();
|
|
|
|
// Calculate the total number of items and total pages
|
|
$totalItems = $notificationsData->count();
|
|
$totalPages = ceil($totalItems / $perPage);
|
|
|
|
// Slice the collection based on the current page and items per page
|
|
$offset = ($page - 1) * $perPage;
|
|
$currentPageItems = $notificationsData->slice($offset, $perPage);
|
|
|
|
if (!empty($notificationsData)) {
|
|
return jsonResponseWithSuccessMessage(__('success.data_fetched_successfully'), $notificationsData, 200);
|
|
}
|
|
}
|
|
} else {
|
|
return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500);
|
|
}
|
|
return jsonResponseWithSuccessMessage(__('success.data_fetched_successfully'), $notificationsData, 200);
|
|
} catch (\Exception $e) {
|
|
Log::error(' get Notification Controller function failed: ' . $e->getMessage());
|
|
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
|
|
}
|
|
}
|
|
}
|