i think that's all the api endpoints!

Signed-off-by: ari melody <ari@arimelody.me>
This commit is contained in:
ari melody 2024-08-03 23:24:15 +01:00
parent 494b29def3
commit 05e16a0867
17 changed files with 810 additions and 231 deletions

View file

@ -10,54 +10,95 @@ import (
func Handler() http.Handler {
mux := http.NewServeMux()
mux.Handle("/v1/artist/", http.StripPrefix("/v1/artist", ServeArtist()))
// ARTIST ENDPOINTS
mux.Handle("/v1/artist/", http.StripPrefix("/v1/artist", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
// GET /api/v1/artist/{id}
ServeArtist().ServeHTTP(w, r)
case http.MethodPut:
// PUT /api/v1/artist/{id} (admin)
admin.MustAuthorise(UpdateArtist()).ServeHTTP(w, r)
case http.MethodDelete:
// DELETE /api/v1/artist/{id} (admin)
admin.MustAuthorise(DeleteArtist()).ServeHTTP(w, r)
default:
http.NotFound(w, r)
}
})))
mux.Handle("/v1/artist", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
// GET /api/v1/artist
ServeAllArtists().ServeHTTP(w, r)
return
case http.MethodPost:
// POST /api/v1/artist (admin)
admin.MustAuthorise(CreateArtist()).ServeHTTP(w, r)
return
default:
http.NotFound(w, r)
return
}
}))
// RELEASE ENDPOINTS
mux.Handle("/v1/music/", http.StripPrefix("/v1/music", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
// GET /api/v1/music/{id}
music.ServeRelease().ServeHTTP(w, r)
return
case http.MethodPut:
// PUT /api/v1/music/{id} (admin)
admin.MustAuthorise(UpdateRelease()).ServeHTTP(w, r)
case http.MethodDelete:
// DELETE /api/v1/music/{id} (admin)
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:
// GET /api/v1/music
ServeCatalog().ServeHTTP(w, r)
return
case http.MethodPost:
// POST /api/v1/music (admin)
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())
// TRACK ENDPOINTS
mux.Handle("/v1/track/", http.StripPrefix("/v1/track", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
// GET /api/v1/track/{id} (admin)
admin.MustAuthorise(ServeTrack()).ServeHTTP(w, r)
case http.MethodPut:
// PUT /api/v1/track/{id} (admin)
admin.MustAuthorise(UpdateTrack()).ServeHTTP(w, r)
case http.MethodDelete:
// DELETE /api/v1/track/{id} (admin)
admin.MustAuthorise(DeleteTrack()).ServeHTTP(w, r)
default:
http.NotFound(w, r)
}
})))
mux.Handle("/v1/track", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
// GET /api/v1/track (admin)
admin.MustAuthorise(ServeAllTracks()).ServeHTTP(w, r)
case http.MethodPost:
// POST /api/v1/track (admin)
admin.MustAuthorise(CreateTrack()).ServeHTTP(w, r)
default:
http.NotFound(w, r)
}
}))
return mux
}