release edit page! + a lot of other stuff oml
Signed-off-by: ari melody <ari@arimelody.me>
This commit is contained in:
parent
f276ef1ff2
commit
10f19d46db
23 changed files with 981 additions and 347 deletions
|
@ -10,6 +10,13 @@ import (
|
|||
controller "arimelody.me/arimelody.me/music/controller"
|
||||
)
|
||||
|
||||
type artistJSON struct {
|
||||
ID string `json:"id"`
|
||||
Name *string `json:"name"`
|
||||
Website *string `json:"website"`
|
||||
Avatar *string `json:"avatar"`
|
||||
}
|
||||
|
||||
func ServeAllArtists() http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
|
@ -78,7 +85,7 @@ func CreateArtist() http.Handler {
|
|||
return
|
||||
}
|
||||
|
||||
var data model.Artist
|
||||
var data artistJSON
|
||||
err := json.NewDecoder(r.Body).Decode(&data)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to create artist: %s\n", err)
|
||||
|
@ -90,7 +97,7 @@ func CreateArtist() http.Handler {
|
|||
http.Error(w, "Artist ID cannot be blank\n", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if data.Name == "" {
|
||||
if data.Name == nil || *data.Name == "" {
|
||||
http.Error(w, "Artist name cannot be blank\n", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
@ -102,9 +109,9 @@ func CreateArtist() http.Handler {
|
|||
|
||||
var artist = model.Artist{
|
||||
ID: data.ID,
|
||||
Name: data.Name,
|
||||
Website: data.Website,
|
||||
Avatar: data.Avatar,
|
||||
Name: *data.Name,
|
||||
Website: *data.Website,
|
||||
Avatar: *data.Avatar,
|
||||
}
|
||||
|
||||
err = controller.CreateArtistDB(global.DB, &artist)
|
||||
|
@ -138,7 +145,7 @@ func UpdateArtist() http.Handler {
|
|||
return
|
||||
}
|
||||
|
||||
var data model.Artist
|
||||
var data artistJSON
|
||||
err := json.NewDecoder(r.Body).Decode(&data)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to update artist: %s\n", err)
|
||||
|
@ -153,24 +160,24 @@ func UpdateArtist() http.Handler {
|
|||
return
|
||||
}
|
||||
|
||||
if data.ID == "" { data.ID = artist.ID }
|
||||
var update = *artist
|
||||
|
||||
if data.Name == "" {
|
||||
http.Error(w, "Artist name cannot be blank\n", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if data.ID != "" { update.ID = data.ID }
|
||||
if data.Name != nil { update.Name = *data.Name }
|
||||
if data.Website != nil { update.Website = *data.Website }
|
||||
if data.Avatar != nil { update.Avatar = *data.Avatar }
|
||||
|
||||
err = controller.UpdateArtistDB(global.DB, &data)
|
||||
err = controller.UpdateArtistDB(global.DB, &update)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to update artist %s: %s\n", artist.ID, err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
artist.ID = data.ID
|
||||
artist.Name = data.Name
|
||||
artist.Website = data.Website
|
||||
artist.Avatar = data.Avatar
|
||||
artist.ID = update.ID
|
||||
artist.Name = update.Name
|
||||
artist.Website = update.Website
|
||||
artist.Avatar = update.Avatar
|
||||
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
err = json.NewEncoder(w).Encode(artist)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue