lots of post-DB cleanup

This commit is contained in:
ari melody 2024-09-02 00:15:23 +01:00
parent 965d6f5c3e
commit c9d950d2b2
Signed by: ari
GPG key ID: CF99829C92678188
23 changed files with 412 additions and 550 deletions

View file

@ -8,6 +8,7 @@ import (
"arimelody.me/arimelody.me/global"
"arimelody.me/arimelody.me/music/model"
db "arimelody.me/arimelody.me/music/controller"
)
type artistJSON struct {
@ -20,7 +21,7 @@ type artistJSON struct {
func ServeAllArtists() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var artists = []*model.Artist{}
err := global.DB.Select(&artists, "SELECT * FROM artist")
artists, err := db.GetAllArtists(global.DB)
if err != nil {
fmt.Printf("FATAL: Failed to serve all artists: %s\n", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
@ -39,7 +40,6 @@ func ServeArtist(artist model.Artist) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
type (
creditJSON struct {
Release string `json:"release"`
Role string `json:"role"`
Primary bool `json:"primary"`
}
@ -49,14 +49,22 @@ func ServeArtist(artist model.Artist) http.Handler {
}
)
var credits = map[string]creditJSON{}
err := global.DB.Select(&credits, "SELECT release,role,is_primary FROM musiccredit WHERE id=$1", artist.ID)
var dbCredits []*model.Credit
dbCredits, err := db.GetArtistCredits(global.DB, artist.ID)
if err != nil {
fmt.Printf("FATAL: Failed to retrieve artist credits for %s: %s\n", artist.ID, err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
var credits = map[string]creditJSON{}
for _, credit := range dbCredits {
credits[credit.Release.ID] = creditJSON{
Role: credit.Role,
Primary: credit.Primary,
}
}
w.Header().Add("Content-Type", "application/json")
err = json.NewEncoder(w).Encode(artistJSON{
Artist: artist,