mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-12-25 16:19:00 +00:00
Add proper handling to album links
This commit is contained in:
parent
c267f5a7ef
commit
e9474ba0b6
@ -28,7 +28,10 @@ func insertAlbum(name string, mbid string, artists []string, tx *sql.Tx) (Album,
|
||||
}
|
||||
|
||||
album = fetchAlbum("mbid", mbid, tx)
|
||||
album.linkAlbumToArtists(artists, tx)
|
||||
err = album.linkAlbumToArtists(artists, tx)
|
||||
if err != nil {
|
||||
return album, err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
album = fetchAlbum("name", name, tx)
|
||||
@ -40,7 +43,10 @@ func insertAlbum(name string, mbid string, artists []string, tx *sql.Tx) (Album,
|
||||
}
|
||||
|
||||
album = fetchAlbum("name", name, tx)
|
||||
album.linkAlbumToArtists(artists, tx)
|
||||
err = album.linkAlbumToArtists(artists, tx)
|
||||
if err != nil {
|
||||
return album, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,8 +82,8 @@ func insertNewAlbum(name string, mbid string, tx *sql.Tx) error {
|
||||
func (album *Album) linkAlbumToArtists(artists []string, tx *sql.Tx) error {
|
||||
var err error
|
||||
for _, artist := range artists {
|
||||
_, err = tx.Exec("INSERT INTO `track_artist` (`track`, `artist`) "+
|
||||
"VALUES (UUID_TO_BIN(?, true), UUID_TO_BIN(?, true)", album.Uuid, artist)
|
||||
_, err = tx.Exec("INSERT INTO `album_artist` (`album`, `artist`) "+
|
||||
"VALUES (UUID_TO_BIN(?, true), UUID_TO_BIN(?, true))", album.Uuid, artist)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -97,10 +97,10 @@ func throwBadReq(w http.ResponseWriter, m string) {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
}
|
||||
|
||||
// throwUnauthorized - Throws a 403
|
||||
// throwOkMessage - Throws a happy 200
|
||||
func throwOkMessage(w http.ResponseWriter, m string) {
|
||||
jr := jsonResponse{
|
||||
Err: m,
|
||||
Msg: m,
|
||||
}
|
||||
js, _ := json.Marshal(&jr)
|
||||
err := errors.New(string(js))
|
||||
@ -241,11 +241,11 @@ func handleIngress(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
throwOkMessage(w, "{}")
|
||||
throwOkMessage(w, "success")
|
||||
return
|
||||
}
|
||||
// Lets trick 'em for now ;) ;)
|
||||
fmt.Fprintf(w, "{}")
|
||||
|
||||
throwBadReq(w, "Unknown ingress type")
|
||||
}
|
||||
|
||||
// FRONTEND HANDLING
|
||||
|
Loading…
Reference in New Issue
Block a user