cml04-falcon-printer/handlers/index.go

37 lines
934 B
Go
Raw Normal View History

2024-10-24 10:58:03 +02:00
package handlers
import (
"html/template"
"net/http"
"git.espin.casa/albert/cml04-falcon-printer/storage"
2024-10-25 22:17:44 +02:00
"git.espin.casa/albert/cml04-falcon-printer/types"
2024-10-24 10:58:03 +02:00
"github.com/julienschmidt/httprouter"
)
type PageView struct {
2024-10-25 22:17:44 +02:00
ProductionOrders []*types.ProductionOrder
CustomerOrders []*types.CustomerOrder
2024-10-24 10:58:03 +02:00
}
func IndexHandler(storage storage.Storager) httprouter.Handle {
return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
2024-10-25 22:17:44 +02:00
// get production orders
pos, err := storage.ListProductionOrders(r.Context(), 40)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
2024-10-24 10:58:03 +02:00
// create view
2024-10-25 22:17:44 +02:00
view := &PageView{
ProductionOrders: pos,
CustomerOrders: nil,
}
2024-10-24 10:58:03 +02:00
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
}
}
}