diff options
Diffstat (limited to 'data.go')
| -rw-r--r-- | data.go | 35 |
1 files changed, 21 insertions, 14 deletions
@@ -35,6 +35,17 @@ type Session struct { Subscriber int64 `json:"subscriber" xml:"subscriber"` } +type Song struct { + Id int + Artist string + Album string + Name string + TrackNumber int + Duration int + Mbid string + Image string +} + type DataStore interface { PutSession(*Session) error GetSession(key string) (*Session, error) @@ -42,8 +53,9 @@ type DataStore interface { PutNowPlaying(s Scrobble) error NowPlaying(userId int) *Scrobble RecentScrobbles(userId int) []*Scrobble - GetSongId(artist, album, name string) (int, error) - InsertSong(s *Scrobble) (int, error) + + GetSongId(s *Song) error + InsertSong(s *Song) error GetScrobblingUser(lfmName string) (int, string, error) GetUser(u *User) error @@ -166,28 +178,23 @@ func (store *SqlStore) NowPlaying(userId int) *Scrobble { return scrobble } -func (store *SqlStore) GetSongId(artist, album, song string) (int, error) { +func (store *SqlStore) GetSongId(s *Song) error { query := ` SELECT song_id FROM songs WHERE artist=$1 AND album=$2 AND name=$3 ` - var id int - row := store.QueryRow(query, artist, album, song) - err := row.Scan(&id) - return id, err - + row := store.QueryRow(query, s.Artist, s.Album, s.Name) + return row.Scan(&s.Id) } -func (store *SqlStore) InsertSong(s *Scrobble) (int, error) { +func (store *SqlStore) InsertSong(s *Song) error { query := ` INSERT INTO songs (artist, album, name, track_number, duration, mbid, image) VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING song_id` - var id int - row := store.QueryRow(query, s.Artist, s.Album, s.TrackName, s.TrackNumber, - s.Duration*1000, s.Mbid, s.Image) - err := row.Scan(&id) - return id, err + row := store.QueryRow(query, s.Artist, s.Album, s.Name, s.TrackNumber, + s.Duration, s.Mbid, s.Image) + return row.Scan(&s.Id) } func (store *SqlStore) InsertUser(user *User) error { |
