Skip to content

usage: GET /api/v1/usage/wall returns latest near-wall audit row (U1)#43

Merged
mastermanas805 merged 2 commits into
masterfrom
pricing/u1-quota-nudge-api-fresh
May 12, 2026
Merged

usage: GET /api/v1/usage/wall returns latest near-wall audit row (U1)#43
mastermanas805 merged 2 commits into
masterfrom
pricing/u1-quota-nudge-api-fresh

Conversation

@mastermanas805
Copy link
Copy Markdown
Member

Summary

Track U1 — API surface for the dashboard's upgrade banner.

  • New endpoint GET /api/v1/usage/wall (api/internal/handlers/usage_wall.go). Returns the most recent near_quota_wall audit row written by the worker's QuotaWallNudgeWorker, scoped to the caller's team and bounded to the last 24h.
  • Response shape:
    • {ok:true, near_wall:false} when no row is present (or the row is stale)
    • {ok:true, near_wall:true, tier, axis, service, current, limit, percent_used, at} when a row exists

Index reuse

Query reads audit_log filtered by (team_id, kind, created_at >= cutoff) and is covered by idx_audit_team_at (team_id, created_at DESC) from migration 012. No new index needed.

Tier gate

team-tier callers always get near_wall:false without an audit query — team tier has no walls so the scan is meaningless. Saves a DB hit for the most-active paid tier.

Auth

Routed under the /api/v1 group, so RequireAuth is enforced and team scope comes from the JWT claims (no team_id in the path).

Test plan

  • 3 new sqlmock-driven tests in usage_wall_test.go cover the latest-row, no-row, and team-tier short-circuit paths
  • Full internal/handlers suite green (ok instant.dev/internal/handlers 21.7s)
  • Two pre-existing failures in internal/plans and one transient failure in internal/middleware are unrelated to U1 (verified with git stash)

🤖 Generated with Claude Code

New endpoint reads the most recent near_quota_wall row written by the
worker's QuotaWallNudgeWorker, scoped to the caller's team and bounded
to the last 24h. Returns the metadata fields (tier/axis/service/current/
limit/percent_used/at) flattened into the response when a row exists,
or {ok:true, near_wall:false} when absent or stale.

Tier gate: team-tier callers always get near_wall=false without an
audit query — team tier has no walls so the scan is meaningless.

Query uses the existing idx_audit_team_at index (team_id + created_at
DESC from migration 012), which is the exact access pattern. No new
index needed.

Routed under the /api/v1 auth group so a valid session JWT is required
and team scope comes from the JWT claims.
…dge-api-fresh

# Conflicts:
#	internal/router/router.go
@mastermanas805 mastermanas805 merged commit 12feb4a into master May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant