payfrit-api/api/stations/list.php
John Mizerek 1f81d98c52 Initial PHP API migration from CFML
Complete port of all 163 API endpoints from Lucee/CFML to PHP 8.3.
Shared helpers in api/helpers.php (DB, auth, request/response, security).
PDO prepared statements throughout. Same JSON response shapes as CFML.
2026-03-14 14:26:59 -07:00

35 lines
1 KiB
PHP

<?php
require_once __DIR__ . '/../helpers.php';
runAuth();
$data = readJsonBody();
$bizId = (int) ($data['BusinessID'] ?? 0);
if ($bizId <= 0) {
apiAbort(['OK' => false, 'ERROR' => 'missing_businessid', 'MESSAGE' => 'BusinessID is required.']);
}
try {
$rows = queryTimed("
SELECT ID, BusinessID, Name, Color, SortOrder
FROM Stations
WHERE BusinessID = ? AND IsActive = 1
ORDER BY SortOrder, ID
", [$bizId]);
$stations = [];
foreach ($rows as $r) {
$stations[] = [
'StationID' => (int) $r['ID'],
'BusinessID' => (int) $r['BusinessID'],
'Name' => $r['Name'],
'Color' => $r['Color'],
'SortOrder' => (int) $r['SortOrder'],
];
}
jsonResponse(['OK' => true, 'ERROR' => '', 'STATIONS' => $stations, 'COUNT' => count($stations)]);
} catch (Exception $e) {
jsonResponse(['OK' => false, 'ERROR' => 'server_error', 'MESSAGE' => 'DB error loading stations', 'DETAIL' => $e->getMessage()]);
}