From 5464678ae5dceb88d64e23424cdc813ff6581ee2 Mon Sep 17 00:00:00 2001 From: Tiago Ribeiro Date: Mon, 9 Mar 2026 09:20:49 -0300 Subject: [PATCH] chore: add geocode sync CLI tool --- backend/cmd/geocode_sync/main.go | 41 ++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 backend/cmd/geocode_sync/main.go diff --git a/backend/cmd/geocode_sync/main.go b/backend/cmd/geocode_sync/main.go new file mode 100644 index 0000000..c169d54 --- /dev/null +++ b/backend/cmd/geocode_sync/main.go @@ -0,0 +1,41 @@ +package main + +import ( + "context" + "fmt" + "log" + + "github.com/jmoiron/sqlx" + _ "github.com/jackc/pgx/v5/stdlib" + "github.com/saveinmed/backend-go/internal/config" + "github.com/saveinmed/backend-go/internal/infrastructure/mapbox" + "github.com/saveinmed/backend-go/internal/infrastructure/notifications" + "github.com/saveinmed/backend-go/internal/repository/postgres" + "github.com/saveinmed/backend-go/internal/usecase" +) + +func main() { + cfg, err := config.Load() + if err != nil { + log.Fatalf("failed to load config: %v", err) + } + + db, err := sqlx.Open("pgx", cfg.DatabaseURL) + if err != nil { + log.Fatalf("failed to open db: %v", err) + } + + repo := postgres.New(db) + mapboxClient := mapbox.New(cfg.MapboxAccessToken) + notifySvc := notifications.NewLoggerNotificationService() + + svc := usecase.NewService(repo, nil, mapboxClient, notifySvc, 12.0, 0.06, cfg.JWTSecret, cfg.JWTExpiresIn, cfg.PasswordPepper) + + fmt.Println("Starting retroactive geocode sync...") + count, err := svc.GeocodeAllAddresses(context.Background()) + if err != nil { + log.Fatalf("failed to sync: %v", err) + } + + fmt.Printf("Successfully updated %d addresses with coordinates.\n", count) +}