Auto commit: 2025-11-21T19:17:14.263Z

This commit is contained in:
Flatlogic Bot 2025-11-21 19:17:14 +00:00
parent 0aaa47eb72
commit a31ae61407
2 changed files with 13 additions and 7 deletions

View File

@ -10,6 +10,7 @@ $action = $_GET['action'] ?? $_POST['action'] ?? '';
if ($_SERVER['REQUEST_METHOD'] === 'POST' && $action === 'create') { if ($_SERVER['REQUEST_METHOD'] === 'POST' && $action === 'create') {
$alarm_time = $_POST['alarm_time'] ?? null; $alarm_time = $_POST['alarm_time'] ?? null;
$label = $_POST['label'] ?? '';
if ($alarm_time) { if ($alarm_time) {
try { try {
@ -21,17 +22,21 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && $action === 'create') {
$noteId = $pdo->lastInsertId(); $noteId = $pdo->lastInsertId();
// 2. Create the alarm and link it to the new note // 2. Create the alarm and link it to the new note
$alarmStmt = $pdo->prepare("INSERT INTO alarms (alarm_time, note_id, is_active) VALUES (?, ?, 1)"); $alarmStmt = $pdo->prepare("INSERT INTO alarms (alarm_time, label, note_id, is_active) VALUES (?, ?, ?, 1)");
$alarmStmt->execute([$alarm_time, $noteId]); $alarmStmt->execute([$alarm_time, $label, $noteId]);
$alarmId = $pdo->lastInsertId(); $alarmId = $pdo->lastInsertId();
$pdo->commit(); $pdo->commit();
$response = [ $response = [
'success' => true, 'success' => true,
'alarm' => [
'id' => $alarmId, 'id' => $alarmId,
'note_id' => $noteId, 'alarm_time' => $alarm_time,
'alarm_time' => $alarm_time 'label' => $label,
'is_active' => 1,
'note_id' => $noteId
]
]; ];
} catch (PDOException $e) { } catch (PDOException $e) {
@ -45,7 +50,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && $action === 'create') {
elseif ($_SERVER['REQUEST_METHOD'] === 'GET' && $action === 'get') { elseif ($_SERVER['REQUEST_METHOD'] === 'GET' && $action === 'get') {
try { try {
$stmt = $pdo->query("SELECT id, alarm_time, note_id, is_active FROM alarms ORDER BY alarm_time"); $stmt = $pdo->query("SELECT id, alarm_time, label, note_id, is_active FROM alarms ORDER BY alarm_time");
$alarms = $stmt->fetchAll(PDO::FETCH_ASSOC); $alarms = $stmt->fetchAll(PDO::FETCH_ASSOC);
$response = ['success' => true, 'alarms' => $alarms]; $response = ['success' => true, 'alarms' => $alarms];
} catch (PDOException $e) { } catch (PDOException $e) {

View File

@ -0,0 +1 @@
ALTER TABLE alarms ADD COLUMN note_id INT NULL, ADD CONSTRAINT fk_note_id FOREIGN KEY (note_id) REFERENCES notes(id) ON DELETE CASCADE;