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,
|
Generated: false,
|
||||||
AutoIncr: 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{
|
Gid: column{
|
||||||
Name: "gid",
|
Name: "gid",
|
||||||
DBType: "text",
|
DBType: "text",
|
||||||
|
|
@ -141,6 +123,24 @@ var Addresses = Table[
|
||||||
Generated: false,
|
Generated: false,
|
||||||
AutoIncr: 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{
|
Indexes: addressIndexes{
|
||||||
AddressPkey: index{
|
AddressPkey: index{
|
||||||
|
|
@ -213,25 +213,25 @@ var Addresses = Table[
|
||||||
}
|
}
|
||||||
|
|
||||||
type addressColumns struct {
|
type addressColumns struct {
|
||||||
Country column
|
Country column
|
||||||
Created column
|
Created column
|
||||||
Location column
|
Location column
|
||||||
H3cell column
|
H3cell column
|
||||||
ID column
|
ID column
|
||||||
Locality column
|
Locality column
|
||||||
PostalCode column
|
PostalCode column
|
||||||
Street column
|
Street column
|
||||||
Unit column
|
Unit column
|
||||||
Region column
|
Region column
|
||||||
Number column
|
Number column
|
||||||
LocationX column
|
Gid column
|
||||||
LocationY column
|
LocationLatitude column
|
||||||
Gid column
|
LocationLongitude column
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c addressColumns) AsSlice() []column {
|
func (c addressColumns) AsSlice() []column {
|
||||||
return []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.
|
// Address is an object representing the database table.
|
||||||
type Address struct {
|
type Address struct {
|
||||||
Country string `db:"country" `
|
Country string `db:"country" `
|
||||||
Created time.Time `db:"created" `
|
Created time.Time `db:"created" `
|
||||||
Location string `db:"location" `
|
Location string `db:"location" `
|
||||||
H3cell string `db:"h3cell" `
|
H3cell string `db:"h3cell" `
|
||||||
ID int32 `db:"id,pk" `
|
ID int32 `db:"id,pk" `
|
||||||
Locality string `db:"locality" `
|
Locality string `db:"locality" `
|
||||||
PostalCode string `db:"postal_code" `
|
PostalCode string `db:"postal_code" `
|
||||||
Street string `db:"street" `
|
Street string `db:"street" `
|
||||||
Unit string `db:"unit" `
|
Unit string `db:"unit" `
|
||||||
Region string `db:"region" `
|
Region string `db:"region" `
|
||||||
Number string `db:"number_" `
|
Number string `db:"number_" `
|
||||||
LocationX null.Val[float64] `db:"location_x,generated" `
|
Gid string `db:"gid" `
|
||||||
LocationY null.Val[float64] `db:"location_y,generated" `
|
LocationLatitude null.Val[float64] `db:"location_latitude,generated" `
|
||||||
Gid string `db:"gid" `
|
LocationLongitude null.Val[float64] `db:"location_longitude,generated" `
|
||||||
|
|
||||||
R addressR `db:"-" `
|
R addressR `db:"-" `
|
||||||
}
|
}
|
||||||
|
|
@ -66,43 +66,43 @@ type addressR struct {
|
||||||
func buildAddressColumns(alias string) addressColumns {
|
func buildAddressColumns(alias string) addressColumns {
|
||||||
return addressColumns{
|
return addressColumns{
|
||||||
ColumnsExpr: expr.NewColumnsExpr(
|
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"),
|
).WithParent("address"),
|
||||||
tableAlias: alias,
|
tableAlias: alias,
|
||||||
Country: psql.Quote(alias, "country"),
|
Country: psql.Quote(alias, "country"),
|
||||||
Created: psql.Quote(alias, "created"),
|
Created: psql.Quote(alias, "created"),
|
||||||
Location: psql.Quote(alias, "location"),
|
Location: psql.Quote(alias, "location"),
|
||||||
H3cell: psql.Quote(alias, "h3cell"),
|
H3cell: psql.Quote(alias, "h3cell"),
|
||||||
ID: psql.Quote(alias, "id"),
|
ID: psql.Quote(alias, "id"),
|
||||||
Locality: psql.Quote(alias, "locality"),
|
Locality: psql.Quote(alias, "locality"),
|
||||||
PostalCode: psql.Quote(alias, "postal_code"),
|
PostalCode: psql.Quote(alias, "postal_code"),
|
||||||
Street: psql.Quote(alias, "street"),
|
Street: psql.Quote(alias, "street"),
|
||||||
Unit: psql.Quote(alias, "unit"),
|
Unit: psql.Quote(alias, "unit"),
|
||||||
Region: psql.Quote(alias, "region"),
|
Region: psql.Quote(alias, "region"),
|
||||||
Number: psql.Quote(alias, "number_"),
|
Number: psql.Quote(alias, "number_"),
|
||||||
LocationX: psql.Quote(alias, "location_x"),
|
Gid: psql.Quote(alias, "gid"),
|
||||||
LocationY: psql.Quote(alias, "location_y"),
|
LocationLatitude: psql.Quote(alias, "location_latitude"),
|
||||||
Gid: psql.Quote(alias, "gid"),
|
LocationLongitude: psql.Quote(alias, "location_longitude"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type addressColumns struct {
|
type addressColumns struct {
|
||||||
expr.ColumnsExpr
|
expr.ColumnsExpr
|
||||||
tableAlias string
|
tableAlias string
|
||||||
Country psql.Expression
|
Country psql.Expression
|
||||||
Created psql.Expression
|
Created psql.Expression
|
||||||
Location psql.Expression
|
Location psql.Expression
|
||||||
H3cell psql.Expression
|
H3cell psql.Expression
|
||||||
ID psql.Expression
|
ID psql.Expression
|
||||||
Locality psql.Expression
|
Locality psql.Expression
|
||||||
PostalCode psql.Expression
|
PostalCode psql.Expression
|
||||||
Street psql.Expression
|
Street psql.Expression
|
||||||
Unit psql.Expression
|
Unit psql.Expression
|
||||||
Region psql.Expression
|
Region psql.Expression
|
||||||
Number psql.Expression
|
Number psql.Expression
|
||||||
LocationX psql.Expression
|
Gid psql.Expression
|
||||||
LocationY psql.Expression
|
LocationLatitude psql.Expression
|
||||||
Gid psql.Expression
|
LocationLongitude psql.Expression
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c addressColumns) Alias() string {
|
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 {
|
type addressWhere[Q psql.Filterable] struct {
|
||||||
Country psql.WhereMod[Q, string]
|
Country psql.WhereMod[Q, string]
|
||||||
Created psql.WhereMod[Q, time.Time]
|
Created psql.WhereMod[Q, time.Time]
|
||||||
Location psql.WhereMod[Q, string]
|
Location psql.WhereMod[Q, string]
|
||||||
H3cell psql.WhereMod[Q, string]
|
H3cell psql.WhereMod[Q, string]
|
||||||
ID psql.WhereMod[Q, int32]
|
ID psql.WhereMod[Q, int32]
|
||||||
Locality psql.WhereMod[Q, string]
|
Locality psql.WhereMod[Q, string]
|
||||||
PostalCode psql.WhereMod[Q, string]
|
PostalCode psql.WhereMod[Q, string]
|
||||||
Street psql.WhereMod[Q, string]
|
Street psql.WhereMod[Q, string]
|
||||||
Unit psql.WhereMod[Q, string]
|
Unit psql.WhereMod[Q, string]
|
||||||
Region psql.WhereMod[Q, string]
|
Region psql.WhereMod[Q, string]
|
||||||
Number psql.WhereMod[Q, string]
|
Number psql.WhereMod[Q, string]
|
||||||
LocationX psql.WhereNullMod[Q, float64]
|
Gid psql.WhereMod[Q, string]
|
||||||
LocationY psql.WhereNullMod[Q, float64]
|
LocationLatitude psql.WhereNullMod[Q, float64]
|
||||||
Gid psql.WhereMod[Q, string]
|
LocationLongitude psql.WhereNullMod[Q, float64]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (addressWhere[Q]) AliasedAs(alias string) addressWhere[Q] {
|
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] {
|
func buildAddressWhere[Q psql.Filterable](cols addressColumns) addressWhere[Q] {
|
||||||
return addressWhere[Q]{
|
return addressWhere[Q]{
|
||||||
Country: psql.Where[Q, string](cols.Country),
|
Country: psql.Where[Q, string](cols.Country),
|
||||||
Created: psql.Where[Q, time.Time](cols.Created),
|
Created: psql.Where[Q, time.Time](cols.Created),
|
||||||
Location: psql.Where[Q, string](cols.Location),
|
Location: psql.Where[Q, string](cols.Location),
|
||||||
H3cell: psql.Where[Q, string](cols.H3cell),
|
H3cell: psql.Where[Q, string](cols.H3cell),
|
||||||
ID: psql.Where[Q, int32](cols.ID),
|
ID: psql.Where[Q, int32](cols.ID),
|
||||||
Locality: psql.Where[Q, string](cols.Locality),
|
Locality: psql.Where[Q, string](cols.Locality),
|
||||||
PostalCode: psql.Where[Q, string](cols.PostalCode),
|
PostalCode: psql.Where[Q, string](cols.PostalCode),
|
||||||
Street: psql.Where[Q, string](cols.Street),
|
Street: psql.Where[Q, string](cols.Street),
|
||||||
Unit: psql.Where[Q, string](cols.Unit),
|
Unit: psql.Where[Q, string](cols.Unit),
|
||||||
Region: psql.Where[Q, string](cols.Region),
|
Region: psql.Where[Q, string](cols.Region),
|
||||||
Number: psql.Where[Q, string](cols.Number),
|
Number: psql.Where[Q, string](cols.Number),
|
||||||
LocationX: psql.WhereNull[Q, float64](cols.LocationX),
|
Gid: psql.Where[Q, string](cols.Gid),
|
||||||
LocationY: psql.WhereNull[Q, float64](cols.LocationY),
|
LocationLatitude: psql.WhereNull[Q, float64](cols.LocationLatitude),
|
||||||
Gid: psql.Where[Q, string](cols.Gid),
|
LocationLongitude: psql.WhereNull[Q, float64](cols.LocationLongitude),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -139,6 +139,8 @@ func reportQuery() bob.BaseQuery[*dialect.SelectQuery] {
|
||||||
"COALESCE(a.country, '') AS \"address.country\"",
|
"COALESCE(a.country, '') AS \"address.country\"",
|
||||||
"a.id AS \"address.id\"",
|
"a.id AS \"address.id\"",
|
||||||
"COALESCE(a.gid, '') AS \"address.gid\"",
|
"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.locality, '') AS \"address.locality\"",
|
||||||
"COALESCE(a.number_, '') AS \"address.number\"",
|
"COALESCE(a.number_, '') AS \"address.number\"",
|
||||||
"COALESCE(a.postal_code, '') AS \"address.postal_code\"",
|
"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)
|
return nil, fmt.Errorf("site from address: %w", err)
|
||||||
}
|
}
|
||||||
site_id = site.ID
|
site_id = site.ID
|
||||||
lat := address.LocationY.GetOr(0.0)
|
lat := address.LocationLatitude.GetOr(0.0)
|
||||||
lng := address.LocationX.GetOr(0.0)
|
lng := address.LocationLongitude.GetOr(0.0)
|
||||||
location = fmt.Sprintf("POINT(%f %f)", lng, lat)
|
location = fmt.Sprintf("POINT(%f %f)", lng, lat)
|
||||||
} else if report.LocationLatitude.IsValue() && report.LocationLongitude.IsValue() {
|
} else if report.LocationLatitude.IsValue() && report.LocationLongitude.IsValue() {
|
||||||
lat := report.LocationLatitude.MustGet()
|
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)
|
return nil, fmt.Errorf("find address from raw: %w", err)
|
||||||
}
|
}
|
||||||
site_id = site.ID
|
site_id = site.ID
|
||||||
lat := address.LocationY.GetOr(0.0)
|
lat := address.LocationLatitude.GetOr(0.0)
|
||||||
lng := address.LocationX.GetOr(0.0)
|
lng := address.LocationLongitude.GetOr(0.0)
|
||||||
location = fmt.Sprintf("POINT(%f %f)", lng, lat)
|
location = fmt.Sprintf("POINT(%f %f)", lng, lat)
|
||||||
} else {
|
} else {
|
||||||
// We have no structured address, no GPS, no unstructued address.
|
// 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)
|
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 {
|
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{
|
return Address{
|
||||||
Country: m.Country,
|
Country: m.Country,
|
||||||
GID: m.Gid,
|
GID: m.Gid,
|
||||||
ID: &m.ID,
|
ID: &m.ID,
|
||||||
Locality: m.Locality,
|
Locality: m.Locality,
|
||||||
Location: &Location{
|
Location: &Location{
|
||||||
Latitude: m.LocationY.GetOr(0.0),
|
Latitude: m.LocationLatitude.GetOr(0.0),
|
||||||
Longitude: m.LocationX.GetOr(0.0),
|
Longitude: m.LocationLongitude.GetOr(0.0),
|
||||||
},
|
},
|
||||||
Number: m.Number,
|
Number: m.Number,
|
||||||
PostalCode: m.PostalCode,
|
PostalCode: m.PostalCode,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue