Fixed some bugs and added Random Classic
This commit is contained in:
46
pkg/db/songList.go
Normal file
46
pkg/db/songList.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"music-server/pkg/models"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
func InsertSongInList(song models.SongListData) {
|
||||
err := pool.QueryRow(context.Background(),
|
||||
`INSERT INTO song_list (match_date, match_id, song_no, game_name, song_name) VALUES ($1, $2, $3, $4, $5)`,
|
||||
song.MatchDate, song.MatchId, song.SongNo, song.GameName, song.SongName)
|
||||
if err != nil {
|
||||
_, _ = fmt.Fprintf(os.Stderr, "QueryRow failed: %v\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
func GetSongList(matchId int) []models.SongListData {
|
||||
rows, err := pool.Query(context.Background(),
|
||||
"SELECT match_date, match_id, song_no, game_name, song_name "+
|
||||
"FROM song_list WHERE match_date = $1"+
|
||||
"ORDER BY song_no DESC", matchId)
|
||||
if err != nil {
|
||||
_, _ = fmt.Fprintf(os.Stderr, "QueryRow failed: %v\n", err)
|
||||
}
|
||||
var songList []models.SongListData
|
||||
for rows.Next() {
|
||||
var matchId, songNo int
|
||||
var matchDate time.Time
|
||||
var gameName, songName string
|
||||
err := rows.Scan(&matchDate, &matchId, &songNo, &gameName, &songName)
|
||||
if err != nil {
|
||||
_, _ = fmt.Fprintf(os.Stderr, "Scan failed: %v\n", err)
|
||||
}
|
||||
songList = append(songList, models.SongListData{
|
||||
MatchDate: matchDate,
|
||||
MatchId: matchId,
|
||||
SongNo: songNo,
|
||||
GameName: gameName,
|
||||
SongName: songName,
|
||||
})
|
||||
}
|
||||
return songList
|
||||
}
|
||||
Reference in New Issue
Block a user