Skip to content

Commit

Permalink
added creed
Browse files Browse the repository at this point in the history
  • Loading branch information
th0rn0 committed Sep 27, 2024
1 parent 539cd9e commit 558ec2c
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions api/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,42 @@ func getNextSongExcludeURI(excludeUri spotify.URI) (Track, error) {

func getNextSongRandom() (Track, error) {
var track Track
if err := db.Raw("SELECT * FROM tracks ORDER BY random()").First(&track).Error; err != nil {
track, err := getNextCreedSong()
if err != nil {
if err := db.Raw("SELECT * FROM tracks ORDER BY random()").First(&track).Error; err != nil {
return track, err
}
}
return track, nil
}

func getNextCreedSong() (Track, error) {
var track Track
if err := db.Raw("SELECT * FROM tracks WHERE artist == 'Creed' ORDER BY random()").First(&track).Error; err != nil {
return track, err
}
return track, nil
}

func getNextSongRandomExcludeURI(excludeUri spotify.URI) (Track, error) {
func getNextCreedSongExcludeURI(excludeUri spotify.URI) (Track, error) {
var track Track
if err := db.Raw("SELECT * FROM tracks WHERE uri != ? ORDER BY random()", excludeUri).First(&track).Error; err != nil {
if err := db.Raw("SELECT * FROM tracks WHERE artist == 'Creed' AND uri != ? ORDER BY random()", excludeUri).First(&track).Error; err != nil {
return track, err
}
return track, nil
}

func getNextSongRandomExcludeURI(excludeUri spotify.URI) (Track, error) {
var track Track
track, err := getNextCreedSongExcludeURI(excludeUri)
if err != nil {
if err := db.Raw("SELECT * FROM tracks WHERE uri != ? ORDER BY random()", excludeUri).First(&track).Error; err != nil {
return track, err
}
}
return track, nil
}

func getNextSongByVotes() (Track, error) {
var track Track
if err := db.Raw("SELECT * FROM tracks WHERE votes = ( SELECT MAX(votes) FROM tracks )").First(&track).Error; err != nil {
Expand Down

0 comments on commit 558ec2c

Please sign in to comment.