trips

package
v0.19.10 Latest Latest
Warning

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

Go to latest
Published: May 16, 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

This section is empty.

Variables

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"`
}

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