From a31ae614070932f95ff413ca98839f0be94a8f81 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Fri, 21 Nov 2025 19:17:14 +0000 Subject: [PATCH] Auto commit: 2025-11-21T19:17:14.263Z --- api/alarms.php | 19 ++++++++++++------- db/migrations/003_add_note_id_to_alarms.sql | 1 + 2 files changed, 13 insertions(+), 7 deletions(-) create mode 100644 db/migrations/003_add_note_id_to_alarms.sql diff --git a/api/alarms.php b/api/alarms.php index 70d902e..6fc10a2 100644 --- a/api/alarms.php +++ b/api/alarms.php @@ -10,6 +10,7 @@ $action = $_GET['action'] ?? $_POST['action'] ?? ''; if ($_SERVER['REQUEST_METHOD'] === 'POST' && $action === 'create') { $alarm_time = $_POST['alarm_time'] ?? null; + $label = $_POST['label'] ?? ''; if ($alarm_time) { try { @@ -21,17 +22,21 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && $action === 'create') { $noteId = $pdo->lastInsertId(); // 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->execute([$alarm_time, $noteId]); + $alarmStmt = $pdo->prepare("INSERT INTO alarms (alarm_time, label, note_id, is_active) VALUES (?, ?, ?, 1)"); + $alarmStmt->execute([$alarm_time, $label, $noteId]); $alarmId = $pdo->lastInsertId(); $pdo->commit(); $response = [ - 'success' => true, - 'id' => $alarmId, - 'note_id' => $noteId, - 'alarm_time' => $alarm_time + 'success' => true, + 'alarm' => [ + 'id' => $alarmId, + 'alarm_time' => $alarm_time, + 'label' => $label, + 'is_active' => 1, + 'note_id' => $noteId + ] ]; } catch (PDOException $e) { @@ -45,7 +50,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && $action === 'create') { elseif ($_SERVER['REQUEST_METHOD'] === 'GET' && $action === 'get') { 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); $response = ['success' => true, 'alarms' => $alarms]; } catch (PDOException $e) { diff --git a/db/migrations/003_add_note_id_to_alarms.sql b/db/migrations/003_add_note_id_to_alarms.sql new file mode 100644 index 0000000..451e282 --- /dev/null +++ b/db/migrations/003_add_note_id_to_alarms.sql @@ -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; \ No newline at end of file