v1 blog API routes
This commit is contained in:
parent
fec3325503
commit
eaa2f6587d
9 changed files with 286 additions and 34 deletions
40
api/api.go
40
api/api.go
|
|
@ -1,14 +1,14 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"arimelody-web/controller"
|
||||
"arimelody-web/model"
|
||||
"arimelody-web/controller"
|
||||
"arimelody-web/model"
|
||||
)
|
||||
|
||||
func Handler(app *model.AppState) http.Handler {
|
||||
|
|
@ -45,7 +45,7 @@ func Handler(app *model.AppState) http.Handler {
|
|||
http.NotFound(w, r)
|
||||
}
|
||||
}))
|
||||
mux.Handle("/v1/artist", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
artistIndexHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
// GET /api/v1/artist
|
||||
|
|
@ -56,7 +56,9 @@ func Handler(app *model.AppState) http.Handler {
|
|||
default:
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
}))
|
||||
})
|
||||
mux.Handle("/v1/artist/", artistIndexHandler)
|
||||
mux.Handle("/v1/artist", artistIndexHandler)
|
||||
|
||||
// RELEASE ENDPOINTS
|
||||
|
||||
|
|
@ -87,7 +89,7 @@ func Handler(app *model.AppState) http.Handler {
|
|||
http.NotFound(w, r)
|
||||
}
|
||||
}))
|
||||
mux.Handle("/v1/music", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
musicIndexHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
// GET /api/v1/music
|
||||
|
|
@ -98,7 +100,9 @@ func Handler(app *model.AppState) http.Handler {
|
|||
default:
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
}))
|
||||
})
|
||||
mux.Handle("/v1/music/", musicIndexHandler)
|
||||
mux.Handle("/v1/music", musicIndexHandler)
|
||||
|
||||
// TRACK ENDPOINTS
|
||||
|
||||
|
|
@ -129,7 +133,7 @@ func Handler(app *model.AppState) http.Handler {
|
|||
http.NotFound(w, r)
|
||||
}
|
||||
}))
|
||||
mux.Handle("/v1/track", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
trackIndexHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
// GET /api/v1/track (admin)
|
||||
|
|
@ -140,7 +144,17 @@ func Handler(app *model.AppState) http.Handler {
|
|||
default:
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
}))
|
||||
})
|
||||
mux.Handle("/v1/track/", trackIndexHandler)
|
||||
mux.Handle("/v1/track", trackIndexHandler)
|
||||
|
||||
// BLOG ENDPOINTS
|
||||
|
||||
mux.Handle("GET /v1/blog/{id}", ServeBlog(app))
|
||||
mux.Handle("PUT /v1/blog/{id}", requireAccount(UpdateBlog(app)))
|
||||
mux.Handle("DELETE /v1/blog/{id}", requireAccount(DeleteBlog(app)))
|
||||
mux.Handle("GET /v1/blog", ServeAllBlogs(app))
|
||||
mux.Handle("POST /v1/blog", requireAccount(CreateBlog(app)))
|
||||
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
session, err := getSession(app, r)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue