Governed operator lists (organizations, grants, people, billing×4) gain
server-side search, status filters, and 50-row pages with true totals
from count(*) OVER(); state is URL-addressable, out-of-range pages
clamp,
and no-match is distinct from true-empty.
People is the eighth flat sidebar entry: /operator/persons lists persons
newest-joined first (excluding the reserved system person), rows linking
to the existing detail.
Billing gains an operator invoice detail at
/operator/billing/invoices/{invoiceID} reusing the member projection;
open invoices past due present as Overdue (derived, filterable, stored
status untouched); all four views lead with the linked organization and
mute object IDs.
Grants filter over the derived Live/Superseded/Inactive state, the SQL
HAVING predicate pinned to the Go derivation by test. Embedded lists
(org composite ledger, Tier changes) adopt the shared controls under
namespaced params with sibling-state-preserving URLs and scoped htmx
swaps that hold the viewport.
Review corrections: blocked ladder Delete renders disabled with tooltip
and mutations fire toasts; collapse triggers paint their open state;
sections use outside headings; plan topology drops the orphan-product
check; domains policy collapses behind a disclosure.
298 lines
8.1 KiB
Go
298 lines
8.1 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: payments.sql
|
|
|
|
package billing
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/lib/pq"
|
|
)
|
|
|
|
const createPayment = `-- name: CreatePayment :one
|
|
INSERT INTO core.payments (
|
|
invoice_id, billing_account_id, payment_method_id,
|
|
amount, currency, status, failed_at
|
|
)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
|
RETURNING payment_id, invoice_id, billing_account_id, payment_method_id, amount, currency, status, failed_at, created_at, updated_at
|
|
`
|
|
|
|
type CreatePaymentParams struct {
|
|
InvoiceID string `json:"invoice_id"`
|
|
BillingAccountID string `json:"billing_account_id"`
|
|
PaymentMethodID uuid.NullUUID `json:"payment_method_id"`
|
|
Amount int32 `json:"amount"`
|
|
Currency string `json:"currency"`
|
|
Status string `json:"status"`
|
|
FailedAt sql.NullTime `json:"failed_at"`
|
|
}
|
|
|
|
func (q *Queries) CreatePayment(ctx context.Context, arg CreatePaymentParams) (Payment, error) {
|
|
row := q.db.QueryRowContext(ctx, createPayment,
|
|
arg.InvoiceID,
|
|
arg.BillingAccountID,
|
|
arg.PaymentMethodID,
|
|
arg.Amount,
|
|
arg.Currency,
|
|
arg.Status,
|
|
arg.FailedAt,
|
|
)
|
|
var i Payment
|
|
err := row.Scan(
|
|
&i.PaymentID,
|
|
&i.InvoiceID,
|
|
&i.BillingAccountID,
|
|
&i.PaymentMethodID,
|
|
&i.Amount,
|
|
&i.Currency,
|
|
&i.Status,
|
|
&i.FailedAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getPaymentByID = `-- name: GetPaymentByID :one
|
|
SELECT payment_id, invoice_id, billing_account_id, payment_method_id, amount, currency, status, failed_at, created_at, updated_at FROM core.payments
|
|
WHERE payment_id = $1
|
|
`
|
|
|
|
func (q *Queries) GetPaymentByID(ctx context.Context, paymentID string) (Payment, error) {
|
|
row := q.db.QueryRowContext(ctx, getPaymentByID, paymentID)
|
|
var i Payment
|
|
err := row.Scan(
|
|
&i.PaymentID,
|
|
&i.InvoiceID,
|
|
&i.BillingAccountID,
|
|
&i.PaymentMethodID,
|
|
&i.Amount,
|
|
&i.Currency,
|
|
&i.Status,
|
|
&i.FailedAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getPaymentsByInvoiceID = `-- name: GetPaymentsByInvoiceID :many
|
|
SELECT payment_id, invoice_id, billing_account_id, payment_method_id, amount, currency, status, failed_at, created_at, updated_at FROM core.payments
|
|
WHERE invoice_id = $1
|
|
ORDER BY created_at DESC
|
|
`
|
|
|
|
func (q *Queries) GetPaymentsByInvoiceID(ctx context.Context, invoiceID string) ([]Payment, error) {
|
|
rows, err := q.db.QueryContext(ctx, getPaymentsByInvoiceID, invoiceID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []Payment{}
|
|
for rows.Next() {
|
|
var i Payment
|
|
if err := rows.Scan(
|
|
&i.PaymentID,
|
|
&i.InvoiceID,
|
|
&i.BillingAccountID,
|
|
&i.PaymentMethodID,
|
|
&i.Amount,
|
|
&i.Currency,
|
|
&i.Status,
|
|
&i.FailedAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listPaymentsPage = `-- name: ListPaymentsPage :many
|
|
SELECT
|
|
p.payment_id,
|
|
p.invoice_id,
|
|
p.billing_account_id,
|
|
ba.org_id,
|
|
p.payment_method_id,
|
|
p.amount,
|
|
p.currency,
|
|
p.status,
|
|
p.failed_at,
|
|
p.created_at,
|
|
p.updated_at,
|
|
ba.name as billing_account_name,
|
|
pm.pm_type as payment_method_type,
|
|
pm.card_brand,
|
|
pm.card_last4,
|
|
count(*) OVER() AS total_count
|
|
FROM core.payments p
|
|
JOIN core.accounts ba ON p.billing_account_id = ba.billing_account_id
|
|
LEFT JOIN core.payment_methods pm ON p.payment_method_id = pm.payment_method_id
|
|
WHERE ($1::text IS NULL
|
|
OR ba.name ILIKE '%' || $1::text || '%'
|
|
OR ba.org_id = ANY($2::uuid[]))
|
|
ORDER BY p.created_at DESC
|
|
LIMIT $4::int OFFSET $3::int
|
|
`
|
|
|
|
type ListPaymentsPageParams struct {
|
|
Q sql.NullString `json:"q"`
|
|
OrgIds []string `json:"org_ids"`
|
|
PageOffset int32 `json:"page_offset"`
|
|
PageLimit int32 `json:"page_limit"`
|
|
}
|
|
|
|
type ListPaymentsPageRow struct {
|
|
PaymentID string `json:"payment_id"`
|
|
InvoiceID string `json:"invoice_id"`
|
|
BillingAccountID string `json:"billing_account_id"`
|
|
OrgID string `json:"org_id"`
|
|
PaymentMethodID uuid.NullUUID `json:"payment_method_id"`
|
|
Amount int32 `json:"amount"`
|
|
Currency string `json:"currency"`
|
|
Status string `json:"status"`
|
|
FailedAt sql.NullTime `json:"failed_at"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
BillingAccountName string `json:"billing_account_name"`
|
|
PaymentMethodType sql.NullString `json:"payment_method_type"`
|
|
CardBrand sql.NullString `json:"card_brand"`
|
|
CardLast4 sql.NullString `json:"card_last4"`
|
|
TotalCount int64 `json:"total_count"`
|
|
}
|
|
|
|
// Operator payments view, paged and searched (operator-list-scale UX-4;
|
|
// operator-billing-views D8). No status facet: the operator-list-scale
|
|
// spec's "Status filters exist where a status vocabulary exists"
|
|
// requirement enumerates grants/invoices/subscriptions/organizations, not
|
|
// payments, so this query offers search + pagination only. Carries
|
|
// ba.org_id so the handler can resolve and link the organization without a
|
|
// cross-module join (see billing_accounts.sql's ListBillingAccountsPage
|
|
// comment for why).
|
|
//
|
|
// sqlc.narg(q): NULL matches every row; set, a case-insensitive substring
|
|
// match against the billing account's name (the view's leading identifier
|
|
// pre-reorder) or its organization via sqlc.narg(org_ids), pre-resolved in
|
|
// Go (operator_billing.go: matchingOrgIDs).
|
|
// count(*) OVER() carries the true total for the filtered set (design D2).
|
|
func (q *Queries) ListPaymentsPage(ctx context.Context, arg ListPaymentsPageParams) ([]ListPaymentsPageRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, listPaymentsPage,
|
|
arg.Q,
|
|
pq.Array(arg.OrgIds),
|
|
arg.PageOffset,
|
|
arg.PageLimit,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []ListPaymentsPageRow{}
|
|
for rows.Next() {
|
|
var i ListPaymentsPageRow
|
|
if err := rows.Scan(
|
|
&i.PaymentID,
|
|
&i.InvoiceID,
|
|
&i.BillingAccountID,
|
|
&i.OrgID,
|
|
&i.PaymentMethodID,
|
|
&i.Amount,
|
|
&i.Currency,
|
|
&i.Status,
|
|
&i.FailedAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.BillingAccountName,
|
|
&i.PaymentMethodType,
|
|
&i.CardBrand,
|
|
&i.CardLast4,
|
|
&i.TotalCount,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listRecentPayments = `-- name: ListRecentPayments :many
|
|
SELECT
|
|
p.payment_id,
|
|
p.invoice_id,
|
|
p.billing_account_id,
|
|
ba.org_id,
|
|
p.amount,
|
|
p.currency,
|
|
p.status,
|
|
p.created_at
|
|
FROM core.payments p
|
|
JOIN core.accounts ba ON ba.billing_account_id = p.billing_account_id
|
|
ORDER BY p.created_at DESC
|
|
LIMIT $1
|
|
`
|
|
|
|
type ListRecentPaymentsRow struct {
|
|
PaymentID string `json:"payment_id"`
|
|
InvoiceID string `json:"invoice_id"`
|
|
BillingAccountID string `json:"billing_account_id"`
|
|
OrgID string `json:"org_id"`
|
|
Amount int32 `json:"amount"`
|
|
Currency string `json:"currency"`
|
|
Status string `json:"status"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
|
|
// Recent payments for the operator landing activity timeline. Joins to
|
|
// core.accounts to resolve the org_id (same schema, safe for sqlc).
|
|
func (q *Queries) ListRecentPayments(ctx context.Context, limit int32) ([]ListRecentPaymentsRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, listRecentPayments, limit)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []ListRecentPaymentsRow{}
|
|
for rows.Next() {
|
|
var i ListRecentPaymentsRow
|
|
if err := rows.Scan(
|
|
&i.PaymentID,
|
|
&i.InvoiceID,
|
|
&i.BillingAccountID,
|
|
&i.OrgID,
|
|
&i.Amount,
|
|
&i.Currency,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|