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{
|
||||
|
|
@ -213,25 +213,25 @@ var Addresses = Table[
|
|||
}
|
||||
|
||||
type addressColumns struct {
|
||||
Country column
|
||||
Created column
|
||||
Location column
|
||||
H3cell column
|
||||
ID column
|
||||
Locality column
|
||||
PostalCode column
|
||||
Street column
|
||||
Unit column
|
||||
Region column
|
||||
Number column
|
||||
LocationX column
|
||||
LocationY column
|
||||
Gid column
|
||||
Country column
|
||||
Created column
|
||||
Location column
|
||||
H3cell column
|
||||
ID column
|
||||
Locality column
|
||||
PostalCode column
|
||||
Street column
|
||||
Unit column
|
||||
Region column
|
||||
Number 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;
|
||||
|
|
@ -25,20 +25,20 @@ import (
|
|||
|
||||
// Address is an object representing the database table.
|
||||
type Address struct {
|
||||
Country string `db:"country" `
|
||||
Created time.Time `db:"created" `
|
||||
Location string `db:"location" `
|
||||
H3cell string `db:"h3cell" `
|
||||
ID int32 `db:"id,pk" `
|
||||
Locality string `db:"locality" `
|
||||
PostalCode string `db:"postal_code" `
|
||||
Street string `db:"street" `
|
||||
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" `
|
||||
Country string `db:"country" `
|
||||
Created time.Time `db:"created" `
|
||||
Location string `db:"location" `
|
||||
H3cell string `db:"h3cell" `
|
||||
ID int32 `db:"id,pk" `
|
||||
Locality string `db:"locality" `
|
||||
PostalCode string `db:"postal_code" `
|
||||
Street string `db:"street" `
|
||||
Unit string `db:"unit" `
|
||||
Region string `db:"region" `
|
||||
Number string `db:"number_" `
|
||||
Gid string `db:"gid" `
|
||||
LocationLatitude null.Val[float64] `db:"location_latitude,generated" `
|
||||
LocationLongitude null.Val[float64] `db:"location_longitude,generated" `
|
||||
|
||||
R addressR `db:"-" `
|
||||
}
|
||||
|
|
@ -66,43 +66,43 @@ 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"),
|
||||
Created: psql.Quote(alias, "created"),
|
||||
Location: psql.Quote(alias, "location"),
|
||||
H3cell: psql.Quote(alias, "h3cell"),
|
||||
ID: psql.Quote(alias, "id"),
|
||||
Locality: psql.Quote(alias, "locality"),
|
||||
PostalCode: psql.Quote(alias, "postal_code"),
|
||||
Street: psql.Quote(alias, "street"),
|
||||
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"),
|
||||
tableAlias: alias,
|
||||
Country: psql.Quote(alias, "country"),
|
||||
Created: psql.Quote(alias, "created"),
|
||||
Location: psql.Quote(alias, "location"),
|
||||
H3cell: psql.Quote(alias, "h3cell"),
|
||||
ID: psql.Quote(alias, "id"),
|
||||
Locality: psql.Quote(alias, "locality"),
|
||||
PostalCode: psql.Quote(alias, "postal_code"),
|
||||
Street: psql.Quote(alias, "street"),
|
||||
Unit: psql.Quote(alias, "unit"),
|
||||
Region: psql.Quote(alias, "region"),
|
||||
Number: psql.Quote(alias, "number_"),
|
||||
Gid: psql.Quote(alias, "gid"),
|
||||
LocationLatitude: psql.Quote(alias, "location_latitude"),
|
||||
LocationLongitude: psql.Quote(alias, "location_longitude"),
|
||||
}
|
||||
}
|
||||
|
||||
type addressColumns struct {
|
||||
expr.ColumnsExpr
|
||||
tableAlias string
|
||||
Country psql.Expression
|
||||
Created psql.Expression
|
||||
Location psql.Expression
|
||||
H3cell psql.Expression
|
||||
ID psql.Expression
|
||||
Locality psql.Expression
|
||||
PostalCode psql.Expression
|
||||
Street psql.Expression
|
||||
Unit psql.Expression
|
||||
Region psql.Expression
|
||||
Number psql.Expression
|
||||
LocationX psql.Expression
|
||||
LocationY psql.Expression
|
||||
Gid psql.Expression
|
||||
tableAlias string
|
||||
Country psql.Expression
|
||||
Created psql.Expression
|
||||
Location psql.Expression
|
||||
H3cell psql.Expression
|
||||
ID psql.Expression
|
||||
Locality psql.Expression
|
||||
PostalCode psql.Expression
|
||||
Street psql.Expression
|
||||
Unit psql.Expression
|
||||
Region psql.Expression
|
||||
Number psql.Expression
|
||||
Gid psql.Expression
|
||||
LocationLatitude psql.Expression
|
||||
LocationLongitude psql.Expression
|
||||
}
|
||||
|
||||
func (c addressColumns) Alias() string {
|
||||
|
|
@ -1150,20 +1150,20 @@ func (address0 *Address) AttachSite(ctx context.Context, exec bob.Executor, site
|
|||
}
|
||||
|
||||
type addressWhere[Q psql.Filterable] struct {
|
||||
Country psql.WhereMod[Q, string]
|
||||
Created psql.WhereMod[Q, time.Time]
|
||||
Location psql.WhereMod[Q, string]
|
||||
H3cell psql.WhereMod[Q, string]
|
||||
ID psql.WhereMod[Q, int32]
|
||||
Locality psql.WhereMod[Q, string]
|
||||
PostalCode psql.WhereMod[Q, string]
|
||||
Street psql.WhereMod[Q, string]
|
||||
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]
|
||||
Country psql.WhereMod[Q, string]
|
||||
Created psql.WhereMod[Q, time.Time]
|
||||
Location psql.WhereMod[Q, string]
|
||||
H3cell psql.WhereMod[Q, string]
|
||||
ID psql.WhereMod[Q, int32]
|
||||
Locality psql.WhereMod[Q, string]
|
||||
PostalCode psql.WhereMod[Q, string]
|
||||
Street psql.WhereMod[Q, string]
|
||||
Unit psql.WhereMod[Q, string]
|
||||
Region psql.WhereMod[Q, string]
|
||||
Number psql.WhereMod[Q, string]
|
||||
Gid psql.WhereMod[Q, string]
|
||||
LocationLatitude psql.WhereNullMod[Q, float64]
|
||||
LocationLongitude psql.WhereNullMod[Q, float64]
|
||||
}
|
||||
|
||||
func (addressWhere[Q]) AliasedAs(alias string) addressWhere[Q] {
|
||||
|
|
@ -1172,20 +1172,20 @@ func (addressWhere[Q]) AliasedAs(alias string) addressWhere[Q] {
|
|||
|
||||
func buildAddressWhere[Q psql.Filterable](cols addressColumns) addressWhere[Q] {
|
||||
return addressWhere[Q]{
|
||||
Country: psql.Where[Q, string](cols.Country),
|
||||
Created: psql.Where[Q, time.Time](cols.Created),
|
||||
Location: psql.Where[Q, string](cols.Location),
|
||||
H3cell: psql.Where[Q, string](cols.H3cell),
|
||||
ID: psql.Where[Q, int32](cols.ID),
|
||||
Locality: psql.Where[Q, string](cols.Locality),
|
||||
PostalCode: psql.Where[Q, string](cols.PostalCode),
|
||||
Street: psql.Where[Q, string](cols.Street),
|
||||
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),
|
||||
Country: psql.Where[Q, string](cols.Country),
|
||||
Created: psql.Where[Q, time.Time](cols.Created),
|
||||
Location: psql.Where[Q, string](cols.Location),
|
||||
H3cell: psql.Where[Q, string](cols.H3cell),
|
||||
ID: psql.Where[Q, int32](cols.ID),
|
||||
Locality: psql.Where[Q, string](cols.Locality),
|
||||
PostalCode: psql.Where[Q, string](cols.PostalCode),
|
||||
Street: psql.Where[Q, string](cols.Street),
|
||||
Unit: psql.Where[Q, string](cols.Unit),
|
||||
Region: psql.Where[Q, string](cols.Region),
|
||||
Number: psql.Where[Q, string](cols.Number),
|
||||
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