Auto commit: 2025-11-21T19:17:14.263Z
This commit is contained in:
parent
0aaa47eb72
commit
a31ae61407
@ -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
|
||||
'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) {
|
||||
|
||||
1
db/migrations/003_add_note_id_to_alarms.sql
Normal file
1
db/migrations/003_add_note_id_to_alarms.sql
Normal 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;
|
||||
Loading…
x
Reference in New Issue
Block a user