firstscreen

package
v0.41.10-rc.2 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package firstscreen reads what the first screen of a new account shows (design first-screen §2): Postgres only, never Rivian. Every query filters on user_id and is bounded: an indexed range per user, a LIMIT of 10000 rows for a count, or a LIMIT 1.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Counts

type Counts struct {
	Drives  int `json:"drives"`
	Charges int `json:"charges"`
}

Counts are capped row counts (at most 10000: the client says "10,000+").

type Currency

type Currency struct {
	Currency     string  `json:"currency"`
	Sessions     int     `json:"sessions"`
	HomeSessions int     `json:"home_sessions"`
	KWh          float64 `json:"kwh"`
	Billed       float64 `json:"billed"`
}

Currency is one currency's totals. A home session with no price counts in HomeSessions and adds nothing to Billed.

type Data

type Data struct {
	// Vehicles is how many vehicles the account has. Receipts are per account, not per vehicle: with more than one the card says
	// "on your Rivian account".
	Vehicles int `json:"vehicles"`
	// OdometerMi is the last recorded odometer (the earlier owner's miles included on a used truck); nil before any state is recorded.
	OdometerMi *float64 `json:"odometer_mi"`
	Recorded   Counts   `json:"recorded"`
	Imported   Counts   `json:"imported"`
	// FirstRecordedChargeAt is when the first live-recorded charge started, so the client knows when two weeks of charges exist.
	FirstRecordedChargeAt *time.Time `json:"first_recorded_charge_at"`
	Receipts              Receipts   `json:"receipts"`
}

Data is the endpoint's body.

type NamedCount

type NamedCount struct {
	Name     string `json:"name"`
	Sessions int    `json:"sessions"`
}

NamedCount is a vendor or a city and how many sessions.

type Receipts

type Receipts struct {
	OptIn bool `json:"opt_in"`
	// State: "off" (not opted in), "waiting" (opted in, the first pass has not finished), "error" (it failed and nothing is stored yet),
	// "empty" (it finished and Rivian returned none), "ready".
	State         string       `json:"state"`
	Sessions      int          `json:"sessions"`
	FirstMonth    string       `json:"first_month,omitempty"` // YYYY-MM of the first session
	Currencies    []Currency   `json:"currencies"`
	TopVendors    []NamedCount `json:"top_vendors"`
	TopCities     []NamedCount `json:"top_cities"`
	LastSuccessAt *time.Time   `json:"last_success_at"`
}

Receipts is the "billed by Rivian" card. Without the user's opt-in it holds only OptIn false and nothing is read.

type Store

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

Store reads the first screen.

func New

func New(db *sql.DB) *Store

New wraps a pool.

func (*Store) FirstScreen

func (s *Store) FirstScreen(ctx context.Context, uid uuid.UUID, receipts bool) (Data, error)

FirstScreen loads the data. receipts says whether the user opted in and the operator allows it; false reads nothing from the receipts tables.

Jump to

Keyboard shortcuts

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