refactor: move music admin to /admin/music; keep /admin generic

This commit is contained in:
ari melody 2025-07-15 16:40:15 +01:00
parent ddbf3444eb
commit bd2dc806d5
Signed by: ari
GPG key ID: CF99829C92678188
31 changed files with 1079 additions and 906 deletions

54
admin/music/trackhttp.go Normal file
View file

@ -0,0 +1,54 @@
package music
import (
"fmt"
"net/http"
"strings"
"arimelody-web/admin/templates"
"arimelody-web/controller"
"arimelody-web/model"
)
func serveTrack(app *model.AppState) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
slices := strings.Split(r.URL.Path[1:], "/")
id := slices[0]
track, err := controller.GetTrack(app.DB, id)
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
}
if track == nil {
http.NotFound(w, r)
return
}
releases, err := controller.GetTrackReleases(app.DB, track.ID, true)
if err != nil {
fmt.Printf("FATAL: Failed to pull releases for %s: %s\n", id, err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
type TrackResponse struct {
Session *model.Session
Track *model.Track
Releases []*model.Release
}
session := r.Context().Value("session").(*model.Session)
err = templates.TrackTemplate.Execute(w, TrackResponse{
Session: session,
Track: track,
Releases: releases,
})
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)
}
})
}