db

package
v0.0.0-...-3656f01 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2023 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package db contains Firestore-related constants, types, and helper functions.

Index

Constants

View Source
const (
	// Document paths in Cloud Firestore.
	AuthDocPath        = "global/auth"
	ConfigDocPath      = "global/config"
	IndexedDataDocPath = "global/indexedData"
	SortedDataDocPath  = "global/sortedData"

	// Collection paths in Cloud Firestore.
	InviteCollectionPath = "invites"
	TeamCollectionPath   = "teams"
	UserCollectionPath   = "users"
)

Variables

This section is empty.

Functions

func GetDoc

func GetDoc(ctx context.Context, ref *firestore.DocumentRef, out interface{}) error

GetDoc fetches a snapshot of the document at ref and decodes it into out, which should be a pointer to a struct representing the document.

Types

type Area

type Area struct {
	// ID contains a short name uniquely identifying the area, e.g. "el_bloque".
	ID string `firestore:"id,omitempty"`
	// Name contains the full area name, e.g. "El Bloque".
	Name string `firestore:"name"`
	// Routes optionally contains sorted routes.
	Routes []Route `firestore:"routes,omitempty"`
	// MPID contains the area's Mountain Project ID.
	MPID string `firestore:"mpId,omitempty"`
}

Area contains information about an area consisting of multiple routes.

type ClimbState

type ClimbState int

climbState describes whether and how a route was climbed.

const (
	NotClimbed ClimbState = iota
	Lead
	TopRope
)

type IndexedData

type IndexedData struct {
	// Areas contains all areas keyed by unique area ID, i.e. area.ID.
	// The area.ID and area.Routes fields are unset.
	Areas map[string]Area `firestore:"areas"`
	// Routes contains all routes keyed by unique route ID, i.e. route.ID.
	// The route.ID field is unset.
	Routes map[string]Route `firestore:"routes"`
}

IndexedData contains areas and routes optimized for lookup by ID. It corresponds to the document at indexedDataDocPath.

func NewIndexedData

func NewIndexedData(areas []Area, routes []Route) IndexedData

newIndexedData constructs an indexedData struct from the supplied areas and routes. The area.ID and route.ID fields are cleared (since those IDs are already used as keys).

type Route

type Route struct {
	// ID contains a short name uniquely identifying the route, e.g. "night_vision".
	ID string `firestore:"id,omitempty"`
	// Name contains the full route name, e.g. "Night Vision".
	Name string `firestore:"name"`
	// Area contains the ID of the area containing this route, i.e. area.ID.
	Area string `firestore:"area,omitempty"`
	// Grade contains the route's grade, e.g. "5.10b" or "5.11c/d".
	Grade string `firestore:"grade,omitempty"`
	// Lead contains the number of points awarded for leading the route.
	Lead int `firestore:"lead,omitempty"`
	// TR contains the number of points awarded for top-roping the route.
	TR int `firestore:"tr,omitempty"`
	// MPID contains the route's Mountain Project ID.
	MPID string `firestore:"mpId,omitempty"`
	// Route height in feet.
	Height int `firestore:"height,omitempty"`
}

Route contains information about an individual route.

type SortedData

type SortedData struct {
	// Areas contains areas in the order in which they were seen.
	// Each area's Routes field contains routes in the order in which they were seen.
	Areas []Area `firestore:"areas"`
}

SortedData holds sorted area and then route data. This format is structured to be easy to display in the app's routes view. It corresponds to the document at sortedDataDocPath.

func NewSortedData

func NewSortedData(areas []Area, routes []Route) (SortedData, error)

newSortedData constructs a sortedData struct from the supplied areas and routes. An error is returned if any areas don't contain routes or any routes reference undefined areas.

type Team

type Team struct {
	// Name contains the team's name.
	Name string `firestore:"name"`
	// Invite contains the team's invitation code.
	Invite string `firestore:"invite"`
	// Users contains information about the team's members, keyed by user ID.
	Users map[string]struct {
		// Name contains the user's name.
		Name string `firestore:"name"`
		// Climbs contains a map from route ID (see route.ID) to state.
		Climbs map[string]ClimbState `firestore:"climbs"`
	} `firestore:"users"`
}

Team contains information about a team. It correponds to documents in the collection at TeamCollectionPath.

type User

type User struct {
	// Name contains the user's name.
	Name string `firestore:"name"`
	// Climbs contains the user's climbs. It's only used if the user isn't on a team.
	Climbs map[string]ClimbState `firestore:"climbs"`
	// Team contains the user's team ID. It's empty if they aren't on a team.
	Team string `firestore:"team"`
}

User contains information about a user. It correponds to documents in the collection at UserCollectionPath.

Jump to

Keyboard shortcuts

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