Help us shape the future of Go! Take the 2026 Go Developer Survey

trips

package
v0.40.22 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package trips persists per-user named trip templates for the planner. Inputs are required; the last computed plan and AI advice are stored alongside as opaque JSON snapshots so the UI can render "the trip I saved last week" without a Rivian round-trip on click.

Index

Constants

View Source
const MaxPerUser = 100

MaxPerUser is how many saved trips one account may keep. A browser user never gets near it; the cap bounds what a leaked phone token can store.

Variables

View Source
var ErrLimit = errors.New("trips: saved trip limit reached")

ErrLimit is returned by Create when the account already keeps MaxPerUser trips.

View Source
var ErrNotFound = errors.New("trips: not found")

ErrNotFound is returned when Get/Delete/Update target a row that either does not exist or belongs to a different user.

Functions

This section is empty.

Types

type Factory

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

Factory hands out per-user *Store instances over a shared pool. Mirrors the push.Factory shape — the cache is just a routing convenience, the isolation lives in the (user_id = $1) predicates inside Store.

func NewFactory

func NewFactory(d *sql.DB) *Factory

NewFactory wraps the shared pool.

func (*Factory) For

func (f *Factory) For(userID uuid.UUID) *Store

For returns the *Store for userID, constructing one on first sight. Returns nil when the factory or userID is zero; handlers should treat that as "not authenticated, refuse the request".

type SavedTrip

type SavedTrip struct {
	ID        uuid.UUID       `json:"id"`
	Name      string          `json:"name"`
	Inputs    json.RawMessage `json:"inputs"`
	Plan      json.RawMessage `json:"plan,omitempty"`
	Advice    json.RawMessage `json:"advice,omitempty"`
	CreatedAt time.Time       `json:"created_at"`
	UpdatedAt time.Time       `json:"updated_at"`
	// ReadOnly is set on the list of a free account for a trip past the free plan's cap: it can be viewed and deleted, not edited.
	ReadOnly bool `json:"read_only,omitempty"`
}

SavedTrip is one row of saved_trips. Inputs/Plan/Advice are kept as json.RawMessage so the package stays decoupled from rivian.TripPlan and the frontend shape — handlers can read/write them verbatim.

type Store

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

Store wraps access to saved_trips for a single user.

func OpenStore

func OpenStore(db *sql.DB, userID uuid.UUID) (*Store, error)

OpenStore binds a pooled connection to a user_id. The pool is owned by the caller.

func (*Store) Close

func (s *Store) Close() error

Close is a no-op; the pool is managed by main.

func (*Store) Count added in v0.40.16

func (s *Store) Count(ctx context.Context) (int, error)

Count is how many saved trips the account keeps.

func (*Store) Create

func (s *Store) Create(ctx context.Context, name string, inputs, plan, advice json.RawMessage) (*SavedTrip, error)

Create inserts a new trip under (user_id, name). Returns the generated UUID + timestamps. The unique (user_id, name) constraint turns a duplicate name into a Postgres unique-violation error; the caller (handler) is responsible for surfacing that as 409.

func (*Store) Delete

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

Delete removes a saved trip by id. Returns ErrNotFound if no row matched so callers can return 404 instead of a silent 204.

func (*Store) Get

func (s *Store) Get(ctx context.Context, id uuid.UUID) (*SavedTrip, error)

Get returns a single saved trip by id, scoped to this user. Returns ErrNotFound when the row is missing or belongs to someone else.

func (*Store) List

func (s *Store) List(ctx context.Context) ([]SavedTrip, error)

List returns every saved trip for this user, most-recently-updated first. The inputs / plan / advice JSON is returned untouched.

func (*Store) Recent added in v0.40.16

func (s *Store) Recent(ctx context.Context, n int) (map[uuid.UUID]bool, error)

Recent returns the ids of the n most recently updated trips (ties broken by id, so the answer is stable).

func (*Store) Update

func (s *Store) Update(ctx context.Context, id uuid.UUID, name string, inputs, plan, advice json.RawMessage) (*SavedTrip, error)

Update overwrites name + inputs + plan + advice on an existing row. Returns ErrNotFound if the id doesn't belong to this user.

Jump to

Keyboard shortcuts

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