From 47333ebf8e0e76f653af83e6c3d1a44b52dfb8f4 Mon Sep 17 00:00:00 2001 From: Fmar Date: Thu, 9 May 2024 19:01:58 +0200 Subject: [PATCH] added single invoice by hash support for republishing --- cmd/invoice-republishing/main.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/cmd/invoice-republishing/main.go b/cmd/invoice-republishing/main.go index d3569c37..6a17610a 100644 --- a/cmd/invoice-republishing/main.go +++ b/cmd/invoice-republishing/main.go @@ -25,10 +25,7 @@ func main() { fmt.Println("Failed to load .env file") } logger := lib.Logger(c.LogFilePath) - startDate, endDate, err := loadStartAndEndIdFromEnv() - if err != nil { - logger.Fatalf("Could not load start and end id from env %v", err) - } + err = envconfig.Process("", c) if err != nil { logger.Fatalf("Error loading environment variables: %v", err) @@ -63,7 +60,20 @@ func main() { defer rabbitmqClient.Close() result := []models.Invoice{} - err = dbConn.NewSelect().Model(&result).Where("settled_at > ?", startDate).Where("settled_at < ?", endDate).Scan(context.Background()) + + singleInvoiceHash := os.Getenv("REPUBLISH_INVOICE_HASH") + + if singleInvoiceHash != "" { + err = dbConn.NewSelect().Model(&result).Where("r_hash = ?", singleInvoiceHash).Scan(context.Background()) + } else { + startDate, endDate, err1 := loadStartAndEndIdFromEnv() + + if err1 != nil { + logger.Fatalf("Could not load start and end id from env %v", err1) + } + + err = dbConn.NewSelect().Model(&result).Where("settled_at > ?", startDate).Where("settled_at < ?", endDate).Scan(context.Background()) + } if err != nil { logger.Fatal(err) }