Add sharding support to beacon list and assignments APIs
For businesses using beacon sharding: - beacons/list.cfm now returns ServicePoints with BeaconMinor as beacons - assignments/list.cfm now shows sharding assignments (SP + Minor) - Both APIs include USES_SHARDING flag and sharding info Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
2f35eb69eb
commit
428129a93e
2 changed files with 139 additions and 27 deletions
|
|
@ -15,6 +15,52 @@ if (!structKeyExists(request, "BusinessID") || !isNumeric(request.BusinessID) ||
|
|||
}
|
||||
</cfscript>
|
||||
|
||||
<!--- Check if this business uses beacon sharding --->
|
||||
<cfquery name="qBiz" datasource="payfrit">
|
||||
SELECT BeaconShardID, BeaconMajor
|
||||
FROM Businesses
|
||||
WHERE ID = <cfqueryparam cfsqltype="cf_sql_integer" value="#request.BusinessID#">
|
||||
LIMIT 1
|
||||
</cfquery>
|
||||
|
||||
<cfset usesSharding = qBiz.recordCount GT 0 AND val(qBiz.BeaconShardID) GT 0>
|
||||
<cfset assignments = []>
|
||||
|
||||
<cfif usesSharding>
|
||||
<!--- Sharding: assignments are ServicePoints with BeaconMinor --->
|
||||
<cfquery name="qShard" datasource="payfrit">
|
||||
SELECT UUID FROM BeaconShards WHERE ID = <cfqueryparam cfsqltype="cf_sql_integer" value="#qBiz.BeaconShardID#">
|
||||
</cfquery>
|
||||
<cfset shardUUID = qShard.recordCount GT 0 ? qShard.UUID : "">
|
||||
|
||||
<cfquery name="qSharding" datasource="payfrit">
|
||||
SELECT
|
||||
sp.ID AS ServicePointID,
|
||||
sp.BeaconMinor,
|
||||
sp.Name AS ServicePointName
|
||||
FROM ServicePoints sp
|
||||
WHERE sp.BusinessID = <cfqueryparam cfsqltype="cf_sql_integer" value="#request.BusinessID#">
|
||||
AND sp.BeaconMinor IS NOT NULL
|
||||
AND sp.IsActive = 1
|
||||
ORDER BY sp.BeaconMinor, sp.Name
|
||||
</cfquery>
|
||||
|
||||
<cfloop query="qSharding">
|
||||
<cfset arrayAppend(assignments, {
|
||||
"ServicePointID" = qSharding.ServicePointID,
|
||||
"BeaconID" = 0,
|
||||
"BusinessID" = request.BusinessID,
|
||||
"BeaconName" = qSharding.ServicePointName & " (Minor " & qSharding.BeaconMinor & ")",
|
||||
"UUID" = shardUUID,
|
||||
"Major" = qBiz.BeaconMajor,
|
||||
"Minor" = qSharding.BeaconMinor,
|
||||
"ServicePointName"= qSharding.ServicePointName,
|
||||
"IsSharding" = true
|
||||
})>
|
||||
</cfloop>
|
||||
|
||||
<cfelse>
|
||||
<!--- Legacy: assignments via ServicePoints.BeaconID -> Beacons --->
|
||||
<cfquery name="q" datasource="payfrit">
|
||||
SELECT
|
||||
sp.ID AS ServicePointID,
|
||||
|
|
@ -31,7 +77,6 @@ if (!structKeyExists(request, "BusinessID") || !isNumeric(request.BusinessID) ||
|
|||
ORDER BY b.Name, sp.Name
|
||||
</cfquery>
|
||||
|
||||
<cfset assignments = []>
|
||||
<cfloop query="q">
|
||||
<cfset arrayAppend(assignments, {
|
||||
"ServicePointID" = q.ServicePointID,
|
||||
|
|
@ -39,8 +84,10 @@ if (!structKeyExists(request, "BusinessID") || !isNumeric(request.BusinessID) ||
|
|||
"BusinessID" = q.BusinessID,
|
||||
"BeaconName" = q.BeaconName,
|
||||
"UUID" = q.UUID,
|
||||
"ServicePointName"= q.ServicePointName
|
||||
"ServicePointName"= q.ServicePointName,
|
||||
"IsSharding" = false
|
||||
})>
|
||||
</cfloop>
|
||||
</cfif>
|
||||
|
||||
<cfoutput>#serializeJSON({ OK=true, ERROR="", COUNT=arrayLen(assignments), ASSIGNMENTS=assignments })#</cfoutput>
|
||||
<cfoutput>#serializeJSON({ OK=true, ERROR="", COUNT=arrayLen(assignments), ASSIGNMENTS=assignments, USES_SHARDING=usesSharding })#</cfoutput>
|
||||
|
|
|
|||
|
|
@ -55,6 +55,30 @@ if (structKeyExists(data, "onlyActive")) {
|
|||
}
|
||||
</cfscript>
|
||||
|
||||
<!--- Check if this business uses beacon sharding --->
|
||||
<cfquery name="qBiz" datasource="payfrit">
|
||||
SELECT BeaconShardID, BeaconMajor
|
||||
FROM Businesses
|
||||
WHERE ID = <cfqueryparam cfsqltype="cf_sql_integer" value="#bizId#">
|
||||
LIMIT 1
|
||||
</cfquery>
|
||||
|
||||
<cfset usesSharding = qBiz.recordCount GT 0 AND val(qBiz.BeaconShardID) GT 0>
|
||||
<cfset shardingInfo = {}>
|
||||
|
||||
<cfif usesSharding>
|
||||
<!--- Get shard UUID for display --->
|
||||
<cfquery name="qShard" datasource="payfrit">
|
||||
SELECT UUID FROM BeaconShards WHERE ID = <cfqueryparam cfsqltype="cf_sql_integer" value="#qBiz.BeaconShardID#">
|
||||
</cfquery>
|
||||
<cfset shardingInfo = {
|
||||
"ShardID" = qBiz.BeaconShardID,
|
||||
"ShardUUID" = qShard.recordCount GT 0 ? qShard.UUID : "",
|
||||
"Major" = qBiz.BeaconMajor
|
||||
}>
|
||||
</cfif>
|
||||
|
||||
<!--- Legacy beacons from Beacons table --->
|
||||
<cfquery name="q" datasource="payfrit">
|
||||
SELECT DISTINCT
|
||||
b.ID,
|
||||
|
|
@ -83,9 +107,50 @@ if (structKeyExists(data, "onlyActive")) {
|
|||
"BusinessID" = q.BusinessID,
|
||||
"Name" = q.Name,
|
||||
"UUID" = q.UUID,
|
||||
"IsActive" = q.IsActive
|
||||
"IsActive" = q.IsActive,
|
||||
"IsSharding" = false
|
||||
})>
|
||||
</cfloop>
|
||||
|
||||
<!--- If using sharding, also show service points with BeaconMinor as "beacons" --->
|
||||
<cfif usesSharding>
|
||||
<cfquery name="qShardBeacons" datasource="payfrit">
|
||||
SELECT
|
||||
sp.ID AS ServicePointID,
|
||||
sp.Name,
|
||||
sp.BeaconMinor,
|
||||
sp.IsActive
|
||||
FROM ServicePoints sp
|
||||
WHERE sp.BusinessID = <cfqueryparam cfsqltype="cf_sql_integer" value="#bizId#">
|
||||
AND sp.BeaconMinor IS NOT NULL
|
||||
<cfif onlyActive>
|
||||
AND sp.IsActive = 1
|
||||
</cfif>
|
||||
ORDER BY sp.BeaconMinor, sp.Name
|
||||
</cfquery>
|
||||
|
||||
<cfloop query="qShardBeacons">
|
||||
<cfset arrayAppend(beacons, {
|
||||
"BeaconID" = 0,
|
||||
"ServicePointID" = qShardBeacons.ServicePointID,
|
||||
"BusinessID" = bizId,
|
||||
"Name" = qShardBeacons.Name,
|
||||
"UUID" = shardingInfo.ShardUUID,
|
||||
"Major" = shardingInfo.Major,
|
||||
"Minor" = qShardBeacons.BeaconMinor,
|
||||
"IsActive" = qShardBeacons.IsActive,
|
||||
"IsSharding" = true
|
||||
})>
|
||||
</cfloop>
|
||||
</cfif>
|
||||
|
||||
<cfscript>try{logPerf(0);}catch(any e){}</cfscript>
|
||||
<cfoutput>#serializeJSON({ OK=true, ERROR="", BusinessID=bizId, COUNT=arrayLen(beacons), BEACONS=beacons })#</cfoutput>
|
||||
<cfoutput>#serializeJSON({
|
||||
OK=true,
|
||||
ERROR="",
|
||||
BusinessID=bizId,
|
||||
COUNT=arrayLen(beacons),
|
||||
BEACONS=beacons,
|
||||
USES_SHARDING=usesSharding,
|
||||
SHARDING_INFO=shardingInfo
|
||||
})#</cfoutput>
|
||||
|
|
|
|||
Reference in a new issue