From 72a4ef9fff81875590213931254ef01df13ce733 Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Thu, 5 Mar 2026 18:55:36 +0000 Subject: [PATCH] Actually update the pool location when we create the lead --- api/lead.go | 22 +++++++++++++++++++--- html/template/sync/intelligence-root.html | 20 ++++++++++---------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/api/lead.go b/api/lead.go index 5c056928..f45072f9 100644 --- a/api/lead.go +++ b/api/lead.go @@ -13,14 +13,16 @@ import ( "github.com/Gleipnir-Technology/nidus-sync/db/enums" "github.com/Gleipnir-Technology/nidus-sync/db/models" nhttp "github.com/Gleipnir-Technology/nidus-sync/http" - //"github.com/rs/zerolog/log" + "github.com/Gleipnir-Technology/nidus-sync/platform/geom" "github.com/aarondl/opt/omit" "github.com/aarondl/opt/omitnull" + "github.com/rs/zerolog/log" "github.com/stephenafamo/scan" ) type createLead struct { - SignalIDs []int `json:"signal_ids"` + PoolLocations map[int]Location `json:"pool_locations"` + SignalIDs []int `json:"signal_ids"` } type createdLead struct { ID int32 `json:"id"` @@ -102,7 +104,21 @@ func postLeads(ctx context.Context, r *http.Request, org *models.Organization, u if err != nil { return nil, nhttp.NewError("failed to update signal %d: %w", signal_id, err) } - + pool_location, ok := req.PoolLocations[signal_id] + if ok { + log.Info().Float64("lat", pool_location.Latitude).Float64("lng", pool_location.Longitude).Msg("got pool location") + geom_query := geom.PostgisPointQuery(pool_location.Longitude, pool_location.Latitude) + _, err = psql.Update( + um.Table("pool"), + um.SetCol("geometry").To(geom_query), + um.From("signal_pool"), + um.Where(psql.Quote("signal_pool", "pool_id").EQ(psql.Quote("pool", "id"))), + um.Where(psql.Quote("signal_pool", "signal_id").EQ(psql.Arg(signal_id))), + ).Exec(ctx, txn) + if err != nil { + return nil, nhttp.NewError("failed to update pool through signal %d: %w", signal_id, err) + } + } txn.Commit(ctx) return &createdLead{ diff --git a/html/template/sync/intelligence-root.html b/html/template/sync/intelligence-root.html index 8d733047..bfd0df0a 100644 --- a/html/template/sync/intelligence-root.html +++ b/html/template/sync/intelligence-root.html @@ -15,16 +15,6 @@