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.
38 lines
1.2 KiB
PHP
38 lines
1.2 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../helpers.php';
|
|
runAuth();
|
|
|
|
global $userId;
|
|
|
|
if ($userId <= 0) {
|
|
apiAbort(['OK' => false, 'ERROR' => 'not_logged_in', 'MESSAGE' => 'Authentication required']);
|
|
}
|
|
|
|
$data = readJsonBody();
|
|
$addressId = (int) ($data['AddressID'] ?? ($_GET['id'] ?? 0));
|
|
|
|
if ($addressId <= 0) {
|
|
apiAbort(['OK' => false, 'ERROR' => 'invalid_id', 'MESSAGE' => 'Address ID required']);
|
|
}
|
|
|
|
try {
|
|
$qAddr = queryOne("
|
|
SELECT Line1, Line2, City, StateID, ZIPCode
|
|
FROM Addresses WHERE ID = ? AND UserID = ? AND IsDeleted = 0
|
|
", [$addressId, $userId]);
|
|
|
|
if (!$qAddr) {
|
|
apiAbort(['OK' => false, 'ERROR' => 'not_found', 'MESSAGE' => 'Address not found']);
|
|
}
|
|
|
|
// Soft-delete all matching duplicates
|
|
queryTimed("
|
|
UPDATE Addresses SET IsDeleted = 1
|
|
WHERE UserID = ? AND Line1 = ? AND Line2 = ? AND City = ? AND StateID = ? AND ZIPCode = ? AND IsDeleted = 0
|
|
", [$userId, $qAddr['Line1'], $qAddr['Line2'] ?? '', $qAddr['City'], (int) $qAddr['StateID'], $qAddr['ZIPCode']]);
|
|
|
|
jsonResponse(['OK' => true, 'MESSAGE' => 'Address deleted']);
|
|
|
|
} catch (Exception $e) {
|
|
apiAbort(['OK' => false, 'ERROR' => 'server_error', 'MESSAGE' => $e->getMessage()]);
|
|
}
|