- AuthorPosts reuses the /posts published predicate, per_page clamp, sort allow-list and row serializer - Bearer tokens are ignored; drafts and scheduled posts never appear - Both author routes share one resolve-or-respond helper for identical 404/500 paths - Document query keys, envelope and 404 in README
37 lines
1.6 KiB
Go
37 lines
1.6 KiB
Go
package journal
|
|
|
|
import (
|
|
apicontrollers "git.golem15.com/golem15/sm-journal-plugin/controllers/api"
|
|
"git.golem15.com/golem15/summercms/modules/pact"
|
|
"git.golem15.com/golem15/summercms/modules/surf"
|
|
)
|
|
|
|
// Routes mounts public GETs and backend-Bearer writes under /_journal/api/v1
|
|
// (D-14). The public group must not attach cabana middleware name "backend"
|
|
// (anonymous callers would 401 — pitfall 4). The public author routes resolve
|
|
// {author} in the handler rather than with Where, so every miss is the JSON
|
|
// 404 {"error":"Author not found"}.
|
|
func (p *Plugin) Routes(r pact.Router) error {
|
|
r.Group("/_journal/api/v1", surf.Use("throttle:journal-public-api"), func(g pact.Router) {
|
|
g.Get("/posts", apicontrollers.Index(p.app))
|
|
g.Get("/posts/{slug}", apicontrollers.Show(p.app))
|
|
g.Where("slug", `[a-z0-9][a-z0-9\-/]*`)
|
|
g.Get("/categories", apicontrollers.Categories(p.app))
|
|
g.Get("/tags", apicontrollers.Tags(p.app))
|
|
g.Get("/rss", apicontrollers.RSS(p.app))
|
|
g.Get("/authors/{author}", apicontrollers.AuthorShow(p.app))
|
|
g.Get("/authors/{author}/posts", apicontrollers.AuthorPosts(p.app))
|
|
})
|
|
r.Group("/_journal/api/v1", surf.Use("throttle:journal-api"), func(g pact.Router) {
|
|
g.Post("/media/upload", apicontrollers.UploadMedia(p.app))
|
|
g.Post("/posts", apicontrollers.Store(p.app))
|
|
g.Put("/posts/{id}", apicontrollers.Update(p.app))
|
|
g.Delete("/posts/{id}", apicontrollers.Destroy(p.app))
|
|
g.Post("/posts/{id}/featured-images", apicontrollers.UploadFeaturedImage(p.app))
|
|
g.Delete("/posts/{id}/featured-images/{fileId}", apicontrollers.DeleteFeaturedImage(p.app))
|
|
g.Where("id", `[0-9]+`)
|
|
g.Where("fileId", `[0-9]+`)
|
|
})
|
|
return nil
|
|
}
|