Add proper handling to album links

This commit is contained in:
Daniel Mason 2021-03-28 22:24:18 +13:00
parent c267f5a7ef
commit e9474ba0b6
Signed by: idanoo
GPG Key ID: 387387CDBC02F132
2 changed files with 15 additions and 9 deletions

View File

@ -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
}

View File

@ -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