cpolis/cmd/frontend/issues.go

29 lines
646 B
Go
Raw Normal View History

package frontend
2024-03-28 07:34:36 +01:00
import (
"html/template"
"log"
"net/http"
b "streifling.com/jason/cpolis/cmd/backend"
2024-03-28 07:34:36 +01:00
)
func PublishLatestIssue(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
2024-03-28 07:34:36 +01:00
return func(w http.ResponseWriter, r *http.Request) {
session, err := getSession(w, r, c, s)
if err != nil {
return
}
2024-03-28 07:34:36 +01:00
if err := db.PublishLatestIssue(); err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html")
2024-03-28 07:34:36 +01:00
tmpl = template.Must(tmpl, err)
tmpl.ExecuteTemplate(w, "page-content", session.Values["role"])
}
}