46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
"text/template"
|
|
|
|
"git.espin.casa/albert/cml04-falcon-ui/helper"
|
|
"git.espin.casa/albert/cml04-falcon-ui/storage"
|
|
"git.espin.casa/albert/cml04-falcon-ui/types"
|
|
"github.com/julienschmidt/httprouter"
|
|
)
|
|
|
|
func BundleHandler(storage storage.Storager) httprouter.Handle {
|
|
return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|
|
|
if r.Method == http.MethodGet {
|
|
t, _ := template.ParseFiles("templates/base.html", "templates/bundle.html")
|
|
err := t.Execute(w, nil)
|
|
if err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
}
|
|
|
|
if r.Method == http.MethodPost {
|
|
// barcodes holder
|
|
Bundles := []types.BundleData{}
|
|
// parse form data from formulary
|
|
if err := r.ParseForm(); err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
}
|
|
// barcode
|
|
codigo := r.FormValue("codigo")
|
|
// date range
|
|
fechas := r.FormValue("fechas")
|
|
// get range dates
|
|
inicio, final, err := helper.Dates(fechas)
|
|
if err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|