2024-08-02 21:48:26 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"arimelody.me/arimelody.me/admin"
|
|
|
|
music "arimelody.me/arimelody.me/music/view"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Handler() http.Handler {
|
|
|
|
mux := http.NewServeMux()
|
|
|
|
|
2024-08-03 22:24:15 +00:00
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
})))
|
2024-08-02 21:48:26 +00:00
|
|
|
mux.Handle("/v1/artist", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
switch r.Method {
|
|
|
|
case http.MethodGet:
|
2024-08-03 22:24:15 +00:00
|
|
|
// GET /api/v1/artist
|
2024-08-02 21:48:26 +00:00
|
|
|
ServeAllArtists().ServeHTTP(w, r)
|
|
|
|
case http.MethodPost:
|
2024-08-03 22:24:15 +00:00
|
|
|
// POST /api/v1/artist (admin)
|
2024-08-02 21:48:26 +00:00
|
|
|
admin.MustAuthorise(CreateArtist()).ServeHTTP(w, r)
|
|
|
|
default:
|
|
|
|
http.NotFound(w, r)
|
|
|
|
}
|
|
|
|
}))
|
2024-08-02 23:27:30 +00:00
|
|
|
|
2024-08-03 22:24:15 +00:00
|
|
|
// RELEASE ENDPOINTS
|
|
|
|
|
2024-08-03 14:02:01 +00:00
|
|
|
mux.Handle("/v1/music/", http.StripPrefix("/v1/music", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
switch r.Method {
|
|
|
|
case http.MethodGet:
|
2024-08-03 22:24:15 +00:00
|
|
|
// GET /api/v1/music/{id}
|
2024-08-03 14:02:01 +00:00
|
|
|
music.ServeRelease().ServeHTTP(w, r)
|
2024-08-03 22:24:15 +00:00
|
|
|
case http.MethodPut:
|
|
|
|
// PUT /api/v1/music/{id} (admin)
|
|
|
|
admin.MustAuthorise(UpdateRelease()).ServeHTTP(w, r)
|
2024-08-03 14:02:01 +00:00
|
|
|
case http.MethodDelete:
|
2024-08-03 22:24:15 +00:00
|
|
|
// DELETE /api/v1/music/{id} (admin)
|
2024-08-03 14:02:01 +00:00
|
|
|
admin.MustAuthorise(DeleteRelease()).ServeHTTP(w, r)
|
|
|
|
default:
|
|
|
|
http.NotFound(w, r)
|
|
|
|
}
|
|
|
|
})))
|
2024-08-02 21:48:26 +00:00
|
|
|
mux.Handle("/v1/music", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
switch r.Method {
|
|
|
|
case http.MethodGet:
|
2024-08-03 22:24:15 +00:00
|
|
|
// GET /api/v1/music
|
2024-08-02 21:48:26 +00:00
|
|
|
ServeCatalog().ServeHTTP(w, r)
|
|
|
|
case http.MethodPost:
|
2024-08-03 22:24:15 +00:00
|
|
|
// POST /api/v1/music (admin)
|
2024-08-02 21:48:26 +00:00
|
|
|
admin.MustAuthorise(CreateRelease()).ServeHTTP(w, r)
|
|
|
|
default:
|
|
|
|
http.NotFound(w, r)
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
|
2024-08-03 22:24:15 +00:00
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
}))
|
2024-08-02 23:27:30 +00:00
|
|
|
|
2024-08-02 21:48:26 +00:00
|
|
|
return mux
|
|
|
|
}
|