Documentation
¶
Index ¶
- Constants
- type ExtractMethod
- type Input
- type Output
- type Playlist
- type Postgres
- func (p *Postgres) CreatePlaylist(userID uuid.UUID, input Input, name, description string, public bool, ...) error
- func (p *Postgres) CreateUser(spotifyID, sessionToken string, sessionExpiry time.Time, token oauth2.Token) error
- func (p *Postgres) DeletePlaylist(id uuid.UUID) error
- func (p *Postgres) GetAllPlaylists() ([]Playlist, error)
- func (p *Postgres) GetPlaylist(id uuid.UUID) (*Playlist, error)
- func (p *Postgres) GetPlaylists(userID uuid.UUID) ([]Playlist, error)
- func (p *Postgres) GetSessionExpiry(sessionToken string) (*time.Time, error)
- func (p *Postgres) GetUserByID(id uuid.UUID) (*User, error)
- func (p *Postgres) GetUserBySpotifyID(spotifyID string) (*User, error)
- func (p *Postgres) GetUserID(sessionToken string) (*uuid.UUID, error)
- func (p *Postgres) IncrementUserBuildCount(userID uuid.UUID) error
- func (p *Postgres) UpdatePlaylistBadBuild(id uuid.UUID, failureMsg string) error
- func (p *Postgres) UpdatePlaylistBadDelete(id uuid.UUID, failureMsg string) error
- func (p *Postgres) UpdatePlaylistConfig(id uuid.UUID, playlist Playlist) error
- func (p *Postgres) UpdatePlaylistGoodBuild(id uuid.UUID, spotifyID string) error
- func (p *Postgres) UpdatePlaylistStartBuild(id uuid.UUID) error
- func (p *Postgres) UpdateUser(spotifyID, sessionToken string, sessionExpiry time.Time, token oauth2.Token) error
- func (p *Postgres) UserExists(spotifyID string) (bool, error)
- type Schedule
- type Store
- type TrackSource
- type TrackSourceType
- type User
Constants ¶
const ( // Never automatically build playlist Never Schedule = "Never" // Daily build the playlist Daily = "Daily" // Weekly build the playlist Weekly = "Weekly" // BiWeekly build the playlist BiWeekly = "Bi-Weekly" // Monthly build the playlist Monthly = "Monthly" )
const ( // LikedSrc pulls tracks from Liked Songs LikedSrc TrackSourceType = "Liked" // AlbumSrc pulls tracks from an album AlbumSrc = "Album" // PlaylistSrc pulls tracks from a playlist PlaylistSrc = "Playlist" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ExtractMethod ¶
type ExtractMethod string
ExtractMethod is the means by which the server pulls songs from a track source
const ( // Randomly songs are chosen from the source Randomly ExtractMethod = "Randomly" // Latest songs are chosen from the source Latest = "Latest" )
type Input ¶
type Input struct {
TrackSources []TrackSource `json:"trackSources"`
}
Input configures the sources used to generate a new Spotify playlist
type Playlist ¶
type Playlist struct {
ID uuid.UUID `db:"id"`
UserID uuid.UUID `db:"user_id"`
Input Input
InputString string `db:"input"`
Name string `db:"name"`
Description string `db:"description"`
Public bool `db:"public"`
Schedule Schedule `db:"schedule"`
SpotifyID *string `db:"spotify_id"`
FailureMsg *string `db:"failure_msg"`
Building bool `db:"building"`
Current bool `db:"current"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
LastBuiltAt *time.Time `db:"last_built_at"`
}
Playlist is the configuration used to build a new Spotify playlist
func (*Playlist) MarshalInput ¶
MarshalInput packs a input object into a JSON string
func (*Playlist) UnmarshalInput ¶
UnmarshalInput unpacks a JSON string into an input object
type Postgres ¶
type Postgres struct {
// contains filtered or unexported fields
}
Postgres is the concrete implementation of Store backed by PostgreSQL
func (*Postgres) CreatePlaylist ¶
func (p *Postgres) CreatePlaylist(userID uuid.UUID, input Input, name, description string, public bool, schedule Schedule) error
CreatePlaylist inserts a new playlist into the DB
func (*Postgres) CreateUser ¶
func (p *Postgres) CreateUser(spotifyID, sessionToken string, sessionExpiry time.Time, token oauth2.Token) error
CreateUser creates a new user row in the DB
func (*Postgres) DeletePlaylist ¶
DeletePlaylist deletes the playlist entry matching the given id
func (*Postgres) GetAllPlaylists ¶
GetAllPlaylists returns all stored playlists
func (*Postgres) GetPlaylist ¶
GetPlaylist returns the playlist with a given id
func (*Postgres) GetPlaylists ¶
GetPlaylists retrieves all the playlists associated with a given userID
func (*Postgres) GetSessionExpiry ¶
GetSessionExpiry returns the expiry time of a sessionToken
func (*Postgres) GetUserByID ¶
GetUserByID returns a User matching the given id
func (*Postgres) GetUserBySpotifyID ¶
GetUserBySpotifyID returns a User matching the given spotifyID
func (*Postgres) IncrementUserBuildCount ¶
IncrementUserBuildCount increments playlists_built by one for the given userID
func (*Postgres) UpdatePlaylistBadBuild ¶
UpdatePlaylistBadBuild updates a playlist entry after a failed build of a playlist
func (*Postgres) UpdatePlaylistBadDelete ¶
UpdatePlaylistBadDelete updates a playlist entry after a failed delete of a playlist
func (*Postgres) UpdatePlaylistConfig ¶
UpdatePlaylistConfig updates the part of a playlist row that configures how Spotify playlists are built
func (*Postgres) UpdatePlaylistGoodBuild ¶
UpdatePlaylistGoodBuild updates a playlist entry after a successful build of the playlist
func (*Postgres) UpdatePlaylistStartBuild ¶
UpdatePlaylistStartBuild sets a playlists building boolean to true
type Schedule ¶
type Schedule string
Schedule is how often spotify playlists are automatically built
type Store ¶
type Store interface {
// Users
GetUserByID(id uuid.UUID) (*User, error)
GetUserBySpotifyID(spotifyID string) (*User, error)
GetUserID(sessionToken string) (*uuid.UUID, error)
UserExists(spotifyID string) (bool, error)
GetSessionExpiry(sessionToken string) (*time.Time, error)
CreateUser(spotifyID, sessionToken string, sessionExpiry time.Time, token oauth2.Token) error
UpdateUser(spotifyID, sessionToken string, sessionExpiry time.Time, token oauth2.Token) error
IncrementUserBuildCount(userID uuid.UUID) error
// Playlists
CreatePlaylist(userID uuid.UUID, input Input, name, description string, public bool, schedule Schedule) error
UpdatePlaylistConfig(id uuid.UUID, playlist Playlist) error
GetPlaylist(id uuid.UUID) (*Playlist, error)
GetPlaylists(userID uuid.UUID) ([]Playlist, error)
GetAllPlaylists() ([]Playlist, error)
UpdatePlaylistGoodBuild(id uuid.UUID, spotifyID string) error
UpdatePlaylistBadBuild(id uuid.UUID, failureMsg string) error
UpdatePlaylistStartBuild(id uuid.UUID) error
DeletePlaylist(id uuid.UUID) error
UpdatePlaylistBadDelete(id uuid.UUID, failureMsg string) error
}
Store provides methods for getting data on users, playlists, and more
type TrackSource ¶
type TrackSource struct {
Name string `json:"name"`
ID string `json:"id"`
Type TrackSourceType `json:"type"`
Count int `json:"count"`
Method ExtractMethod `json:"method"`
ImageURL string // Not serialized and stored in DB, only used to display in UI
}
TrackSource represents a single source of tracks for a generated Spotify playlist
func (TrackSource) StringifyMethod ¶
func (t TrackSource) StringifyMethod() string
StringifyMethod returns a string version of an extraction method
type TrackSourceType ¶
type TrackSourceType string
TrackSourceType is an enumeration of the possible track sources for a playlist
type User ¶
type User struct {
ID uuid.UUID `db:"id"`
SpotifyID string `db:"spotify_id"`
PlaylistsBuilt int `db:"playlists_built"`
SessionToken string `db:"session_token"`
SessionExpiry time.Time `db:"session_expiry"`
Token oauth2.Token
AccessToken string `db:"access_token"`
RefreshToken string `db:"refresh_token"`
TokenType string `db:"token_type"`
TokenExpiry time.Time `db:"token_expiry"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
}
User is the metadata for a corresponding Spotify user
func (*User) MarshalToken ¶
func (u *User) MarshalToken()
MarshalToken unpacks the Token field into the token db mapping fields
func (*User) UnmarshalToken ¶
func (u *User) UnmarshalToken()
UnmarshalToken packs the token db mapping fields into the Token field