Documentation
¶
Index ¶
- type Plan
- type User
- type UserResponse
- type UsersHandler
- type UsersRepository
- func (r *UsersRepository) Activate(ctx context.Context, id uuid.UUID) (User, error)
- func (r *UsersRepository) Create(ctx context.Context, user User) (User, error)
- func (r *UsersRepository) Delete(ctx context.Context, id uuid.UUID) error
- func (r *UsersRepository) FindByEmail(ctx context.Context, email string) (User, error)
- func (r *UsersRepository) FindByID(ctx context.Context, id uuid.UUID) (User, error)
- func (r *UsersRepository) FindByStripeCustomerID(ctx context.Context, stripeCustomerID string) (User, error)
- func (r *UsersRepository) Update(ctx context.Context, user User) (User, error)
- func (r *UsersRepository) UpdatePlan(ctx context.Context, id uuid.UUID, plan Plan) error
- func (r *UsersRepository) UpdateStripeCustomerID(ctx context.Context, id uuid.UUID, stripeCustomerID string) error
- func (r *UsersRepository) UpdateStripeSubscriptionID(ctx context.Context, id uuid.UUID, subID *string) error
- type UsersService
- func (s *UsersService) Activate(ctx context.Context, id uuid.UUID) (User, error)
- func (s *UsersService) Create(ctx context.Context, user User) (User, error)
- func (s *UsersService) Delete(ctx context.Context, id uuid.UUID) error
- func (s *UsersService) GetByID(ctx context.Context, id uuid.UUID) (User, error)
- func (s *UsersService) Update(ctx context.Context, user User) (User, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type User ¶
type User struct {
ID uuid.UUID `gorm:"primaryKey;type:uuid;default:gen_random_uuid()"`
Email string `gorm:"not null;unique"`
Name string `gorm:"not null"`
Plan Plan `gorm:"type:varchar(20);not null;default:'beta'"`
ActivatedAt *time.Time `gorm:"column:activated_at"`
CreatedAt time.Time `gorm:"autoCreateTime"`
UpdatedAt time.Time `gorm:"autoUpdateTime"`
// Billing columns — nullable, only populated when BILLING_ENABLED=true.
// StripeCustomerID is indexed to support webhook lookups (SPEC-API §3.1).
StripeCustomerID *string `gorm:"column:stripe_customer_id;index:idx_users_stripe_customer_id"`
StripeSubscriptionID *string `gorm:"column:stripe_subscription_id"`
}
type UserResponse ¶ added in v0.3.1
type UserResponse struct {
ID uuid.UUID `json:"id"`
Name string `json:"name"`
Email string `json:"email"`
ActivatedAt *time.Time `json:"activated_at"`
}
UserResponse is the JSON representation of a user returned from the API.
type UsersHandler ¶
type UsersHandler struct {
// contains filtered or unexported fields
}
UsersHandler handles user-related HTTP requests.
func NewUsersHandler ¶
func NewUsersHandler(service userService, tracker analytics.Tracker) *UsersHandler
NewUsersHandler constructs a UsersHandler with the given service and tracker.
type UsersRepository ¶
type UsersRepository struct {
// contains filtered or unexported fields
}
func NewUsersRepository ¶
func NewUsersRepository(db *gorm.DB) *UsersRepository
func (*UsersRepository) Activate ¶ added in v0.3.1
Activate sets activated_at to the current time only when it is currently NULL, making the operation idempotent. It then re-fetches and returns the updated user.
func (*UsersRepository) FindByEmail ¶
func (*UsersRepository) FindByStripeCustomerID ¶ added in v0.4.0
func (r *UsersRepository) FindByStripeCustomerID(ctx context.Context, stripeCustomerID string) (User, error)
FindByStripeCustomerID looks up a user by their Stripe customer id. Used by the Stripe webhook handler to locate the user for an incoming event.
func (*UsersRepository) UpdatePlan ¶ added in v0.4.0
UpdatePlan sets the user's plan. Called by the Stripe webhook handler on checkout.session.completed (→ pro) and customer.subscription.deleted (→ free).
func (*UsersRepository) UpdateStripeCustomerID ¶ added in v0.4.0
func (r *UsersRepository) UpdateStripeCustomerID(ctx context.Context, id uuid.UUID, stripeCustomerID string) error
UpdateStripeCustomerID persists the Stripe customer id for a user. It is called the first time a user initiates Stripe checkout.
func (*UsersRepository) UpdateStripeSubscriptionID ¶ added in v0.4.0
func (r *UsersRepository) UpdateStripeSubscriptionID(ctx context.Context, id uuid.UUID, subID *string) error
UpdateStripeSubscriptionID stores or clears the Stripe subscription id for a user. Pass nil to clear (e.g. on subscription cancellation).
type UsersService ¶
type UsersService struct {
// contains filtered or unexported fields
}
func NewUsersService ¶
func NewUsersService(repository repository) *UsersService
func (*UsersService) Activate ¶ added in v0.3.1
Activate sets activated_at on the user if it is currently unset. The operation is idempotent: if the user is already activated the existing timestamp is preserved. Returns the (possibly unchanged) user.