19 lines
467 B
PHP
19 lines
467 B
PHP
<?php
|
|
// POST { id } -> deletes an entry the caller owns.
|
|
require __DIR__ . '/../lib/bootstrap.php';
|
|
require_method('POST');
|
|
|
|
$user = require_user();
|
|
$body = json_body();
|
|
$id = (int)($body['id'] ?? 0);
|
|
|
|
if ($id <= 0) json_error('Invalid id.');
|
|
|
|
$stmt = db()->prepare('DELETE FROM journal_entries WHERE id = ? AND user_id = ?');
|
|
$stmt->execute([$id, $user['id']]);
|
|
if ($stmt->rowCount() === 0) {
|
|
json_error('Entry not found.', 404);
|
|
}
|
|
|
|
json_out(['ok' => true]);
|