first commit
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user