Skip to content

Commit

Permalink
Nickelback clause added
Browse files Browse the repository at this point in the history
  • Loading branch information
th0rn0 committed Sep 27, 2024
1 parent 829a7f7 commit 683f999
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions api/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func getNextSongExcludeURI(excludeUri spotify.URI) (Track, error) {

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

func getNextCreedSong() (Track, error) {
func getNextSongRandomExcludeURI(excludeUri spotify.URI) (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
track, err := getNextButtRockSongExcludeURI(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 getNextCreedSongExcludeURI(excludeUri spotify.URI) (Track, error) {
func getNextSongByVotes() (Track, error) {
var track Track
if err := db.Raw("SELECT * FROM tracks WHERE artist == 'Creed' AND uri != ? ORDER BY random()", excludeUri).First(&track).Error; err != nil {
if err := db.Raw("SELECT * FROM tracks WHERE votes = ( SELECT MAX(votes) FROM tracks )").First(&track).Error; err != nil {
return track, err
}
return track, nil
}

func getNextSongRandomExcludeURI(excludeUri spotify.URI) (Track, error) {
func getNextSongByVotesExcludeURI(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
}
if err := db.Raw("SELECT * FROM tracks WHERE votes = ( SELECT MAX(votes) FROM tracks ) AND uri != ?", excludeUri).First(&track).Error; err != nil {
return track, err
}
return track, nil
}

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

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

0 comments on commit 683f999

Please sign in to comment.