models

package
v0.0.0-...-bdb8bbd Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close()

Close will close the global MongoDB session

func CreateChallenge

func CreateChallenge(c Challenge) error

CreateChallenge creates a new challenge in database

func GetActiveChallenges

func GetActiveChallenges(userID int64) (*[]Challenge, error)

GetActiveChallenges get active challenges by user ID from database

func GetAllChallenges

func GetAllChallenges(userID int64) (*[]Challenge, error)

GetAllChallenges get all challenges for a user from database

func GetCompletedChallenges

func GetCompletedChallenges(userID int64) (*[]Challenge, error)

GetCompletedChallenges get completed challenges by user ID from database

func GetExpiredChallenges

func GetExpiredChallenges() (*[]Challenge, error)

GetExpiredChallenges get expired challenges from database

func GetPendingChallenges

func GetPendingChallenges(userID int64) (*[]Challenge, error)

GetPendingChallenges get pending challenges by user ID from database

func RemoveChallenge

func RemoveChallenge(id bson.ObjectId) error

RemoveChallenge removes a challenge from database

func RemoveSegment

func RemoveSegment(ID int64) error

RemoveSegment deletes segment from DB

func RemoveUser

func RemoveUser(ID int64) error

RemoveUser deletes user from DB

func UpdateChallengeStatus

func UpdateChallengeStatus(id bson.ObjectId, status string, updateTime time.Time) error

UpdateChallengeStatus updates the challenge

Types

type Challenge

type Challenge struct {
	ID         bson.ObjectId `bson:"_id,omitempty" json:"id"`
	Segment    *Segment      `bson:"segment" json:"segment"`
	Challenger *Opponent     `bson:"challenger" json:"challenger"`
	Challengee *Opponent     `bson:"challengee" json:"challengee"`
	Status     string        `bson:"status" json:"status"`
	Created    *time.Time    `bson:"created" json:"created,omitempty"`
	Expires    *time.Time    `bson:"expires" json:"expires,omitempty"`
	Completed  *time.Time    `bson:"completed" json:"completed,omitempty"`
	Expired    bool          `bson:"expired" json:"expired"`
	WinnerID   *int64        `bson:"winnerId" json:"winnerId,omitempty"`
	WinnerName *string       `bson:"winnerName" json:"winnerName,omitempty"`
	LoserID    *int64        `bson:"loserId" json:"loserId,omitempty"`
	LoserName  *string       `bson:"loserName" json:"loserName,omitempty"`
	CreatedAt  time.Time     `bson:"createdAt" json:"createdAt"`
	UpdatedAt  time.Time     `bson:"updatedAt" json:"updatedAt"`
	DeletedAt  *time.Time    `bson:"deletedAt" json:"deletedAt,omitempty"`
}

Challenge struct handles the database schema for a challenge

func GetChallengeByID

func GetChallengeByID(id bson.ObjectId) (*Challenge, error)

GetChallengeByID gets a single stored challenge from database

func (Challenge) UpdateChallenge

func (c Challenge) UpdateChallenge() error

UpdateChallenge updates a challenge from database

type Friend

type Friend struct {
	ID             int64  `bson:"_id" json:"id"`
	FirstName      string `bson:"firstname" json:"firstName"`
	LastName       string `bson:"lastname" json:"lastName"`
	FullName       string `bson:"fullName" json:"fullName"`
	Photo          string `bson:"photo" json:"photo"`
	ChallengeCount int    `bson:"challengeCount" json:"challengeCount"`
	Wins           int    `bson:"wins" json:"wins"`
	Losses         int    `bson:"losses" json:"losses"`
}

Friend struct handles the MongoDB schema for each users friends

type Map

type Map struct {
	ID       string `bson:"id" json:"id"`
	Polyline string `bson:"polyline" json:"polyline"`
}

Map struct handles the MongoDB schema for each segments map

type Opponent

type Opponent struct {
	ID               int64    `json:"id"`
	Name             string   `json:"name"`
	Photo            string   `json:"photo"`
	Completed        bool     `json:"completed"`
	Time             *int     `json:"time,omitempty"`
	AverageCadence   *float64 `json:"averageCadence,omitempty"`
	AverageWatts     *float64 `json:"averageWatts,omitempty"`
	AverageHeartRate *float64 `json:"averageHeartRate,omitempty"`
	MaxHeartRate     *float64 `json:"maxHeartRate,omitempty"`
}

Opponent struct handles the database schema for each users challenge effort

type Segment

