Files
breadcrumb-the-shire/modules/notifications/pages/notifications/mark-read-data().php
fs fb6e30a062 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>
2026-03-19 22:09:44 +01:00

49 lines
1.2 KiB
PHP

<?php
use MintyPHP\Http\SessionStoreInterface;
use MintyPHP\Module\Notifications\Service\NotificationService;
use MintyPHP\Router;
use MintyPHP\Session;
use MintyPHP\Support\Guard;
Guard::requireLogin();
if (requestInput()->method() !== 'POST') {
http_response_code(405);
Router::json(['ok' => false, 'error' => 'method_not_allowed']);
return;
}
if (!Session::checkCsrfToken()) {
http_response_code(403);
Router::json(['ok' => false, 'error' => 'csrf']);
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);
$all = requestInput()->body('all');
$id = (int) requestInput()->body('id');
if ($all) {
$service->markAllAsRead($userId);
} elseif ($id > 0) {
$service->markAsRead($userId, $id);
} else {
http_response_code(400);
Router::json(['ok' => false, 'error' => 'invalid_request']);
return;
}
$unreadCount = $service->unreadCount($userId);
app(SessionStoreInterface::class)->set('module.notifications.unread_count', $unreadCount);
Router::json(['ok' => true, 'unread_count' => $unreadCount]);