3 function handle_request($id, $input)
5 $input = json_decode($input, true);
6 $appointment = $input['turno'];
7 $petId = $input['mascota_id'];
9 $db = new SQLite3('database.sqlite');
13 $result = $db->query('SELECT id FROM veterinario');
15 while ($row = $result->fetchArray(SQLITE3_ASSOC
)) {
16 $veterinaries[] = $row['id'];
19 $result = $db->query("SELECT veterinario_id FROM turno WHERE turno = '{$appointment}'");
21 while ($row = $result->fetchArray(SQLITE3_ASSOC
)) {
22 $key = array_search($row['veterinario_id'], $veterinaries);
24 unset($veterinaries[$key]);
28 $veterinaryId = array_shift($veterinaries);
30 $db->exec("INSERT INTO turno (turno, mascota_id, veterinario_id) VALUES ('{$appointment}', '{$petId}', '{$veterinaryId}')");
35 'turno' => $appointment,
36 'mascota_id' => $petId,