Documentation
¶
Overview ¶
Package referral tracks user-to-user invite relationships. This is a side-path feature — errors must never block the main login flow.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Recorder ¶
type Recorder struct {
// contains filtered or unexported fields
}
Recorder implements identity.ReferralRecorder using the referral Repository.
func NewRecorder ¶
func NewRecorder(repo Repository) *Recorder
NewRecorder creates a Recorder backed by the given repository.
type Referral ¶
type Referral struct {
ReferralID string `json:"referral_id"`
ReferrerAccountID string `json:"referrer_account_id"`
ReferredEmail string `json:"referred_email"`
ReferredAccountID string `json:"referred_account_id,omitempty"`
Status string `json:"status"` // pending | completed
CreatedAt time.Time `json:"created_at"`
CompletedAt *time.Time `json:"completed_at,omitempty"`
}
Referral records a single referrer → referred relationship.
type Repository ¶
type Repository interface {
// Create inserts a new pending referral. Duplicate (referrer, email) pairs
// are silently ignored (idempotent).
Create(ctx context.Context, r *Referral) error
// Complete marks referrals for the given email as completed, linking them
// to the referred account. Returns count of rows updated.
Complete(ctx context.Context, referredEmail, referredAccountID string) (int, error)
// ListByReferrer returns all referrals created by a given account.
ListByReferrer(ctx context.Context, referrerAccountID string) ([]*Referral, error)
}
Repository is the storage contract for referrals.
func NewSQLRepository ¶
func NewSQLRepository(db *shared.DB) Repository
NewSQLRepository creates a SQL-backed referral repository (PostgreSQL or SQLite — dialect handled transparently by shared.DB).
Click to show internal directories.
Click to hide internal directories.