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
- Variables
- type Factory
- type SavedTrip
- type Store
- func (s *Store) Close() error
- func (s *Store) Create(ctx context.Context, name string, inputs, plan, advice json.RawMessage) (*SavedTrip, error)
- func (s *Store) Delete(ctx context.Context, id uuid.UUID) error
- func (s *Store) Get(ctx context.Context, id uuid.UUID) (*SavedTrip, error)
- func (s *Store) List(ctx context.Context) ([]SavedTrip, error)
- func (s *Store) Update(ctx context.Context, id uuid.UUID, name string, ...) (*SavedTrip, error)
Constants ¶
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 ¶
var ErrLimit = errors.New("trips: saved trip limit reached")
ErrLimit is returned by Create when the account already keeps MaxPerUser trips.
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.
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 (*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 ¶
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 ¶
Get returns a single saved trip by id, scoped to this user. Returns ErrNotFound when the row is missing or belongs to someone else.