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) +}