Get and set site name
This commit is contained in:
@ -4,7 +4,9 @@ import (
|
||||
"log/slog"
|
||||
"net/http"
|
||||
|
||||
"git.codemonkeysoftware.net/b/peachy-go"
|
||||
"git.codemonkeysoftware.net/b/peachy-go/desktop/components"
|
||||
"git.codemonkeysoftware.net/b/peachy-go/desktop/fields"
|
||||
"git.codemonkeysoftware.net/b/peachy-go/desktop/pages"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/chi/v5/middleware"
|
||||
@ -14,7 +16,7 @@ import (
|
||||
/*
|
||||
Create a new chi router, configure it and return it.
|
||||
*/
|
||||
func NewChiRouter(port string) *chi.Mux {
|
||||
func NewChiRouter(port string, db *peachy.DB) *chi.Mux {
|
||||
|
||||
r := chi.NewRouter()
|
||||
|
||||
@ -40,14 +42,31 @@ func NewChiRouter(port string) *chi.Mux {
|
||||
|
||||
r.Handle("/static/*", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
|
||||
|
||||
r.Get("/splash", func(w http.ResponseWriter, r *http.Request) {
|
||||
slog.Info("we splashin")
|
||||
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
HXRender(w, r, pages.Splash)
|
||||
})
|
||||
|
||||
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
slog.Info("we homies")
|
||||
HXRender(w, r, pages.HomePage)
|
||||
r.Get("/site", func(w http.ResponseWriter, r *http.Request) {
|
||||
page, err := pages.HomePage(db)
|
||||
if err != nil {
|
||||
logger.Error("internal error", "path", r.URL.Path, "error", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
HXRender(w, r, page)
|
||||
})
|
||||
|
||||
r.Patch("/site", func(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
if r.Form.Has(fields.SiteName) {
|
||||
err := db.SetSiteName(r.Form.Get(fields.SiteName))
|
||||
if err != nil {
|
||||
logger.Error("internal error", "path", r.URL.Path, "error", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
w.WriteHeader(http.StatusOK)
|
||||
})
|
||||
|
||||
r.Get("/hello", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
Reference in New Issue
Block a user