users

package
v0.4.3-dev.1 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Plan added in v0.2.0

type Plan string
const (
	PlanFree Plan = "free"
	PlanBeta Plan = "beta"
	PlanPro  Plan = "pro"
)

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.

func (*UsersHandler) Activate added in v0.3.1

func (h *UsersHandler) Activate(c *echo.Context) error

Activate handles POST /api/v1/users/me/activate. Sets activated_at on the user if not already set. Always returns 204 No Content.

func (*UsersHandler) GetMe added in v0.3.1

func (h *UsersHandler) GetMe(c *echo.Context) error

GetMe handles GET /api/v1/users/me. Returns the authenticated user's profile including their activation status.

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

func (r *UsersRepository) Activate(ctx context.Context, id uuid.UUID) (User, error)

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

func (r *UsersRepository) Create(ctx context.Context, user User) (User, error)

func (*UsersRepository) Delete

func (r *UsersRepository) Delete(ctx context.Context, id uuid.UUID) error

func (*UsersRepository) FindByEmail

func (r *UsersRepository) FindByEmail(ctx context.Context, email string) (User, error)

func (*UsersRepository) FindByID

func (r *UsersRepository) FindByID(ctx context.Context, id uuid.UUID) (User, error)

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

func (r *UsersRepository) Update(ctx context.Context, user User) (User, error)

func (*UsersRepository) UpdatePlan added in v0.4.0

func (r *UsersRepository) UpdatePlan(ctx context.Context, id uuid.UUID, plan Plan) error

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

func (s *UsersService) Activate(ctx context.Context, id uuid.UUID) (User, error)

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.

func (*UsersService) Create

func (s *UsersService) Create(ctx context.Context, user User) (User, error)

Create creates a new user.

func (*UsersService) Delete

func (s *UsersService) Delete(ctx context.Context, id uuid.UUID) error

Delete removes a user by ID.

func (*UsersService) GetByID added in v0.2.0

func (s *UsersService) GetByID(ctx context.Context, id uuid.UUID) (User, error)

GetByID looks up a user by their ID.

func (*UsersService) Update

func (s *UsersService) Update(ctx context.Context, user User) (User, error)

Update persists changes to an existing user.

Jump to

Keyboard shortcuts

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