userutils

package
v1.8.5 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UpdateUserCount

func UpdateUserCount()

UpdateUserCount refreshes user metrics

Types

type ArtistsStruct

type ArtistsStruct []TopArtist

func (*ArtistsStruct) Scan

func (sla *ArtistsStruct) Scan(value interface{}) error

func (ArtistsStruct) Value

func (sla ArtistsStruct) Value() (driver.Value, error)

type CompareStruct

type CompareStruct struct {
	Artists []TopArtist
	Tracks  []TopTrack
	Genres  []string
	Score   float32
}

type FriendsStruct

type FriendsStruct []string

func (*FriendsStruct) Scan

func (sla *FriendsStruct) Scan(value interface{}) error

func (FriendsStruct) Value

func (sla FriendsStruct) Value() (driver.Value, error)

type GenresStruct

type GenresStruct []string

func (*GenresStruct) Scan

func (sla *GenresStruct) Scan(value interface{}) error

func (GenresStruct) Value

func (sla GenresStruct) Value() (driver.Value, error)

type Playlist

type Playlist struct {
	ID   string
	Name string
}

type PlaylistsStruct

type PlaylistsStruct []Playlist

func (*PlaylistsStruct) Scan

func (sla *PlaylistsStruct) Scan(value interface{}) error

func (PlaylistsStruct) Value

func (sla PlaylistsStruct) Value() (driver.Value, error)

type RecentTracks

type RecentTracks struct {
	ID         uint `gorm:"primarykey"`
	User       uint `gorm:"index"`
	Track      string
	ListenedAt int64 `gorm:"index,autoCreateTime"`
}

type RecentTracksStatisticsStruct

type RecentTracksStatisticsStruct struct {
	Count         int
	TopTracks     []RecentTracksStatisticsStructTrack
	Hours         map[int]int
	Days          map[int]int
	TotalListened int
}

type RecentTracksStatisticsStructTrack

type RecentTracksStatisticsStructTrack struct {
	Count  int
	Name   string
	Artist string
	Image  string
	URI    string
}

type RecentTracksTimerStruct

type RecentTracksTimerStruct struct {
	UserID string
	Lock   *chan struct{}
}

type TopArtist

type TopArtist struct {
	Name  string
	Image string
	ID    string
}

type TopStruct

type TopStruct struct {
	Genres  GenresStruct
	Updated int64
	Artists ArtistsStruct
	Tracks  TracksStruct
}

type TopTrack

type TopTrack struct {
	Artist     string
	Name       string
	Image      string
	ID         string
	Duration   int
	PreviewURL string
}

type TracksStruct

type TracksStruct []TopTrack

func (*TracksStruct) Scan

func (sla *TracksStruct) Scan(value interface{}) error

func (TracksStruct) Value

func (sla TracksStruct) Value() (driver.Value, error)

type User

type User struct {
	ID          uint           `gorm:"primarykey" json:"-"`
	CreatedAt   time.Time      `json:"-"`
	DeletedAt   gorm.DeletedAt `gorm:"index" json:"-"`
	UserID      string         `gorm:"unique"`
	DisplayName string
	Token       *oauth2.Token `gorm:"embedded;embeddedPrefix:token_" json:"-"`
	Image       string
	Playlists   PlaylistsStruct
	LastUpdated time.Time    `json:"-"`
	Settings    UserSettings `gorm:"embedded;embeddedPrefix:settings_"`
	Top         TopStruct    `gorm:"embedded;embeddedPrefix:top_"`
	CompareCode string       `gorm:"unique"`
	Friends     FriendsStruct
}

User is the main user struct

func GetUser

func GetUser(ID string) *User

GetUser gets the user from the database by ID

func GetUserFromCompareCode

func GetUserFromCompareCode(code string) *User

GetUser gets the user from the database by Compare Code

func (*User) AddFriend

func (u *User) AddFriend(target *User)

AddFriend appends a friend to a user's friend list and otherwise

func (*User) Client

func (u *User) Client() *spotify.Client

func (*User) Compare

func (u *User) Compare(target *User) CompareStruct

Compares two users and returns the result

func (*User) GetFriends

func (u *User) GetFriends() []*User

GetFriends returns a user's friends

func (*User) GetPlaylistTracks

func (u *User) GetPlaylistTracks(ID string, cl spotify.Client) ([]*tracks.Track, error)

GetPlaylistTracks returns a list of tracks for a given playlist

func (*User) GetRecentTrackSince

func (u *User) GetRecentTrackSince(t time.Time) []RecentTracks

func (*User) GetRecentTracks

func (u *User) GetRecentTracks() ([]*tracks.Track, error)

func (*User) RecentTracksStatistics

func (u *User) RecentTracksStatistics(t time.Time) RecentTracksStatisticsStruct

func (*User) RefreshToken

func (u *User) RefreshToken() error

RefreshToken refreshes the user's token

func (*User) RefreshTop

func (u *User) RefreshTop() error

RefreshTop updates the user's top

func (*User) RefreshUser

func (u *User) RefreshUser() error

RefreshUser refreshes the user's information

func (*User) RemoveFriend

func (u *User) RemoveFriend(target *User)

RemoveFriend removes a friend from a user's friend list and back

func (*User) Save

func (u *User) Save() error

Save

func (*User) StartRecentTracksUpdater

func (u *User) StartRecentTracksUpdater()

func (*User) StopRecentTracksUpdater

func (u *User) StopRecentTracksUpdater()

func (*User) String

func (u *User) String() string

func (*User) UpdateRecentTracks

func (u *User) UpdateRecentTracks()

UpdateRecentTracks updates the recent tracks

type UserSettings

type UserSettings struct {
	RecentTracks bool `gorm:"default:false"`
}

Jump to

Keyboard shortcuts

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