Fixed some bugs and added Random Classic

This commit is contained in:
2024-07-28 15:58:12 +02:00
parent 59f1e2c75c
commit 51a74a9ed1
12 changed files with 152 additions and 16 deletions

View File

@@ -20,9 +20,34 @@ func GetGameName(gameId int) string {
return gameName
}
func GetGameById(gameId int) models.GameData {
var id, timesPlayed int
var numberOfSongs pgtype.Int4
var gameName, path string
var added, deleted, lastChanged, lastPlayed pgtype.Timestamp
err := pool.QueryRow(context.Background(),
"SELECT id, game_name, added, deleted, last_changed, path, times_played, last_played, number_of_songs "+
"FROM game WHERE id = $1", gameId).Scan(&id, &gameName, &added, &deleted, &lastChanged, &path, &timesPlayed, &lastPlayed, &numberOfSongs)
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "QueryRow failed: %v\n", err)
return models.GameData{}
}
return models.GameData{
Id: id,
GameName: gameName,
Added: added.Time,
Deleted: deleted.Time,
LastChanged: lastChanged.Time,
Path: path,
TimesPlayed: timesPlayed,
LastPlayed: lastPlayed.Time,
NumberOfSongs: numberOfSongs.Int,
}
}
func SetGameDeletionDate() {
_, err := pool.Exec(context.Background(),
"UPDATE game SET deleted=$1", time.Now())
"UPDATE game SET deleted=$1 WHERE deleted IS NULL", time.Now())
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "Exec failed: %v\n", err)
}
@@ -94,7 +119,7 @@ func InsertGameWithExistingId(id int, name string, path string) {
func FindAllGames() []models.GameData {
rows, err := pool.Query(context.Background(),
"SELECT id, game_name, added, deleted, last_changed, path, times_played, last_played, number_of_songs "+
"FROM game "+
"FROM game WHERE deleted IS NULL"+
"ORDER BY game_name")
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "QueryRow failed: %v\n", err)