From f09777eaa5f11099c355e901eba756fb53f08f25 Mon Sep 17 00:00:00 2001 From: John Mizerek Date: Sun, 1 Mar 2026 11:20:16 -0800 Subject: [PATCH] =?UTF-8?q?Add=20get=5Fbeacon=5Fconfig=20endpoint=20?= =?UTF-8?q?=E2=80=94=20single=20call=20for=20all=20beacon=20config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Combines allocate_business_namespace + allocate_servicepoint_minor into one endpoint that returns UUID, Major, Minor, MeasuredPower, AdvInterval, TxPower, ServicePointName, and BusinessName. No more hardcoded defaults on the client. Co-Authored-By: Claude Opus 4.6 --- api/beacon-sharding/get_beacon_config.cfm | 206 ++++++++++++++++++++++ 1 file changed, 206 insertions(+) create mode 100644 api/beacon-sharding/get_beacon_config.cfm diff --git a/api/beacon-sharding/get_beacon_config.cfm b/api/beacon-sharding/get_beacon_config.cfm new file mode 100644 index 0000000..a3f9904 --- /dev/null +++ b/api/beacon-sharding/get_beacon_config.cfm @@ -0,0 +1,206 @@ + + + + + + + + + + +function apiAbort(obj) { + writeOutput(serializeJSON(obj)); + abort; +} + +function readJsonBody() { + raw = toString(getHttpRequestData().content); + if (isNull(raw) || len(trim(raw)) EQ 0) return {}; + try { + parsed = deserializeJSON(raw); + } catch(any e) { + apiAbort({ OK=false, ERROR="bad_json", MESSAGE="Invalid JSON body" }); + } + if (!isStruct(parsed)) return {}; + return parsed; +} + +data = readJsonBody(); +httpHeaders = getHttpRequestData().headers; + +// Get BusinessID +bizId = 0; +if (structKeyExists(request, "BusinessID") && isNumeric(request.BusinessID) && request.BusinessID GT 0) { + bizId = int(request.BusinessID); +} +if (bizId LTE 0 && structKeyExists(data, "BusinessID") && isNumeric(data.BusinessID) && data.BusinessID GT 0) { + bizId = int(data.BusinessID); +} +if (bizId LTE 0 && structKeyExists(httpHeaders, "X-Business-ID") && isNumeric(httpHeaders["X-Business-ID"]) && httpHeaders["X-Business-ID"] GT 0) { + bizId = int(httpHeaders["X-Business-ID"]); +} +if (bizId LTE 0) { + apiAbort({ OK=false, ERROR="missing_business_id", MESSAGE="BusinessID is required" }); +} + +// Get ServicePointID +spId = 0; +if (structKeyExists(data, "ServicePointID") && isNumeric(data.ServicePointID) && data.ServicePointID GT 0) { + spId = int(data.ServicePointID); +} +if (spId LTE 0) { + apiAbort({ OK=false, ERROR="missing_servicepoint_id", MESSAGE="ServicePointID is required" }); +} + + + + + SELECT b.ID, b.Name, b.BeaconShardID, b.BeaconMajor + FROM Businesses b + WHERE b.ID = + LIMIT 1 + + + + + + + + + + + + + + + SELECT ID, UUID, BusinessCount + FROM BeaconShards + WHERE IsActive = 1 + AND BusinessCount < MaxBusinesses + ORDER BY BusinessCount ASC + LIMIT 1 + FOR UPDATE + + + + + + + + + + + SELECT COALESCE(MAX(BeaconMajor), -1) AS MaxMajor + FROM Businesses + WHERE BeaconShardID = + + + + + + + + + + + UPDATE Businesses + SET BeaconShardID = , + BeaconMajor = + WHERE ID = + AND (BeaconShardID IS NULL OR BeaconMajor IS NULL) + + + + + UPDATE BeaconShards + SET BusinessCount = BusinessCount + 1 + WHERE ID = + + + + + + SELECT UUID FROM BeaconShards WHERE ID = + + + + + SELECT ID, BusinessID, Name, BeaconMinor + FROM ServicePoints + WHERE ID = + LIMIT 1 + + + + + + + + + + + + + + + + SELECT COALESCE(MAX(BeaconMinor), -1) AS MaxMinor + FROM ServicePoints + WHERE BusinessID = + + + + + + + + + + + UPDATE ServicePoints + SET BeaconMinor = + WHERE ID = + AND BeaconMinor IS NULL + + + +#serializeJSON({ + OK = true, + UUID = qShardUUID.UUID, + Major = beaconMajor, + Minor = beaconMinor, + MeasuredPower = -100, + AdvInterval = 2, + TxPower = 1, + ServicePointName = qSP.Name, + BusinessName = qBiz.Name +})# + + + + + #serializeJSON({ OK=false, ERROR="server_error", MESSAGE=cfcatch.message, DETAIL=cfcatch.detail })# + +