consumption

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Consumption

type Consumption struct {
	TeaID uuid.UUID
	Time  time.Time
}

Consumption represents a single tea consumption event.

type FDBStore added in v1.3.2

type FDBStore struct {
	// contains filtered or unexported fields
}

FDBStore is a FoundationDB-backed implementation of Store.

func NewFDBStore added in v1.3.2

func NewFDBStore(db fdbclient.Database, retention time.Duration) *FDBStore

NewFDBStore creates a FoundationDB-backed consumption store with the given retention window. If retention <= 0, a default of 30 days is used.

func (*FDBStore) Recent added in v1.3.2

func (s *FDBStore) Recent(ctx context.Context, userID uuid.UUID, since time.Time) ([]Consumption, error)

Recent returns consumption events for userID since the given time (inclusive), ordered from most recent to oldest.

func (*FDBStore) Record added in v1.3.2

func (s *FDBStore) Record(ctx context.Context, userID uuid.UUID, teaID uuid.UUID, ts time.Time) error

Record writes a consumption entry for the given user and tea at the provided time. It also trims keys older than the retention window.

type MemoryStore

type MemoryStore struct {
	// contains filtered or unexported fields
}

MemoryStore is a simple in-memory implementation of Store. It is process-local and not persisted across restarts.

func NewMemoryStore

func NewMemoryStore(retention time.Duration) *MemoryStore

func (*MemoryStore) Recent

func (m *MemoryStore) Recent(_ context.Context, userID uuid.UUID, since time.Time) ([]Consumption, error)

func (*MemoryStore) Record

func (m *MemoryStore) Record(_ context.Context, userID uuid.UUID, teaID uuid.UUID, ts time.Time) error

type Store

type Store interface {
	Record(ctx context.Context, userID uuid.UUID, teaID uuid.UUID, ts time.Time) error
	// Recent returns consumptions since the provided time (inclusive) for the given user.
	Recent(ctx context.Context, userID uuid.UUID, since time.Time) ([]Consumption, error)
}

Store defines operations for recording and querying recent tea consumption.

Jump to

Keyboard shortcuts

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