Fix address lat/lng location names, populate in report response
This commit is contained in:
parent
7e2a22c58c
commit
59e58840c9
6 changed files with 129 additions and 113 deletions
|
|
@ -114,24 +114,6 @@ var Addresses = Table[
|
|||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
LocationX: column{
|
||||
Name: "location_x",
|
||||
DBType: "double precision",
|
||||
Default: "GENERATED",
|
||||
Comment: "",
|
||||
Nullable: true,
|
||||
Generated: true,
|
||||
AutoIncr: false,
|
||||
},
|
||||
LocationY: column{
|
||||
Name: "location_y",
|
||||
DBType: "double precision",
|
||||
Default: "GENERATED",
|
||||
Comment: "",
|
||||
Nullable: true,
|
||||
Generated: true,
|
||||
AutoIncr: false,
|
||||
},
|
||||
Gid: column{
|
||||
Name: "gid",
|
||||
DBType: "text",
|
||||
|
|
@ -141,6 +123,24 @@ var Addresses = Table[
|
|||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
LocationLatitude: column{
|
||||
Name: "location_latitude",
|
||||
DBType: "double precision",
|
||||
Default: "GENERATED",
|
||||
Comment: "",
|
||||
Nullable: true,
|
||||
Generated: true,
|
||||
AutoIncr: false,
|
||||
},
|
||||
LocationLongitude: column{
|
||||
Name: "location_longitude",
|
||||
DBType: "double precision",
|
||||
Default: "GENERATED",
|
||||
Comment: "",
|
||||
Nullable: true,
|
||||
Generated: true,
|
||||
AutoIncr: false,
|
||||
},
|
||||
},
|
||||
Indexes: addressIndexes{
|
||||
AddressPkey: index{
|
||||
|
|
@ -224,14 +224,14 @@ type addressColumns struct {
|
|||
Unit column
|
||||
Region column
|
||||
Number column
|
||||
LocationX column
|
||||
LocationY column
|
||||
Gid column
|
||||
LocationLatitude column
|
||||
LocationLongitude column
|
||||
}
|
||||
|
||||
func (c addressColumns) AsSlice() []column {
|
||||
return []column{
|
||||
c.Country, c.Created, c.Location, c.H3cell, c.ID, c.Locality, c.PostalCode, c.Street, c.Unit, c.Region, c.Number, c.LocationX, c.LocationY, c.Gid,
|
||||
c.Country, c.Created, c.Location, c.H3cell, c.ID, c.Locality, c.PostalCode, c.Street, c.Unit, c.Region, c.Number, c.Gid, c.LocationLatitude, c.LocationLongitude,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
14
db/migrations/00134_address_location_names.sql
Normal file
14
db/migrations/00134_address_location_names.sql
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
-- +goose Up
|
||||
ALTER TABLE address
|
||||
DROP COLUMN location_x,
|
||||
DROP COLUMN location_y;
|
||||
ALTER TABLE address
|
||||
ADD COLUMN location_latitude DOUBLE PRECISION GENERATED ALWAYS AS (ST_Y(location)) STORED,
|
||||
ADD COLUMN location_longitude DOUBLE PRECISION GENERATED ALWAYS AS (ST_X(location)) STORED;
|
||||
-- +goose Down
|
||||
ALTER TABLE address
|
||||
DROP COLUMN location_latitude,
|
||||
DROP COLUMN location_longitude;
|
||||
ALTER TABLE address
|
||||
ADD COLUMN location_y DOUBLE PRECISION GENERATED ALWAYS AS (ST_Y(location)) STORED,
|
||||
ADD COLUMN location_x DOUBLE PRECISION GENERATED ALWAYS AS (ST_X(location)) STORED;
|
||||
|
|
@ -36,9 +36,9 @@ type Address struct {
|
|||
Unit string `db:"unit" `
|
||||
Region string `db:"region" `
|
||||
Number string `db:"number_" `
|
||||
LocationX null.Val[float64] `db:"location_x,generated" `
|
||||
LocationY null.Val[float64] `db:"location_y,generated" `
|
||||
Gid string `db:"gid" `
|
||||
LocationLatitude null.Val[float64] `db:"location_latitude,generated" `
|
||||
LocationLongitude null.Val[float64] `db:"location_longitude,generated" `
|
||||
|
||||
R addressR `db:"-" `
|
||||
}
|
||||
|
|
@ -66,7 +66,7 @@ type addressR struct {
|
|||
func buildAddressColumns(alias string) addressColumns {
|
||||
return addressColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"country", "created", "location", "h3cell", "id", "locality", "postal_code", "street", "unit", "region", "number_", "location_x", "location_y", "gid",
|
||||
"country", "created", "location", "h3cell", "id", "locality", "postal_code", "street", "unit", "region", "number_", "gid", "location_latitude", "location_longitude",
|
||||
).WithParent("address"),
|
||||
tableAlias: alias,
|
||||
Country: psql.Quote(alias, "country"),
|
||||
|
|
@ -80,9 +80,9 @@ func buildAddressColumns(alias string) addressColumns {
|
|||
Unit: psql.Quote(alias, "unit"),
|
||||
Region: psql.Quote(alias, "region"),
|
||||
Number: psql.Quote(alias, "number_"),
|
||||
LocationX: psql.Quote(alias, "location_x"),
|
||||
LocationY: psql.Quote(alias, "location_y"),
|
||||
Gid: psql.Quote(alias, "gid"),
|
||||
LocationLatitude: psql.Quote(alias, "location_latitude"),
|
||||
LocationLongitude: psql.Quote(alias, "location_longitude"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -100,9 +100,9 @@ type addressColumns struct {
|
|||
Unit psql.Expression
|
||||
Region psql.Expression
|
||||
Number psql.Expression
|
||||
LocationX psql.Expression
|
||||
LocationY psql.Expression
|
||||
Gid psql.Expression
|
||||
LocationLatitude psql.Expression
|
||||
LocationLongitude psql.Expression
|
||||
}
|
||||
|
||||
func (c addressColumns) Alias() string {
|
||||
|
|
@ -1161,9 +1161,9 @@ type addressWhere[Q psql.Filterable] struct {
|
|||
Unit psql.WhereMod[Q, string]
|
||||
Region psql.WhereMod[Q, string]
|
||||
Number psql.WhereMod[Q, string]
|
||||
LocationX psql.WhereNullMod[Q, float64]
|
||||
LocationY psql.WhereNullMod[Q, float64]
|
||||
Gid psql.WhereMod[Q, string]
|
||||
LocationLatitude psql.WhereNullMod[Q, float64]
|
||||
LocationLongitude psql.WhereNullMod[Q, float64]
|
||||
}
|
||||
|
||||
func (addressWhere[Q]) AliasedAs(alias string) addressWhere[Q] {
|
||||
|
|
@ -1183,9 +1183,9 @@ func buildAddressWhere[Q psql.Filterable](cols addressColumns) addressWhere[Q] {
|
|||
Unit: psql.Where[Q, string](cols.Unit),
|
||||
Region: psql.Where[Q, string](cols.Region),
|
||||
Number: psql.Where[Q, string](cols.Number),
|
||||
LocationX: psql.WhereNull[Q, float64](cols.LocationX),
|
||||
LocationY: psql.WhereNull[Q, float64](cols.LocationY),
|
||||
Gid: psql.Where[Q, string](cols.Gid),
|
||||
LocationLatitude: psql.WhereNull[Q, float64](cols.LocationLatitude),
|
||||
LocationLongitude: psql.WhereNull[Q, float64](cols.LocationLongitude),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -139,6 +139,8 @@ func reportQuery() bob.BaseQuery[*dialect.SelectQuery] {
|
|||
"COALESCE(a.country, '') AS \"address.country\"",
|
||||
"a.id AS \"address.id\"",
|
||||
"COALESCE(a.gid, '') AS \"address.gid\"",
|
||||
"COALESCE(a.location_latitude, 0) AS \"address.location.latitude\"",
|
||||
"COALESCE(a.location_longitude, 0) AS \"address.location.longitude\"",
|
||||
"COALESCE(a.locality, '') AS \"address.locality\"",
|
||||
"COALESCE(a.number_, '') AS \"address.number\"",
|
||||
"COALESCE(a.postal_code, '') AS \"address.postal_code\"",
|
||||
|
|
|
|||
|
|
@ -70,8 +70,8 @@ func SignalCreateFromPublicreport(ctx context.Context, user User, report_id stri
|
|||
return nil, fmt.Errorf("site from address: %w", err)
|
||||
}
|
||||
site_id = site.ID
|
||||
lat := address.LocationY.GetOr(0.0)
|
||||
lng := address.LocationX.GetOr(0.0)
|
||||
lat := address.LocationLatitude.GetOr(0.0)
|
||||
lng := address.LocationLongitude.GetOr(0.0)
|
||||
location = fmt.Sprintf("POINT(%f %f)", lng, lat)
|
||||
} else if report.LocationLatitude.IsValue() && report.LocationLongitude.IsValue() {
|
||||
lat := report.LocationLatitude.MustGet()
|
||||
|
|
@ -97,8 +97,8 @@ func SignalCreateFromPublicreport(ctx context.Context, user User, report_id stri
|
|||
return nil, fmt.Errorf("find address from raw: %w", err)
|
||||
}
|
||||
site_id = site.ID
|
||||
lat := address.LocationY.GetOr(0.0)
|
||||
lng := address.LocationX.GetOr(0.0)
|
||||
lat := address.LocationLatitude.GetOr(0.0)
|
||||
lng := address.LocationLongitude.GetOr(0.0)
|
||||
location = fmt.Sprintf("POINT(%f %f)", lng, lat)
|
||||
} else {
|
||||
// We have no structured address, no GPS, no unstructued address.
|
||||
|
|
|
|||
|
|
@ -25,15 +25,15 @@ func (a Address) String() string {
|
|||
return fmt.Sprintf("%s %s, %s, %s, %s, %s", a.Number, a.Street, a.Locality, a.Region, a.PostalCode, a.Country)
|
||||
}
|
||||
func AddressFromModel(m *models.Address) Address {
|
||||
log.Debug().Int32("id", m.ID).Float64("lat", m.LocationY.GetOr(0.0)).Float64("lng", m.LocationX.GetOr(0.0)).Msg("converting address")
|
||||
log.Debug().Int32("id", m.ID).Float64("lat", m.LocationLatitude.GetOr(0.0)).Float64("lng", m.LocationLongitude.GetOr(0.0)).Msg("converting address")
|
||||
return Address{
|
||||
Country: m.Country,
|
||||
GID: m.Gid,
|
||||
ID: &m.ID,
|
||||
Locality: m.Locality,
|
||||
Location: &Location{
|
||||
Latitude: m.LocationY.GetOr(0.0),
|
||||
Longitude: m.LocationX.GetOr(0.0),
|
||||
Latitude: m.LocationLatitude.GetOr(0.0),
|
||||
Longitude: m.LocationLongitude.GetOr(0.0),
|
||||
},
|
||||
Number: m.Number,
|
||||
PostalCode: m.PostalCode,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue