create support for releases, artists, tracks, and credits
Signed-off-by: ari melody <ari@arimelody.me>
This commit is contained in:
parent
442889340c
commit
9329aa9f60
19 changed files with 252 additions and 37 deletions
|
@ -98,10 +98,20 @@ func CreateArtist() http.Handler {
|
|||
var data model.Artist
|
||||
err := json.NewDecoder(r.Body).Decode(&data)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to create artist: %s\n", err)
|
||||
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if data.ID == "" {
|
||||
http.Error(w, "Artist ID cannot be blank", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if data.Name == "" {
|
||||
http.Error(w, "Artist name cannot be blank", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if global.GetArtist(data.ID) != nil {
|
||||
http.Error(w, fmt.Sprintf("Artist %s already exists", data.ID), http.StatusBadRequest)
|
||||
return
|
||||
|
@ -114,8 +124,6 @@ func CreateArtist() http.Handler {
|
|||
Avatar: data.Avatar,
|
||||
}
|
||||
|
||||
global.Artists = append(global.Artists, artist)
|
||||
|
||||
err = controller.CreateArtistDB(global.DB, &artist)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to create artist %s: %s\n", artist.ID, err)
|
||||
|
@ -123,6 +131,8 @@ func CreateArtist() http.Handler {
|
|||
return
|
||||
}
|
||||
|
||||
global.Artists = append(global.Artists, &artist)
|
||||
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
err = json.NewEncoder(w).Encode(artist)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue