2024-09-03 07:07:45 +00:00
|
|
|
package admin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
|
2025-01-20 10:34:39 +00:00
|
|
|
"arimelody-web/model"
|
|
|
|
"arimelody-web/controller"
|
2024-09-03 07:07:45 +00:00
|
|
|
)
|
|
|
|
|
2025-01-21 14:53:18 +00:00
|
|
|
func serveArtist(app *model.AppState) http.Handler {
|
2024-09-03 07:07:45 +00:00
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
slices := strings.Split(r.URL.Path[1:], "/")
|
|
|
|
id := slices[0]
|
2025-01-21 14:53:18 +00:00
|
|
|
artist, err := controller.GetArtist(app.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
|
|
|
|
}
|
|
|
|
|
2025-01-21 14:53:18 +00:00
|
|
|
credits, err := controller.GetArtistCredits(app.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
|
|
|
|
}
|
|
|
|
|
2025-01-20 15:08:01 +00:00
|
|
|
type ArtistResponse struct {
|
2025-01-23 00:37:19 +00:00
|
|
|
Session *model.Session
|
2025-01-20 15:08:01 +00:00
|
|
|
Artist *model.Artist
|
|
|
|
Credits []*model.Credit
|
2024-09-03 07:07:45 +00:00
|
|
|
}
|
|
|
|
|
2025-01-23 00:37:19 +00:00
|
|
|
session := r.Context().Value("session").(*model.Session)
|
2025-01-20 15:08:01 +00:00
|
|
|
|
2025-01-26 20:09:18 +00:00
|
|
|
err = artistTemplate.Execute(w, ArtistResponse{
|
2025-01-23 00:37:19 +00:00
|
|
|
Session: session,
|
2025-01-20 15:08:01 +00:00
|
|
|
Artist: artist,
|
|
|
|
Credits: credits,
|
|
|
|
})
|
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)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|