This commit is contained in:
aespin 2024-10-07 15:24:46 +02:00
parent eb99161ada
commit 06f9de21d1
4 changed files with 47 additions and 10 deletions

View File

@ -22,6 +22,7 @@ func Run() error {
dbHost := flag.String("db-host", "db", "database host address") dbHost := flag.String("db-host", "db", "database host address")
dbPort := flag.Int("db-port", 5432, "database tcp port") dbPort := flag.Int("db-port", 5432, "database tcp port")
dbName := flag.String("db-name", "falcon", "database user password") dbName := flag.String("db-name", "falcon", "database user password")
flag.Parse()
// setup logger // setup logger
log := logger.New(os.Stdout, *logLevel) log := logger.New(os.Stdout, *logLevel)
// log fields // log fields

View File

@ -27,7 +27,7 @@ func BarcodesHandler(storage storage.Storager) httprouter.Handle {
// post method // post method
if r.Method == http.MethodPost { if r.Method == http.MethodPost {
// barcodes holder // barcodes holder
barcodes := []types.Barcode{} Barcodes := []types.Barcode{}
// parse form data from formulary // parse form data from formulary
if err := r.ParseForm(); err != nil { if err := r.ParseForm(); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
@ -47,7 +47,7 @@ func BarcodesHandler(storage storage.Storager) httprouter.Handle {
return return
} }
// append barcode to holder // append barcode to holder
barcodes = append(barcodes, *data) Barcodes = append(Barcodes, *data)
} else { } else {
inicio := strings.Split(fechas, "-")[0] inicio := strings.Split(fechas, "-")[0]
inicio = strings.TrimSpace(inicio) inicio = strings.TrimSpace(inicio)
@ -67,12 +67,12 @@ func BarcodesHandler(storage storage.Storager) httprouter.Handle {
return return
} }
//set barcodes //set barcodes
barcodes = data Barcodes = data
} }
// parse template files // parse template files
t, _ := template.ParseFiles("templates/base.html", "templates/barcodes.html") t, _ := template.ParseFiles("templates/base.html", "templates/barcodes.html")
// execute templates // execute templates
err := t.Execute(w, barcodes) err := t.Execute(w, Barcodes)
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
return return

View File

@ -71,21 +71,23 @@ func (s *storage) ListBarcode(ctx context.Context, lb types.LoadingBed, inicio s
if err != nil { if err != nil {
return nil, err return nil, err
} }
if lb == types.ALL { 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 return nil, err
} }
} else { } 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 return nil, err
} }
} }
fmt.Printf("result: +%v\n", barcodes)
return return
} }
// Barcode implements Storager. // Barcode implements Storager.
func (s *storage) Barcode(ctx context.Context, reading string) (barcode *types.Barcode, err error) { 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 nil, err
} }
return return

View File

@ -38,7 +38,7 @@
</div> </div>
<div class="column"> <div class="column">
<nav class="panel is-link"> <nav class="panel is-link">
<p class="panel-heading"><i class="far fa-file"></i> Listar códigos leídos</p> <p class="panel-heading"><i class="far fa-file"></i> Busqueda de códigos</p>
<form action="/barcodes" method="post"> <form action="/barcodes" method="post">
<div class="panel-block"> <div class="panel-block">
<div class="field"> <div class="field">
@ -91,6 +91,40 @@
</form> </form>
</nav> </nav>
</div> </div>
{{ if .}}
<div class="column">
<nav class="panel is-link">
<p class="panel-heading"><i class="far fa-file"></i> Listado códigos leídos</p>
<div class="panel-block">
<table class="table">
<thead>
<tr>
<th><abbr title="Unidad de almacén">UA</abbr></th>
<th>Origen</th>
<th>Fecha</th>
</tr>
</thead>
<tfoot>
<tr>
<th><abbr title="Unidad de almacén">UA</abbr></th>
<th>Origen</th>
<th>Fecha</th>
</tr>
</tfoot>
<tbody>
{{ range . }}
<tr>
<td>{{ .Barcode }}</td>
<td>{{ .LoadingBed }}</td>
<td>{{ .CreatedAt }}</td>
</tr>
{{ end }}
</tbody>
</table>
</div>
</nav>
</div>
{{ end }}
</div> </div>
</div> </div>
<script src="/assets/js/barcode.js"> <script src="/assets/js/barcode.js">