HOLY REFACTOR GOOD GRIEF (also finally started some CRUD work)

Signed-off-by: ari melody <ari@arimelody.me>
This commit is contained in:
ari melody 2024-08-02 22:48:26 +01:00
parent 1c310c9101
commit 442889340c
80 changed files with 1571 additions and 1330 deletions

43
api/api.go Normal file
View file

@ -0,0 +1,43 @@
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", music.ServeRelease()))
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
default:
http.NotFound(w, r)
return
}
}))
return mux
}