1
0
mirror of git://f0xx.org/ac/ac-ms-issues synced 2026-07-29 01:38:56 +03:00
Files
ac-ms-issues/public/api/report_viewed.php
Anton Afanasyeu 892f6e3196 initial
2026-06-23 12:29:32 +02:00

26 lines
760 B
PHP

<?php
declare(strict_types=1);
require_once __DIR__ . '/../../src/bootstrap.php';
if (!Auth::user()) {
json_out(['ok' => false, 'error' => 'unauthorized'], 401);
}
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
json_out(['ok' => false, 'error' => 'POST required'], 405);
}
$raw = file_get_contents('php://input');
$data = is_string($raw) && $raw !== '' ? json_decode($raw, true) : $_POST;
$id = (int) ($data['id'] ?? 0);
if ($id <= 0) {
json_out(['ok' => false, 'error' => 'invalid id'], 400);
}
try {
ReportRepository::markViewed($id, (int) Auth::user()['id']);
json_out(['ok' => true, 'id' => $id]);
} catch (Throwable $e) {
error_log('report_viewed: ' . $e->getMessage());
json_out(['ok' => false, 'error' => 'failed'], 500);
}