arimelody.me/api/api.go

64 lines
1.8 KiB
Go
Raw Normal View History

package api
import (
"net/http"
"arimelody.me/arimelody.me/admin"
music "arimelody.me/arimelody.me/music/view"
)
func Handler() http.Handler {
mux := http.NewServeMux()
mux.Handle("/v1/artist/", http.StripPrefix("/v1/artist", ServeArtist()))
mux.Handle("/v1/artist", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
ServeAllArtists().ServeHTTP(w, r)
return
case http.MethodPost:
admin.MustAuthorise(CreateArtist()).ServeHTTP(w, r)
return
default:
http.NotFound(w, r)
return
}
}))
mux.Handle("/v1/music/", http.StripPrefix("/v1/music", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
music.ServeRelease().ServeHTTP(w, r)
return
case http.MethodDelete:
admin.MustAuthorise(DeleteRelease()).ServeHTTP(w, r)
return
default:
http.NotFound(w, r)
return
}
})))
mux.Handle("/v1/music", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
ServeCatalog().ServeHTTP(w, r)
return
case http.MethodPost:
admin.MustAuthorise(CreateRelease()).ServeHTTP(w, r)
return
case http.MethodDelete:
admin.MustAuthorise(DeleteRelease()).ServeHTTP(w, r)
return
default:
http.NotFound(w, r)
return
}
}))
mux.Handle("/v1/musiccredit", CreateMusicCredit())
mux.Handle("/v1/musiclink", CreateMusicLink())
mux.Handle("/v1/track", CreateTrack())
return mux
}