model

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: May 3, 2017 License: Apache-2.0 Imports: 7 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CarShare

type CarShare struct {
	ID        bson.ObjectId `json:"-"    bson:"_id,omitempty"`
	Name      string        `json:"name" bson:"name"`
	Members   []*User       `json:"-"    bson:"-"`
	MemberIDs []string      `json:"-"    bson:"members"`
	Admins    []*User       `json:"-"    bson:"-"`
	AdminIDs  []string      `json:"-"    bson:"admins"`
	Trips     []Trip        `json:"-"    bson:"-"`
	TripIDs   []string      `json:"-"    bson:"trips"`
}

CarShare an individual group of users who make up a car share

func (*CarShare) AddToManyIDs

func (cs *CarShare) AddToManyIDs(name string, IDs []string) error

AddToManyIDs adds some new trips

func (*CarShare) DeleteToManyIDs

func (cs *CarShare) DeleteToManyIDs(name string, IDs []string) error

DeleteToManyIDs removes some relationships from car shrae

func (CarShare) GetID

func (cs CarShare) GetID() string

GetID to satisfy jsonapi.MarshalIdentifier interface

func (CarShare) GetReferencedIDs

func (cs CarShare) GetReferencedIDs() []jsonapi.ReferenceID

GetReferencedIDs to satisfy the jsonapi.MarshalLinkedRelations interface

func (CarShare) GetReferencedStructs

func (cs CarShare) GetReferencedStructs() []jsonapi.MarshalIdentifier

GetReferencedStructs to satisfy the jsonapi.MarhsalIncludedRelations interface

func (CarShare) GetReferences

func (cs CarShare) GetReferences() []jsonapi.Reference

GetReferences to satisfy the jsonapi.MarshalReferences interface

func (*CarShare) IsAdmin added in v0.3.0

func (cs *CarShare) IsAdmin(userID string) bool

IsAdmin returns true if userID is in list of admins

func (*CarShare) IsMember added in v0.3.0

func (cs *CarShare) IsMember(userID string) bool

IsMember returns true if usreID is in list of members

func (*CarShare) SetID

func (cs *CarShare) SetID(id string) error

SetID to satisfy jsonapi.UnmarshalIdentifier interface

func (*CarShare) SetToManyReferenceIDs

func (cs *CarShare) SetToManyReferenceIDs(name string, IDs []string) error

SetToManyReferenceIDs sets the trips reference IDs and satisfies the jsonapi.UnmarshalToManyRelations interface

type Score

type Score struct {
	MetresAsDriver    int `json:"metres-as-driver"    bson:"metres-as-driver"`
	MetresAsPassenger int `json:"metres-as-passenger" bson:"metres-as-passenger"`
}

A score keeps track of how many miles a user has travelled as a driver and as a passenger

type Trip

type Trip struct {
	ID           bson.ObjectId    `json:"-"         bson:"_id,omitempty"`
	Metres       int              `json:"metres"    bson:"metres"`
	TimeStamp    time.Time        `json:"timestamp" bson:"timestamp"`
	CarShare     *CarShare        `json:"-"         bson:"-"`
	CarShareID   string           `json:"-"         bson:"car-share"`
	Driver       *User            `json:"-"         bson:"-"`
	DriverID     string           `json:"-"         bson:"driver"`
	Passengers   []*User          `json:"-"         bson:"-"`
	PassengerIDs []string         `json:"-"         bson:"passengers"`
	Scores       map[string]Score `json:"scores"    bson:"scores"`
}

Trip - a single instance of a car share

func (*Trip) AddToManyIDs

func (t *Trip) AddToManyIDs(name string, IDs []string) error

AddToManyIDs to satisfy jsonapi.AddToManyIDs

func (*Trip) CalculateScores

func (t *Trip) CalculateScores(scoresFromLastTrip map[string]Score) error

CalculateScores for the trip (basically the ratio between distance travelled as driver and as passenger)

func (*Trip) DeleteToManyIDs

func (t *Trip) DeleteToManyIDs(name string, IDs []string) error

DeleteToManyIDs to satisfy jsonapi.DeleteToManyIDs

func (Trip) GetID

func (t Trip) GetID() string

GetID to satisfy jsonapi.MarshalIdentifier interface

func (Trip) GetReferencedIDs

func (t Trip) GetReferencedIDs() []jsonapi.ReferenceID

GetReferencedIDs to satisfy jsonapi.MarshalLinkedRelations interface

func (Trip) GetReferencedStructs

func (t Trip) GetReferencedStructs() []jsonapi.MarshalIdentifier

GetReferencedStructs to satisfy jsonapi.MarshalIncludedRelations interface

func (Trip) GetReferences

func (t Trip) GetReferences() []jsonapi.Reference

GetReferences to satisfy jsonapi.MarshalReferences interface

func (*Trip) SetID

func (t *Trip) SetID(id string) error

SetID to satisfy jsonapi.UnmarshalIdentifier interface

func (*Trip) SetToManyReferenceIDs

func (t *Trip) SetToManyReferenceIDs(name string, IDs []string) error

SetToManyReferenceIDs to satisfy jsonapi.UnmarshalToManyRelations

func (*Trip) SetToOneReferenceID

func (t *Trip) SetToOneReferenceID(name, ID string) error

SetToOneReferenceID to satisfy jsonapi.UnmarshalToOneRelations interface

type User

type User struct {
	ID bson.ObjectId `json:"-" bson:"_id,omitempty"`

	// users linked to firebase
	FirebaseUID string `json:"-"             bson:"firebase-uid"`
	DisplayName string `json:"display-name"  bson:"display-name"`
	Email       string `json:"-"             bson:"email"`
	PhotoURL    string `json:"photo-url"     bson:"photo-url"`
	IsAnon      bool   `json:"is-anon"       bson:"is-anon"`

	// Used for non firebase users created specifically for a car share
	LinkedCarShareID string   `json:"-" bson:"linked-carshare"`
	LinkedCarShare   CarShare `json:"-" bson:"-"`
}

User of the system

func (User) GetID

func (u User) GetID() string

GetID to satisfy jsonapi.MarshalIdentifier interface

func (*User) SetID

func (u *User) SetID(id string) error

SetID to satisfy jsonapi.UnmarshalIdentifier interface

Jump to

Keyboard shortcuts

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