Fixed some bugs
Images should not be included in the database Removes songs where the path doesn't work Started working on adding cover images Started adding vue directly in the application
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"music-server/pkg/models"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func ClearSongs(gameId int) {
|
||||
@@ -66,3 +67,49 @@ func AddSongPlayed(id int, name string) {
|
||||
_, _ = fmt.Fprintf(os.Stderr, "Exec failed: %v\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
func FetchAllSongs() []models.SongData {
|
||||
rows, err := pool.Query(context.Background(),
|
||||
"SELECT song_name, path FROM song")
|
||||
if err != nil {
|
||||
_, _ = fmt.Fprintf(os.Stderr, "QueryRow failed: %v\n", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
var songDataList []models.SongData
|
||||
for rows.Next() {
|
||||
var songName string
|
||||
var path string
|
||||
|
||||
err := rows.Scan(&songName, &path)
|
||||
if err != nil {
|
||||
_, _ = fmt.Fprintf(os.Stderr, "QueryRow failed: %v\n", err)
|
||||
}
|
||||
|
||||
songDataList = append(songDataList, models.SongData{
|
||||
SongName: songName,
|
||||
Path: path,
|
||||
})
|
||||
}
|
||||
return songDataList
|
||||
}
|
||||
|
||||
func RemoveBrokenSong(song models.SongData) {
|
||||
_, err := pool.Exec(context.Background(), "DELETE FROM song where path=$1", song.Path)
|
||||
if err != nil {
|
||||
_, _ = fmt.Fprintf(os.Stderr, "Exec failed: %v\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
func RemoveBrokenSongs(songs []models.SongData) {
|
||||
joined := ""
|
||||
for _, song := range songs {
|
||||
joined += "'" + song.Path + "',"
|
||||
}
|
||||
joined = strings.TrimSuffix(joined, ",")
|
||||
|
||||
_, err := pool.Exec(context.Background(), "DELETE FROM song where path in ($1)", joined)
|
||||
if err != nil {
|
||||
_, _ = fmt.Fprintf(os.Stderr, "Exec failed: %v\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user