2024-09-03 07:07:45 +00:00
|
|
|
package admin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"arimelody-web/global"
|
2024-11-01 19:33:26 +00:00
|
|
|
"arimelody-web/model"
|
|
|
|
"arimelody-web/controller"
|
2024-09-03 07:07:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func serveArtist() http.Handler {
|
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
slices := strings.Split(r.URL.Path[1:], "/")
|
|
|
|
id := slices[0]
|
2024-11-01 19:33:26 +00:00
|
|
|
artist, err := controller.GetArtist(global.DB, id)
|
2024-09-03 07:07:45 +00:00
|
|
|
if err != nil {
|
|
|
|
if artist == nil {
|
|
|
|
http.NotFound(w, r)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
fmt.Printf("Error rendering admin artist page for %s: %s\n", id, err)
|
|
|
|
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-11-01 19:33:26 +00:00
|
|
|
credits, err := controller.GetArtistCredits(global.DB, artist.ID, true)
|
2024-09-03 07:07:45 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("Error rendering admin track page for %s: %s\n", id, err)
|
|
|
|
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
type Artist struct {
|
|
|
|
*model.Artist
|
|
|
|
Credits []*model.Credit
|
|
|
|
}
|
|
|
|
|
|
|
|
err = pages["artist"].Execute(w, Artist{ Artist: artist, Credits: credits })
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("Error rendering admin track page for %s: %s\n", id, err)
|
|
|
|
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|