45 lines
1.2 KiB
PHP
45 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Controllers;
|
|
|
|
use App\Core\Auth;
|
|
use App\Services\NotificationService;
|
|
|
|
class NotificationController
|
|
{
|
|
public function list(): void
|
|
{
|
|
if (!Auth::check()) {
|
|
http_response_code(403);
|
|
echo 'Unauthorized';
|
|
return;
|
|
}
|
|
|
|
$service = new NotificationService();
|
|
$items = $service->getLatest((int)Auth::user()['id'], 20);
|
|
$unreadCount = $service->getUnreadCount((int)Auth::user()['id']);
|
|
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
echo json_encode([
|
|
'items' => $items,
|
|
'unread_count' => $unreadCount,
|
|
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
|
}
|
|
|
|
public function readAll(): void
|
|
{
|
|
if (!Auth::check()) {
|
|
http_response_code(403);
|
|
echo 'Unauthorized';
|
|
return;
|
|
}
|
|
|
|
$service = new NotificationService();
|
|
$service->markAllRead((int)Auth::user()['id']);
|
|
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
echo json_encode(['success' => true], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
|
}
|
|
} |