feat: add notifications module with bell UI, event listeners, and cleanup job
In-app notification system with topbar bell icon, dropdown panel, mark-as-read/dismiss actions, and scheduled cleanup of old read notifications. Includes event listeners for user.created and user.deleted events, authorization policy, and full test coverage. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
34
modules/notifications/pages/notifications/list-data().php
Normal file
34
modules/notifications/pages/notifications/list-data().php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use MintyPHP\Http\SessionStoreInterface;
|
||||
use MintyPHP\Module\Notifications\Service\NotificationService;
|
||||
use MintyPHP\Router;
|
||||
use MintyPHP\Support\Guard;
|
||||
|
||||
Guard::requireLogin();
|
||||
|
||||
if (requestInput()->method() !== 'GET') {
|
||||
http_response_code(405);
|
||||
Router::json(['ok' => false, 'error' => 'method_not_allowed']);
|
||||
return;
|
||||
}
|
||||
|
||||
$session = app(SessionStoreInterface::class)->all();
|
||||
$userId = (int) ($session['user']['id'] ?? 0);
|
||||
if ($userId <= 0) {
|
||||
http_response_code(401);
|
||||
Router::json(['ok' => false, 'error' => 'unauthorized']);
|
||||
return;
|
||||
}
|
||||
|
||||
$service = app(NotificationService::class);
|
||||
$notifications = $service->listForUser($userId, 50);
|
||||
$unreadCount = $service->unreadCount($userId);
|
||||
|
||||
app(SessionStoreInterface::class)->set('module.notifications.unread_count', $unreadCount);
|
||||
|
||||
Router::json([
|
||||
'ok' => true,
|
||||
'notifications' => $notifications,
|
||||
'unread_count' => $unreadCount,
|
||||
]);
|
||||
Reference in New Issue
Block a user