store

package
v0.0.0-...-389ba5e Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
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"
)
View Source
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 Output

type Output struct {
	Name        string
	Description string
	Public      bool
}

Output configures the user facing result of a newly built 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

func (p *Playlist) MarshalInput() error

MarshalInput packs a input object into a JSON string

func (*Playlist) UnmarshalInput

func (p *Playlist) UnmarshalInput() error

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 New

func New(db *sqlx.DB) *Postgres

New returns a new Postgres struct using the given DB

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

func (p *Postgres) DeletePlaylist(id uuid.UUID) error

DeletePlaylist deletes the playlist entry matching the given id

func (*Postgres) GetAllPlaylists

func (p *Postgres) GetAllPlaylists() ([]Playlist, error)

GetAllPlaylists returns all stored playlists

func (*Postgres) GetPlaylist

func (p *Postgres) GetPlaylist(id uuid.UUID) (*Playlist, error)

GetPlaylist returns the playlist with a given id

func (*Postgres) GetPlaylists

func (p *Postgres) GetPlaylists(userID uuid.UUID) ([]Playlist, error)

GetPlaylists retrieves all the playlists associated with a given userID

func (*Postgres) GetSessionExpiry

func (p *Postgres) GetSessionExpiry(sessionToken string) (*time.Time, error)

GetSessionExpiry returns the expiry time of a sessionToken

func (*Postgres) GetUserByID

func (p *Postgres) GetUserByID(id uuid.UUID) (*User, error)

GetUserByID returns a User matching the given id

func (*Postgres) GetUserBySpotifyID

func (p *Postgres) GetUserBySpotifyID(spotifyID string) (*User, error)

GetUserBySpotifyID returns a User matching the given spotifyID

func (*Postgres) GetUserID

func (p *Postgres) GetUserID(sessionToken string) (*uuid.UUID, error)

GetUserID returns the UUID for a user based off of a session token

func (*Postgres) IncrementUserBuildCount

func (p *Postgres) IncrementUserBuildCount(userID uuid.UUID) error

IncrementUserBuildCount increments playlists_built by one for the given userID

func (*Postgres) UpdatePlaylistBadBuild

func (p *Postgres) UpdatePlaylistBadBuild(id uuid.UUID, failureMsg string) error

UpdatePlaylistBadBuild updates a playlist entry after a failed build of a playlist

func (*Postgres) UpdatePlaylistBadDelete

func (p *Postgres) UpdatePlaylistBadDelete(id uuid.UUID, failureMsg string) error

UpdatePlaylistBadDelete updates a playlist entry after a failed delete of a playlist

func (*Postgres) UpdatePlaylistConfig

func (p *Postgres) UpdatePlaylistConfig(id uuid.UUID, playlist Playlist) error

UpdatePlaylistConfig updates the part of a playlist row that configures how Spotify playlists are built

func (*Postgres) UpdatePlaylistGoodBuild

func (p *Postgres) UpdatePlaylistGoodBuild(id uuid.UUID, spotifyID string) error

UpdatePlaylistGoodBuild updates a playlist entry after a successful build of the playlist

func (*Postgres) UpdatePlaylistStartBuild

func (p *Postgres) UpdatePlaylistStartBuild(id uuid.UUID) error

UpdatePlaylistStartBuild sets a playlists building boolean to true

func (*Postgres) UpdateUser

func (p *Postgres) UpdateUser(spotifyID, sessionToken string, sessionExpiry time.Time, token oauth2.Token) error

UpdateUser updates an existing user with new sesion and oauth2 token data

func (*Postgres) UserExists

func (p *Postgres) UserExists(spotifyID string) (bool, error)

UserExists determines if there is a user for the give spotifyID already

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

Jump to

Keyboard shortcuts

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