referral

package
v0.2.1-dev Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

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.

func (*Recorder) CompleteReferral

func (r *Recorder) CompleteReferral(ctx context.Context, referredEmail, referredAccountID string) error

CompleteReferral marks pending referrals for the email as completed.

func (*Recorder) RecordReferral

func (r *Recorder) RecordReferral(ctx context.Context, referrerAccountID, referredEmail string) error

RecordReferral creates a pending referral. Idempotent on (referrer, email).

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).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL