chore: add geocode sync CLI tool
This commit is contained in:
parent
f54c619fc7
commit
5464678ae5
1 changed files with 41 additions and 0 deletions
41
backend/cmd/geocode_sync/main.go
Normal file
41
backend/cmd/geocode_sync/main.go
Normal file
|
|
@ -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)
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue