turns out rewriting all of your database code takes a while
This commit is contained in:
parent
1998a36d6d
commit
965d6f5c3e
30 changed files with 947 additions and 1036 deletions
|
@ -6,19 +6,48 @@ import (
|
|||
"strings"
|
||||
|
||||
"arimelody.me/arimelody.me/global"
|
||||
"arimelody.me/arimelody.me/music/model"
|
||||
"arimelody.me/arimelody.me/music/controller"
|
||||
)
|
||||
|
||||
func serveTrack() http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
slices := strings.Split(r.URL.Path[1:], "/")
|
||||
id := slices[0]
|
||||
track := global.GetTrack(id)
|
||||
track, err := music.GetTrack(global.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
|
||||
}
|
||||
|
||||
err := pages["track"].Execute(w, track)
|
||||
dbReleases, err := music.GetTrackReleases(global.DB, track)
|
||||
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
|
||||
}
|
||||
releases := []model.FullRelease{}
|
||||
for _, release := range dbReleases {
|
||||
fullRelease, err := music.GetFullRelease(global.DB, release)
|
||||
if err != nil {
|
||||
fmt.Printf("FATAL: Failed to pull full release data for %s: %s\n", release.ID, err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
releases = append(releases, *fullRelease)
|
||||
}
|
||||
|
||||
type Track struct {
|
||||
*model.Track
|
||||
Releases []model.FullRelease
|
||||
}
|
||||
|
||||
err = pages["track"].Execute(w, Track{ 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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue