feat: Rename game to soundtrack throughout codebase
- Database migration: rename game table to soundtrack - Rename game_name to soundtrack_name, game_id to soundtrack_id - Update all SQL queries in soundtrack.sql, song.sql, song_list.sql, statistics.sql - Regenerate sqlc code (soundtrack.sql.go, song.sql.go, etc.) - Update backend: music.go, sync.go, statistics.go - Update server: musicHandler.go, syncHandler.go, routes.go - Update frontend: hello.go - Keep URL paths as /games for backward compatibility Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
+26
-26
@@ -22,7 +22,7 @@ type SongInfo struct {
|
||||
|
||||
var currentSong = -1
|
||||
|
||||
var gamesNew []repository.Game
|
||||
var gamesNew []repository.Soundtrack
|
||||
|
||||
var songQueNew []repository.Song
|
||||
|
||||
@@ -37,10 +37,10 @@ func initRepo() {
|
||||
}
|
||||
}
|
||||
|
||||
func getAllGames() []repository.Game {
|
||||
func getAllGames() []repository.Soundtrack {
|
||||
if len(gamesNew) == 0 {
|
||||
initRepo()
|
||||
gamesNew, _ = BackendRepo().FindAllGames(BackendCtx())
|
||||
gamesNew, _ = BackendRepo().FindAllSoundtracks(BackendCtx())
|
||||
}
|
||||
return gamesNew
|
||||
|
||||
@@ -59,7 +59,7 @@ func Reset() {
|
||||
songQueNew = nil
|
||||
currentSong = -1
|
||||
initRepo()
|
||||
gamesNew, _ = BackendRepo().FindAllGames(BackendCtx())
|
||||
gamesNew, _ = BackendRepo().FindAllSoundtracks(BackendCtx())
|
||||
}
|
||||
|
||||
func AddLatestToQue() {
|
||||
@@ -77,8 +77,8 @@ func AddLatestPlayed() {
|
||||
currentSongData := songQueNew[currentSong]
|
||||
|
||||
initRepo()
|
||||
BackendRepo().AddGamePlayed(BackendCtx(), currentSongData.GameID)
|
||||
BackendRepo().AddSongPlayed(BackendCtx(), repository.AddSongPlayedParams{GameID: currentSongData.GameID, SongName: currentSongData.SongName})
|
||||
BackendRepo().AddSoundtrackPlayed(BackendCtx(), currentSongData.SoundtrackID)
|
||||
BackendRepo().AddSongPlayed(BackendCtx(), repository.AddSongPlayedParams{SoundtrackID: currentSongData.SoundtrackID, SongName: currentSongData.SongName})
|
||||
}
|
||||
|
||||
func SetPlayed(songNumber int) {
|
||||
@@ -87,8 +87,8 @@ func SetPlayed(songNumber int) {
|
||||
}
|
||||
songData := songQueNew[songNumber]
|
||||
initRepo()
|
||||
BackendRepo().AddGamePlayed(BackendCtx(), songData.GameID)
|
||||
BackendRepo().AddSongPlayed(BackendCtx(), repository.AddSongPlayedParams{GameID: songData.GameID, SongName: songData.SongName})
|
||||
BackendRepo().AddSoundtrackPlayed(BackendCtx(), songData.SoundtrackID)
|
||||
BackendRepo().AddSongPlayed(BackendCtx(), repository.AddSongPlayedParams{SoundtrackID: songData.SoundtrackID, SongName: songData.SongName})
|
||||
}
|
||||
|
||||
func GetRandomSong() string {
|
||||
@@ -105,7 +105,7 @@ func GetRandomSong() string {
|
||||
func GetRandomSongLowChance() string {
|
||||
getAllGames()
|
||||
|
||||
var listOfGames []repository.Game
|
||||
var listOfGames []repository.Soundtrack
|
||||
|
||||
var averagePlayed = getAveragePlayed()
|
||||
|
||||
@@ -131,7 +131,7 @@ func GetRandomSongClassic() string {
|
||||
|
||||
var listOfAllSongs []repository.Song
|
||||
for _, game := range gamesNew {
|
||||
songList, _ := BackendRepo().FindSongsFromGame(BackendCtx(), game.ID)
|
||||
songList, _ := BackendRepo().FindSongsFromSoundtrack(BackendCtx(), game.ID)
|
||||
listOfAllSongs = append(listOfAllSongs, songList...)
|
||||
}
|
||||
|
||||
@@ -139,13 +139,13 @@ func GetRandomSongClassic() string {
|
||||
var song repository.Song
|
||||
for !songFound {
|
||||
song = listOfAllSongs[rand.Intn(len(listOfAllSongs))]
|
||||
gameData, err := BackendRepo().GetGameById(BackendCtx(), song.GameID)
|
||||
gameData, err := BackendRepo().GetSoundtrackById(BackendCtx(), song.SoundtrackID)
|
||||
|
||||
if err != nil {
|
||||
BackendRepo().RemoveBrokenSong(BackendCtx(), song.Path)
|
||||
logging.GetLogger().Warn("Song not found, removed from database",
|
||||
zap.String("song", song.SongName),
|
||||
zap.String("game", gameData.GameName),
|
||||
zap.String("game", gameData.SoundtrackName),
|
||||
zap.String("filename", *song.FileName))
|
||||
continue
|
||||
}
|
||||
@@ -157,7 +157,7 @@ func GetRandomSongClassic() string {
|
||||
BackendRepo().RemoveBrokenSong(BackendCtx(), song.Path)
|
||||
logging.GetLogger().Warn("Song not found, removed from database",
|
||||
zap.String("song", song.SongName),
|
||||
zap.String("game", gameData.GameName),
|
||||
zap.String("game", gameData.SoundtrackName),
|
||||
zap.String("filename", *song.FileName))
|
||||
} else {
|
||||
songFound = true
|
||||
@@ -180,7 +180,7 @@ func GetSongInfo() SongInfo {
|
||||
currentGameData := getCurrentGame(currentSongData)
|
||||
|
||||
return SongInfo{
|
||||
Game: currentGameData.GameName,
|
||||
Game: currentGameData.SoundtrackName,
|
||||
GamePlayed: currentGameData.TimesPlayed,
|
||||
Song: currentSongData.SongName,
|
||||
SongPlayed: currentSongData.TimesPlayed,
|
||||
@@ -195,7 +195,7 @@ func GetPlayedSongs() []SongInfo {
|
||||
for i, song := range songQueNew {
|
||||
gameData := getCurrentGame(song)
|
||||
songList = append(songList, SongInfo{
|
||||
Game: gameData.GameName,
|
||||
Game: gameData.SoundtrackName,
|
||||
GamePlayed: gameData.TimesPlayed,
|
||||
Song: song.SongName,
|
||||
SongPlayed: song.TimesPlayed,
|
||||
@@ -217,22 +217,22 @@ func GetSong(song string) string {
|
||||
return songData.Path
|
||||
}
|
||||
|
||||
func GetAllGames() []string {
|
||||
func GetAllSoundtracks() []string {
|
||||
getAllGames()
|
||||
|
||||
var jsonArray []string
|
||||
for _, game := range gamesNew {
|
||||
jsonArray = append(jsonArray, game.GameName)
|
||||
jsonArray = append(jsonArray, game.SoundtrackName)
|
||||
}
|
||||
return jsonArray
|
||||
}
|
||||
|
||||
func GetAllGamesRandom() []string {
|
||||
func GetAllSoundtracksRandom() []string {
|
||||
getAllGames()
|
||||
|
||||
var jsonArray []string
|
||||
for _, game := range gamesNew {
|
||||
jsonArray = append(jsonArray, game.GameName)
|
||||
jsonArray = append(jsonArray, game.SoundtrackName)
|
||||
}
|
||||
rand.Shuffle(len(jsonArray), func(i, j int) { jsonArray[i], jsonArray[j] = jsonArray[j], jsonArray[i] })
|
||||
return jsonArray
|
||||
@@ -266,12 +266,12 @@ func GetPreviousSong() string {
|
||||
}
|
||||
}
|
||||
|
||||
func getSongFromList(games []repository.Game) repository.Song {
|
||||
func getSongFromList(games []repository.Soundtrack) repository.Song {
|
||||
songFound := false
|
||||
var song repository.Song
|
||||
for !songFound {
|
||||
game := getRandomGame(games)
|
||||
songs, _ := BackendRepo().FindSongsFromGame(BackendCtx(), game.ID)
|
||||
songs, _ := BackendRepo().FindSongsFromSoundtrack(BackendCtx(), game.ID)
|
||||
if len(songs) == 0 {
|
||||
continue
|
||||
}
|
||||
@@ -285,7 +285,7 @@ func getSongFromList(games []repository.Game) repository.Song {
|
||||
BackendRepo().RemoveBrokenSong(BackendCtx(), song.Path)
|
||||
logging.GetLogger().Warn("Song not found, removed from database",
|
||||
zap.String("song", song.SongName),
|
||||
zap.String("game", game.GameName),
|
||||
zap.String("game", game.SoundtrackName),
|
||||
zap.Any("filename", song.FileName))
|
||||
} else {
|
||||
songFound = true
|
||||
@@ -299,13 +299,13 @@ func getSongFromList(games []repository.Game) repository.Song {
|
||||
return song
|
||||
}
|
||||
|
||||
func getCurrentGame(currentSongData repository.Song) repository.Game {
|
||||
func getCurrentGame(currentSongData repository.Song) repository.Soundtrack {
|
||||
for _, game := range gamesNew {
|
||||
if game.ID == currentSongData.GameID {
|
||||
if game.ID == currentSongData.SoundtrackID {
|
||||
return game
|
||||
}
|
||||
}
|
||||
return repository.Game{}
|
||||
return repository.Soundtrack{}
|
||||
}
|
||||
|
||||
func getAveragePlayed() int32 {
|
||||
@@ -317,6 +317,6 @@ func getAveragePlayed() int32 {
|
||||
return sum / int32(len(gamesNew))
|
||||
}
|
||||
|
||||
func getRandomGame(listOfGames []repository.Game) repository.Game {
|
||||
func getRandomGame(listOfGames []repository.Soundtrack) repository.Soundtrack {
|
||||
return listOfGames[rand.Intn(len(listOfGames))]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user