From eb99161ada67081a07c16ef6c333cc4472c30733 Mon Sep 17 00:00:00 2001 From: aespin Date: Mon, 7 Oct 2024 11:32:26 +0200 Subject: [PATCH] wip --- docker/Dockerfile | 4 ++-- storage/storage.go | 55 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 3192255..fb87d3f 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -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"] \ No newline at end of file diff --git a/storage/storage.go b/storage/storage.go index 087045b..58993fc 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -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) {