mirror of
git://f0xx.org/ac/ac-ms-issues
synced 2026-07-29 03:38:42 +03:00
initial
This commit is contained in:
25
public/api/report_viewed.php
Normal file
25
public/api/report_viewed.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?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);
|
||||
}
|
||||
Reference in New Issue
Block a user