Files
SkinbaseNova/app/Http/Controllers/Api/NotificationController.php
2026-03-20 21:17:26 +01:00

38 lines
1.2 KiB
PHP

<?php
namespace App\Http\Controllers\Api;
use App\Services\NotificationService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
/**
* GET /api/notifications — digestd notification list
* POST /api/notifications/read-all — mark all unread as read
* POST /api/notifications/{id}/read — mark single as read
*/
class NotificationController extends Controller
{
public function __construct(private NotificationService $notifications) {}
public function index(Request $request): JsonResponse
{
return response()->json(
$this->notifications->listForUser($request->user(), (int) $request->query('page', 1), 20)
);
}
public function readAll(Request $request): JsonResponse
{
$this->notifications->markAllRead($request->user());
return response()->json(['message' => 'All notifications marked as read.']);
}
public function markRead(Request $request, string $id): JsonResponse
{
$this->notifications->markRead($request->user(), $id);
return response()->json(['message' => 'Notification marked as read.']);
}
}