| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "net/http" |
| 5 | |
| 6 | "github.com/stevedylandev/andromeda/pkg/darkmatter" |
| 7 | "github.com/stevedylandev/andromeda/pkg/web" |
| 8 | ) |
| 9 | |
| 10 | func (a *App) routes() *http.ServeMux { |
| 11 | mux := http.NewServeMux() |
| 12 | |
| 13 | requireSession := func(next http.HandlerFunc) http.HandlerFunc { |
| 14 | return a.Sessions.RequireSession("/admin/login", next) |
| 15 | } |
| 16 | |
| 17 | mux.HandleFunc("GET /", a.indexHandler) |
| 18 | mux.HandleFunc("GET /static/", web.EmbeddedHandler(appFS, "static")) |
| 19 | darkmatter.Mount(mux, "/assets") |
| 20 | |
| 21 | mux.HandleFunc("GET /admin/login", a.loginGetHandler) |
| 22 | mux.HandleFunc("POST /admin/login", a.loginPostHandler) |
| 23 | mux.HandleFunc("GET /admin/logout", a.logoutHandler) |
| 24 | mux.HandleFunc("GET /admin", requireSession(a.adminHandler)) |
| 25 | mux.HandleFunc("GET /admin/search", requireSession(a.adminSearch)) |
| 26 | mux.HandleFunc("POST /admin/categories/labels", requireSession(a.adminUpdateLabels)) |
| 27 | mux.HandleFunc("POST /admin/add", requireSession(a.adminAddBook)) |
| 28 | mux.HandleFunc("POST /admin/books/{id}/status", requireSession(a.adminUpdateStatus)) |
| 29 | mux.HandleFunc("POST /admin/books/{id}/notes", requireSession(a.adminUpdateNotes)) |
| 30 | mux.HandleFunc("POST /admin/books/{id}/delete", requireSession(a.adminDeleteBook)) |
| 31 | |
| 32 | mux.HandleFunc("GET /api/books", a.apiListBooks) |
| 33 | mux.HandleFunc("GET /api/books/{id}", a.apiGetBook) |
| 34 | |
| 35 | return mux |
| 36 | } |