cml04-falcon-printer/handlers/index.go
2024-10-25 22:17:44 +02:00

37 lines
934 B
Go

package handlers
import (
"html/template"
"net/http"
"git.espin.casa/albert/cml04-falcon-printer/storage"
"git.espin.casa/albert/cml04-falcon-printer/types"
"github.com/julienschmidt/httprouter"
)
type PageView struct {
ProductionOrders []*types.ProductionOrder
CustomerOrders []*types.CustomerOrder
}
func IndexHandler(storage storage.Storager) httprouter.Handle {
return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
// get production orders
pos, err := storage.ListProductionOrders(r.Context(), 40)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// create view
view := &PageView{
ProductionOrders: pos,
CustomerOrders: nil,
}
t, _ := template.ParseFiles("templates/base.html", "templates/index.html")
if err := t.Execute(w, view); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
}