api delete booking
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* api_teacher_delete_booking.php
|
||||
* --------------------------------------------------------------------------
|
||||
* Elimina una prenotazione (record bookingclass). Libera il ticket:
|
||||
* l'allievo se lo ritrova disponibile. Solo staff (Admin=1 / teacher=3).
|
||||
*
|
||||
* Posizione: public/api/api_teacher_delete_booking.php
|
||||
* Metodo: POST
|
||||
* Auth: Bearer token (Sanctum) via _bootstrap.php
|
||||
* Body: booking_id=<int>
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/_bootstrap.php';
|
||||
|
||||
// Gate staff
|
||||
$roleId = (int) $user->role_id;
|
||||
if (!in_array($roleId, [1, 3], true)) {
|
||||
http_response_code(403);
|
||||
echo json_encode(['success' => false, 'message' => 'Forbidden']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$bookingId = isset($_POST['booking_id']) ? (int) $_POST['booking_id'] : 0;
|
||||
|
||||
if ($bookingId <= 0) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'message' => 'ID prenotazione non valido']);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
$stmt = $db->prepare("DELETE FROM bookingclass WHERE idbookingclass = :id");
|
||||
$stmt->execute([':id' => $bookingId]);
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'booking_id' => $bookingId,
|
||||
'deleted' => $stmt->rowCount(),
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
} catch (Throwable $ex) {
|
||||
error_log('api_teacher_delete_booking error: ' . $ex->getMessage());
|
||||
http_response_code(500);
|
||||
echo json_encode(['success' => false, 'message' => 'Errore eliminazione']);
|
||||
}
|
||||
Reference in New Issue
Block a user