diff --git a/cmd/app.go b/cmd/app.go index 8c547c6..3a044ef 100644 --- a/cmd/app.go +++ b/cmd/app.go @@ -22,6 +22,7 @@ func Run() error { dbHost := flag.String("db-host", "db", "database host address") dbPort := flag.Int("db-port", 5432, "database tcp port") dbName := flag.String("db-name", "falcon", "database user password") + flag.Parse() // setup logger log := logger.New(os.Stdout, *logLevel) // log fields diff --git a/handlers/barcodes.go b/handlers/barcodes.go index e0cd085..d1c966f 100644 --- a/handlers/barcodes.go +++ b/handlers/barcodes.go @@ -27,7 +27,7 @@ func BarcodesHandler(storage storage.Storager) httprouter.Handle { // post method if r.Method == http.MethodPost { // barcodes holder - barcodes := []types.Barcode{} + Barcodes := []types.Barcode{} // parse form data from formulary if err := r.ParseForm(); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) @@ -47,7 +47,7 @@ func BarcodesHandler(storage storage.Storager) httprouter.Handle { return } // append barcode to holder - barcodes = append(barcodes, *data) + Barcodes = append(Barcodes, *data) } else { inicio := strings.Split(fechas, "-")[0] inicio = strings.TrimSpace(inicio) @@ -67,12 +67,12 @@ func BarcodesHandler(storage storage.Storager) httprouter.Handle { return } //set barcodes - barcodes = data + Barcodes = data } // parse template files t, _ := template.ParseFiles("templates/base.html", "templates/barcodes.html") // execute templates - err := t.Execute(w, barcodes) + err := t.Execute(w, Barcodes) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return diff --git a/storage/storage.go b/storage/storage.go index 58993fc..cba71af 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -71,21 +71,23 @@ func (s *storage) ListBarcode(ctx context.Context, lb types.LoadingBed, inicio s if err != nil { return nil, err } + if lb == types.ALL { - if err := s.db.Where("created_at >= ? and created_at < ?", ti, tf).Find(barcodes).WithContext(ctx).Error; err != nil { + if err := s.db.Where("created_at >= ? and created_at < ?", ti, tf).Find(&barcodes).WithContext(ctx).Error; err != nil { return nil, err } } else { - if err := s.db.Where("loading_bed = ? and created_at >= ? and created_at < ?", lb, ti, tf).Find(barcodes).WithContext(ctx).Error; err != nil { + if err := s.db.Where("loading_bed = ? and created_at >= ? and created_at < ?", lb, ti, tf).Find(&barcodes).WithContext(ctx).Error; err != nil { return nil, err } } + fmt.Printf("result: +%v\n", barcodes) return } // Barcode implements Storager. func (s *storage) Barcode(ctx context.Context, reading string) (barcode *types.Barcode, err error) { - if err := s.db.First(barcode, reading).WithContext(ctx).Error; err != nil { + if err := s.db.First(&barcode, reading).WithContext(ctx).Error; err != nil { return nil, err } return diff --git a/templates/barcodes.html b/templates/barcodes.html index e056d8d..a016534 100644 --- a/templates/barcodes.html +++ b/templates/barcodes.html @@ -38,7 +38,7 @@