This commit is contained in:
aespin 2024-10-07 11:32:26 +02:00
parent 193b82725f
commit eb99161ada
2 changed files with 49 additions and 10 deletions

View File

@ -16,7 +16,7 @@ COPY . .
RUN go get -d -v ./...
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -mod=mod -ldflags "-s -w" -o cml04-falcon-system main.go
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -mod=mod -ldflags "-s -w" -o cml04-falcon-ui main.go
# Etapa de producción
@ -33,6 +33,6 @@ ADD templates /root/templates
RUN update-ca-certificates
WORKDIR /root/
COPY --from=builder /app/cml04-falcon-system .
COPY --from=builder /app/cml04-falcon-ui .
CMD ["./cml04-falcon-ui"]

View File

@ -4,6 +4,7 @@ import (
"context"
"fmt"
"sync"
"time"
"git.espin.casa/albert/cml04-falcon-ui/types"
"gorm.io/driver/postgres"
@ -22,7 +23,7 @@ type Storager interface {
Barcode(ctx context.Context, reading string) (barcode *types.Barcode, err error)
ListBarcode(ctx context.Context, lb types.LoadingBed, inicio, final string) (barcodes []types.Barcode, err error)
Bundle(ctx context.Context, ua string) (bundle *types.BundleData, err error)
ListBundle(ctx context.Context)
ListBundle(ctx context.Context, lb types.LoadingBed, inicio string, final string) (bundles []types.BundleData, err error)
}
type storage struct {
@ -31,25 +32,63 @@ type storage struct {
}
// ListBundle implements Storager.
func (s *storage) ListBundle(ctx context.Context) {
panic("unimplemented")
func (s *storage) ListBundle(ctx context.Context, lb types.LoadingBed, inicio string, final string) (bundles []types.BundleData, err error) {
ti, err := time.Parse("02/01/2006 15:04", inicio)
if err != nil {
return nil, err
}
tf, err := time.Parse("02/01/2006 15:04", final)
if err != nil {
return nil, err
}
if lb == types.ALL {
if err := s.db.Where("created_at >= ? and created_at < ?", ti, tf).Find(bundles).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(bundles).WithContext(ctx).Error; err != nil {
return nil, err
}
}
return
}
// Bundle implements Storager.
func (s *storage) Bundle(ctx context.Context, ua string) (bundle *types.BundleData, err error) {
panic("unimplemented")
if err := s.db.First(bundle, ua).WithContext(ctx).Error; err != nil {
return nil, err
}
return
}
// ListBarcode implements Storager.
func (s *storage) ListBarcode(ctx context.Context, lb types.LoadingBed, inicio string, final string) (barcodes []types.Barcode, err error) {
fmt.Println(lb, inicio, final)
return []types.Barcode{}, nil
ti, err := time.Parse("02/01/2006 15:04", inicio)
if err != nil {
return nil, err
}
tf, err := time.Parse("02/01/2006 15:04", final)
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 {
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 {
return nil, err
}
}
return
}
// Barcode implements Storager.
func (s *storage) Barcode(ctx context.Context, reading string) (barcode *types.Barcode, err error) {
fmt.Println(reading)
return &types.Barcode{}, nil
if err := s.db.First(barcode, reading).WithContext(ctx).Error; err != nil {
return nil, err
}
return
}
func ProductionDataBase(conf *DBConfig) (*gorm.DB, error) {