type Segment struct {
	ID                 int64      `bson:"_id" json:"id"`
	Name               string     `bson:"name" json:"name"`
	ActivityType       string     `bson:"activityType" json:"activityType"`
	Distance           float64    `bson:"distance" json:"distance"`
	AverageGrade       float64    `bson:"averageGrade" json:"averageGrade"`
	MaximumGrade       float64    `bson:"maximumGrade" json:"maximumGrade"`
	ElevationHigh      float64    `bson:"elevationHigh" json:"elevationHigh"`
	ElevationLow       float64    `bson:"elevationLow" json:"elevationLow"`
	ClimbCategory      int        `bson:"climbCategory" json:"climbCategory"`
	City               string     `bson:"city" json:"city"`
	State              string     `bson:"state" json:"state"`
	Country            string     `bson:"country" json:"country"`
	TotalElevationGain float64    `bson:"totalElevationGain" json:"totalElevationGain"`
	StartLocation      [2]float64 `bson:"startLocation" json:"startLocation"`
	EndLocation        [2]float64 `bson:"endLocation" json:"endLocation"`
	Map                Map        `bson:"map" json:"map"`
	CreatedAt          time.Time  `bson:"createdAt" json:"createdAt"`
	UpdatedAt          time.Time  `bson:"updatedAt" json:"updatedAt"`
}

Segment struct handles the MongoDB schema for a segment

func GetSegmentByID

func GetSegmentByID(id int64) (*Segment, error)

GetSegmentByID gets a single stored segment from MongoDB

func SaveSegment

func SaveSegment(s *strava.SegmentDetailed) (*Segment, error)

SaveSegment stores a cached segment this prevents strava api rate limiting

func (Segment) UpdateSegment

func (segment Segment) UpdateSegment(s *strava.SegmentDetailed) (*Segment, error)

UpdateSegment stores a cached segment this prevents stale data from strava api rate limiting

type User

type User struct {
	ID             int64          `bson:"_id" json:"id"`
	FirstName      string         `bson:"firstname" json:"firstName"`
	LastName       string         `bson:"lastname" json:"lastName"`
	FullName       string         `bson:"fullname" json:"fullName"`
	City           string         `bson:"city" json:"city"`
	State          string         `bson:"state" json:"state"`
	Country        string         `bson:"country" json:"country"`
	Gender         string         `bson:"gender" json:"gender"`
	Token          string         `bson:"token" json:"token"`
	Photo          string         `bson:"photo" json:"photo"`
	Email          string         `bson:"email" json:"email"`
	Friends        []*Friend      `bson:"friends" json:"friends"`
	Segments       []*UserSegment `bson:"segments" json:"segments"`
	Wins           int            `bson:"wins" json:"wins"`
	Losses         int            `bson:"losses" json:"losses"`
	ChallengeCount int            `bson:"challengeCount" json:"challengeCount"`
	CreatedAt      time.Time      `bson:"createdAt" json:"createdAt,omitempty"`
	UpdatedAt      time.Time      `bson:"updatedAt" json:"updatedAt,omitempty"`
	DeletedAt      *time.Time     `bson:"deletedAt" json:"deletedAt,omitempty"`
}

User struct handles the MongoDB schema for a user

func CreateUser

func CreateUser(auth *strava.AuthorizationResponse) (*User, error)

CreateUser creates user in MongoDB

func GetAllUsers

func GetAllUsers() ([]User, error)

GetAllUsers returns all users from the DB

func GetUserByID

func GetUserByID(id int64) (*User, error)

GetUserByID gets a single stored user from MongoDB

func RegisterUser

func RegisterUser(auth *strava.AuthorizationResponse) (*User, error)

RegisterUser creates a user in MongoDB

func (*User) IncrementLosses

func (u *User) IncrementLosses(id int64) error

IncrementLosses increment losses and challenge count for a particular user by id

func (*User) IncrementSegments

func (u *User) IncrementSegments(id int64) error

IncrementSegments increment segment count for a particular user by id

func (*User) IncrementWins

func (u *User) IncrementWins(id int64) error

IncrementWins increment wins and challenge count for a particular user by id

func (User) RemoveFriendsSegmentsFromUser

func (u User) RemoveFriendsSegmentsFromUser() error

RemoveFriendsSegmentsFromUser modifies user in MongoDB

func (User) SaveUserFriends

func (u User) SaveUserFriends(friends []*Friend) error

SaveUserFriends save user friends

func (User) SaveUserSegments

func (u User) SaveUserSegments(segments []*UserSegment) error

SaveUserSegments save user segments

func (User) UpdateAthlete

func (u User) UpdateAthlete(athlete *strava.AthleteDetailed) (*User, error)

UpdateAthlete updates user in MongoDB

func (User) UpdateUser

func (u User) UpdateUser(auth *strava.AuthorizationResponse) (*User, error)

UpdateUser updates user in MongoDB

type UserSegment

type UserSegment struct {
	ID           int64  `bson:"_id" json:"id"`
	Name         string `bson:"name" json:"name"`
	Count        int    `bson:"count" json:"count"`
	ActivityType string `bson:"activityType" json:"activityType"`
}

UserSegment struct handles the MongoDB schema for each users segments

Jump to

Keyboard shortcuts

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