Remove now-empty report address fields
We'll instead create address rows and reference those
This commit is contained in:
parent
5306f8ba62
commit
9ba99d5ceb
10 changed files with 128 additions and 312 deletions
|
|
@ -82,9 +82,9 @@ func AddRoutes(r *mux.Router) {
|
|||
r.Handle("/geocode/suggestion", handlerJSONSlice(geocode.SuggestionList)).Methods("GET")
|
||||
publicreport := resource.Publicreport(router)
|
||||
r.Handle("/publicreport/{id}", handlerJSON(publicreport.ByID)).Methods("GET").Name("publicreport.ByIDGet")
|
||||
r.Handle("/publicreport/{id}", handlerJSONPut(publicreport.Update)).Methods("PUT")
|
||||
r.Handle("/publicreport/{id}/image", handlerFormPost(publicreport.ImageCreate)).Methods("POST")
|
||||
r.Handle("/publicreport/compliance/{id}", handlerJSON(publicreport.ByIDCompliance)).Methods("GET").Name("publicreport.compliance.ByIDGet")
|
||||
r.Handle("/publicreport/compliance/{id}", handlerJSON(compliance.ByID)).Methods("GET").Name("publicreport.compliance.ByIDGet")
|
||||
r.Handle("/publicreport/compliance/{id}", handlerJSONPut(publicreport.UpdateCompliance)).Methods("PUT")
|
||||
r.Handle("/publicreport/nuisance/{id}", handlerJSON(publicreport.ByIDNuisance)).Methods("GET").Name("publicreport.nuisance.ByIDGet")
|
||||
r.Handle("/publicreport/water/{id}", handlerJSON(publicreport.ByIDWater)).Methods("GET").Name("publicreport.water.ByIDGet")
|
||||
|
||||
|
|
|
|||
|
|
@ -24,60 +24,6 @@ var PublicreportReports = Table[
|
|||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
AddressNumber: column{
|
||||
Name: "address_number",
|
||||
DBType: "text",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
AddressStreet: column{
|
||||
Name: "address_street",
|
||||
DBType: "text",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
AddressLocality: column{
|
||||
Name: "address_locality",
|
||||
DBType: "text",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
AddressRegion: column{
|
||||
Name: "address_region",
|
||||
DBType: "text",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
AddressPostalCode: column{
|
||||
Name: "address_postal_code",
|
||||
DBType: "text",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
AddressCountry: column{
|
||||
Name: "address_country",
|
||||
DBType: "text",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
AddressID: column{
|
||||
Name: "address_id",
|
||||
DBType: "integer",
|
||||
|
|
@ -369,12 +315,6 @@ var PublicreportReports = Table[
|
|||
|
||||
type publicreportReportColumns struct {
|
||||
AddressRaw column
|
||||
AddressNumber column
|
||||
AddressStreet column
|
||||
AddressLocality column
|
||||
AddressRegion column
|
||||
AddressPostalCode column
|
||||
AddressCountry column
|
||||
AddressID column
|
||||
Created column
|
||||
Location column
|
||||
|
|
@ -401,7 +341,7 @@ type publicreportReportColumns struct {
|
|||
|
||||
func (c publicreportReportColumns) AsSlice() []column {
|
||||
return []column{
|
||||
c.AddressRaw, c.AddressNumber, c.AddressStreet, c.AddressLocality, c.AddressRegion, c.AddressPostalCode, c.AddressCountry, c.AddressID, c.Created, c.Location, c.H3cell, c.ID, c.LatlngAccuracyType, c.LatlngAccuracyValue, c.MapZoom, c.OrganizationID, c.PublicID, c.ReporterName, c.ReporterEmail, c.ReporterPhone, c.ReporterContactConsent, c.ReportType, c.Reviewed, c.ReviewerID, c.Status, c.LocationLatitude, c.LocationLongitude, c.AddressGid, c.ClientUUID,
|
||||
c.AddressRaw, c.AddressID, c.Created, c.Location, c.H3cell, c.ID, c.LatlngAccuracyType, c.LatlngAccuracyValue, c.MapZoom, c.OrganizationID, c.PublicID, c.ReporterName, c.ReporterEmail, c.ReporterPhone, c.ReporterContactConsent, c.ReportType, c.Reviewed, c.ReviewerID, c.Status, c.LocationLatitude, c.LocationLongitude, c.AddressGid, c.ClientUUID,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
49
db/migrations/00131_publicreport_address_consolidation.sql
Normal file
49
db/migrations/00131_publicreport_address_consolidation.sql
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
-- +goose Up
|
||||
WITH new_addresses AS (
|
||||
INSERT INTO address (
|
||||
country,
|
||||
locality,
|
||||
postal_code,
|
||||
street,
|
||||
number_,
|
||||
region,
|
||||
gid,
|
||||
location,
|
||||
h3cell,
|
||||
created,
|
||||
unit
|
||||
)
|
||||
SELECT DISTINCT ON (r.address_gid)
|
||||
r.address_country,
|
||||
r.address_locality,
|
||||
r.address_postal_code,
|
||||
r.address_street,
|
||||
r.address_number,
|
||||
r.address_region,
|
||||
r.address_gid,
|
||||
r.location,
|
||||
r.h3cell,
|
||||
r.created,
|
||||
'' -- default empty string for unit since there's no corresponding column
|
||||
FROM publicreport.report r
|
||||
WHERE r.address_id IS NULL
|
||||
AND r.location IS NOT NULL
|
||||
AND r.h3cell IS NOT NULL
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM address a WHERE a.gid = r.address_gid
|
||||
)
|
||||
RETURNING id, gid
|
||||
)
|
||||
UPDATE publicreport.report r
|
||||
SET address_id = a.id
|
||||
FROM address a
|
||||
WHERE r.address_gid = a.gid
|
||||
AND r.address_id IS NULL;
|
||||
ALTER TABLE publicreport.report
|
||||
DROP COLUMN address_number,
|
||||
DROP COLUMN address_street,
|
||||
DROP COLUMN address_locality,
|
||||
DROP COLUMN address_region,
|
||||
DROP COLUMN address_postal_code,
|
||||
DROP COLUMN address_country;
|
||||
|
||||
|
|
@ -29,12 +29,6 @@ import (
|
|||
// PublicreportReport is an object representing the database table.
|
||||
type PublicreportReport struct {
|
||||
AddressRaw string `db:"address_raw" `
|
||||
AddressNumber string `db:"address_number" `
|
||||
AddressStreet string `db:"address_street" `
|
||||
AddressLocality string `db:"address_locality" `
|
||||
AddressRegion string `db:"address_region" `
|
||||
AddressPostalCode string `db:"address_postal_code" `
|
||||
AddressCountry string `db:"address_country" `
|
||||
AddressID null.Val[int32] `db:"address_id" `
|
||||
Created time.Time `db:"created" `
|
||||
Location null.Val[string] `db:"location" `
|
||||
|
|
@ -92,16 +86,10 @@ type publicreportReportR struct {
|
|||
func buildPublicreportReportColumns(alias string) publicreportReportColumns {
|
||||
return publicreportReportColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"address_raw", "address_number", "address_street", "address_locality", "address_region", "address_postal_code", "address_country", "address_id", "created", "location", "h3cell", "id", "latlng_accuracy_type", "latlng_accuracy_value", "map_zoom", "organization_id", "public_id", "reporter_name", "reporter_email", "reporter_phone", "reporter_contact_consent", "report_type", "reviewed", "reviewer_id", "status", "location_latitude", "location_longitude", "address_gid", "client_uuid",
|
||||
"address_raw", "address_id", "created", "location", "h3cell", "id", "latlng_accuracy_type", "latlng_accuracy_value", "map_zoom", "organization_id", "public_id", "reporter_name", "reporter_email", "reporter_phone", "reporter_contact_consent", "report_type", "reviewed", "reviewer_id", "status", "location_latitude", "location_longitude", "address_gid", "client_uuid",
|
||||
).WithParent("publicreport.report"),
|
||||
tableAlias: alias,
|
||||
AddressRaw: psql.Quote(alias, "address_raw"),
|
||||
AddressNumber: psql.Quote(alias, "address_number"),
|
||||
AddressStreet: psql.Quote(alias, "address_street"),
|
||||
AddressLocality: psql.Quote(alias, "address_locality"),
|
||||
AddressRegion: psql.Quote(alias, "address_region"),
|
||||
AddressPostalCode: psql.Quote(alias, "address_postal_code"),
|
||||
AddressCountry: psql.Quote(alias, "address_country"),
|
||||
AddressID: psql.Quote(alias, "address_id"),
|
||||
Created: psql.Quote(alias, "created"),
|
||||
Location: psql.Quote(alias, "location"),
|
||||
|
|
@ -131,12 +119,6 @@ type publicreportReportColumns struct {
|
|||
expr.ColumnsExpr
|
||||
tableAlias string
|
||||
AddressRaw psql.Expression
|
||||
AddressNumber psql.Expression
|
||||
AddressStreet psql.Expression
|
||||
AddressLocality psql.Expression
|
||||
AddressRegion psql.Expression
|
||||
AddressPostalCode psql.Expression
|
||||
AddressCountry psql.Expression
|
||||
AddressID psql.Expression
|
||||
Created psql.Expression
|
||||
Location psql.Expression
|
||||
|
|
@ -174,12 +156,6 @@ func (publicreportReportColumns) AliasedAs(alias string) publicreportReportColum
|
|||
// Generated columns are not included
|
||||
type PublicreportReportSetter struct {
|
||||
AddressRaw omit.Val[string] `db:"address_raw" `
|
||||
AddressNumber omit.Val[string] `db:"address_number" `
|
||||
AddressStreet omit.Val[string] `db:"address_street" `
|
||||
AddressLocality omit.Val[string] `db:"address_locality" `
|
||||
AddressRegion omit.Val[string] `db:"address_region" `
|
||||
AddressPostalCode omit.Val[string] `db:"address_postal_code" `
|
||||
AddressCountry omit.Val[string] `db:"address_country" `
|
||||
AddressID omitnull.Val[int32] `db:"address_id" `
|
||||
Created omit.Val[time.Time] `db:"created" `
|
||||
Location omitnull.Val[string] `db:"location" `
|
||||
|
|
@ -203,28 +179,10 @@ type PublicreportReportSetter struct {
|
|||
}
|
||||
|
||||
func (s PublicreportReportSetter) SetColumns() []string {
|
||||
vals := make([]string, 0, 27)
|
||||
vals := make([]string, 0, 21)
|
||||
if s.AddressRaw.IsValue() {
|
||||
vals = append(vals, "address_raw")
|
||||
}
|
||||
if s.AddressNumber.IsValue() {
|
||||
vals = append(vals, "address_number")
|
||||
}
|
||||
if s.AddressStreet.IsValue() {
|
||||
vals = append(vals, "address_street")
|
||||
}
|
||||
if s.AddressLocality.IsValue() {
|
||||
vals = append(vals, "address_locality")
|
||||
}
|
||||
if s.AddressRegion.IsValue() {
|
||||
vals = append(vals, "address_region")
|
||||
}
|
||||
if s.AddressPostalCode.IsValue() {
|
||||
vals = append(vals, "address_postal_code")
|
||||
}
|
||||
if s.AddressCountry.IsValue() {
|
||||
vals = append(vals, "address_country")
|
||||
}
|
||||
if !s.AddressID.IsUnset() {
|
||||
vals = append(vals, "address_id")
|
||||
}
|
||||
|
|
@ -292,24 +250,6 @@ func (s PublicreportReportSetter) Overwrite(t *PublicreportReport) {
|
|||
if s.AddressRaw.IsValue() {
|
||||
t.AddressRaw = s.AddressRaw.MustGet()
|
||||
}
|
||||
if s.AddressNumber.IsValue() {
|
||||
t.AddressNumber = s.AddressNumber.MustGet()
|
||||
}
|
||||
if s.AddressStreet.IsValue() {
|
||||
t.AddressStreet = s.AddressStreet.MustGet()
|
||||
}
|
||||
if s.AddressLocality.IsValue() {
|
||||
t.AddressLocality = s.AddressLocality.MustGet()
|
||||
}
|
||||
if s.AddressRegion.IsValue() {
|
||||
t.AddressRegion = s.AddressRegion.MustGet()
|
||||
}
|
||||
if s.AddressPostalCode.IsValue() {
|
||||
t.AddressPostalCode = s.AddressPostalCode.MustGet()
|
||||
}
|
||||
if s.AddressCountry.IsValue() {
|
||||
t.AddressCountry = s.AddressCountry.MustGet()
|
||||
}
|
||||
if !s.AddressID.IsUnset() {
|
||||
t.AddressID = s.AddressID.MustGetNull()
|
||||
}
|
||||
|
|
@ -378,169 +318,133 @@ func (s *PublicreportReportSetter) Apply(q *dialect.InsertQuery) {
|
|||
})
|
||||
|
||||
q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
vals := make([]bob.Expression, 27)
|
||||
vals := make([]bob.Expression, 21)
|
||||
if s.AddressRaw.IsValue() {
|
||||
vals[0] = psql.Arg(s.AddressRaw.MustGet())
|
||||
} else {
|
||||
vals[0] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.AddressNumber.IsValue() {
|
||||
vals[1] = psql.Arg(s.AddressNumber.MustGet())
|
||||
if !s.AddressID.IsUnset() {
|
||||
vals[1] = psql.Arg(s.AddressID.MustGetNull())
|
||||
} else {
|
||||
vals[1] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.AddressStreet.IsValue() {
|
||||
vals[2] = psql.Arg(s.AddressStreet.MustGet())
|
||||
if s.Created.IsValue() {
|
||||
vals[2] = psql.Arg(s.Created.MustGet())
|
||||
} else {
|
||||
vals[2] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.AddressLocality.IsValue() {
|
||||
vals[3] = psql.Arg(s.AddressLocality.MustGet())
|
||||
if !s.Location.IsUnset() {
|
||||
vals[3] = psql.Arg(s.Location.MustGetNull())
|
||||
} else {
|
||||
vals[3] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.AddressRegion.IsValue() {
|
||||
vals[4] = psql.Arg(s.AddressRegion.MustGet())
|
||||
if !s.H3cell.IsUnset() {
|
||||
vals[4] = psql.Arg(s.H3cell.MustGetNull())
|
||||
} else {
|
||||
vals[4] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.AddressPostalCode.IsValue() {
|
||||
vals[5] = psql.Arg(s.AddressPostalCode.MustGet())
|
||||
if s.ID.IsValue() {
|
||||
vals[5] = psql.Arg(s.ID.MustGet())
|
||||
} else {
|
||||
vals[5] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.AddressCountry.IsValue() {
|
||||
vals[6] = psql.Arg(s.AddressCountry.MustGet())
|
||||
if s.LatlngAccuracyType.IsValue() {
|
||||
vals[6] = psql.Arg(s.LatlngAccuracyType.MustGet())
|
||||
} else {
|
||||
vals[6] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if !s.AddressID.IsUnset() {
|
||||
vals[7] = psql.Arg(s.AddressID.MustGetNull())
|
||||
if s.LatlngAccuracyValue.IsValue() {
|
||||
vals[7] = psql.Arg(s.LatlngAccuracyValue.MustGet())
|
||||
} else {
|
||||
vals[7] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.Created.IsValue() {
|
||||
vals[8] = psql.Arg(s.Created.MustGet())
|
||||
if s.MapZoom.IsValue() {
|
||||
vals[8] = psql.Arg(s.MapZoom.MustGet())
|
||||
} else {
|
||||
vals[8] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if !s.Location.IsUnset() {
|
||||
vals[9] = psql.Arg(s.Location.MustGetNull())
|
||||
if s.OrganizationID.IsValue() {
|
||||
vals[9] = psql.Arg(s.OrganizationID.MustGet())
|
||||
} else {
|
||||
vals[9] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if !s.H3cell.IsUnset() {
|
||||
vals[10] = psql.Arg(s.H3cell.MustGetNull())
|
||||
if s.PublicID.IsValue() {
|
||||
vals[10] = psql.Arg(s.PublicID.MustGet())
|
||||
} else {
|
||||
vals[10] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.ID.IsValue() {
|
||||
vals[11] = psql.Arg(s.ID.MustGet())
|
||||
if s.ReporterName.IsValue() {
|
||||
vals[11] = psql.Arg(s.ReporterName.MustGet())
|
||||
} else {
|
||||
vals[11] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.LatlngAccuracyType.IsValue() {
|
||||
vals[12] = psql.Arg(s.LatlngAccuracyType.MustGet())
|
||||
if s.ReporterEmail.IsValue() {
|
||||
vals[12] = psql.Arg(s.ReporterEmail.MustGet())
|
||||
} else {
|
||||
vals[12] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.LatlngAccuracyValue.IsValue() {
|
||||
vals[13] = psql.Arg(s.LatlngAccuracyValue.MustGet())
|
||||
if s.ReporterPhone.IsValue() {
|
||||
vals[13] = psql.Arg(s.ReporterPhone.MustGet())
|
||||
} else {
|
||||
vals[13] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.MapZoom.IsValue() {
|
||||
vals[14] = psql.Arg(s.MapZoom.MustGet())
|
||||
if !s.ReporterContactConsent.IsUnset() {
|
||||
vals[14] = psql.Arg(s.ReporterContactConsent.MustGetNull())
|
||||
} else {
|
||||
vals[14] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.OrganizationID.IsValue() {
|
||||
vals[15] = psql.Arg(s.OrganizationID.MustGet())
|
||||
if s.ReportType.IsValue() {
|
||||
vals[15] = psql.Arg(s.ReportType.MustGet())
|
||||
} else {
|
||||
vals[15] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.PublicID.IsValue() {
|
||||
vals[16] = psql.Arg(s.PublicID.MustGet())
|
||||
if !s.Reviewed.IsUnset() {
|
||||
vals[16] = psql.Arg(s.Reviewed.MustGetNull())
|
||||
} else {
|
||||
vals[16] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.ReporterName.IsValue() {
|
||||
vals[17] = psql.Arg(s.ReporterName.MustGet())
|
||||
if !s.ReviewerID.IsUnset() {
|
||||
vals[17] = psql.Arg(s.ReviewerID.MustGetNull())
|
||||
} else {
|
||||
vals[17] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.ReporterEmail.IsValue() {
|
||||
vals[18] = psql.Arg(s.ReporterEmail.MustGet())
|
||||
if s.Status.IsValue() {
|
||||
vals[18] = psql.Arg(s.Status.MustGet())
|
||||
} else {
|
||||
vals[18] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.ReporterPhone.IsValue() {
|
||||
vals[19] = psql.Arg(s.ReporterPhone.MustGet())
|
||||
if s.AddressGid.IsValue() {
|
||||
vals[19] = psql.Arg(s.AddressGid.MustGet())
|
||||
} else {
|
||||
vals[19] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if !s.ReporterContactConsent.IsUnset() {
|
||||
vals[20] = psql.Arg(s.ReporterContactConsent.MustGetNull())
|
||||
if !s.ClientUUID.IsUnset() {
|
||||
vals[20] = psql.Arg(s.ClientUUID.MustGetNull())
|
||||
} else {
|
||||
vals[20] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.ReportType.IsValue() {
|
||||
vals[21] = psql.Arg(s.ReportType.MustGet())
|
||||
} else {
|
||||
vals[21] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if !s.Reviewed.IsUnset() {
|
||||
vals[22] = psql.Arg(s.Reviewed.MustGetNull())
|
||||
} else {
|
||||
vals[22] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if !s.ReviewerID.IsUnset() {
|
||||
vals[23] = psql.Arg(s.ReviewerID.MustGetNull())
|
||||
} else {
|
||||
vals[23] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.Status.IsValue() {
|
||||
vals[24] = psql.Arg(s.Status.MustGet())
|
||||
} else {
|
||||
vals[24] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.AddressGid.IsValue() {
|
||||
vals[25] = psql.Arg(s.AddressGid.MustGet())
|
||||
} else {
|
||||
vals[25] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if !s.ClientUUID.IsUnset() {
|
||||
vals[26] = psql.Arg(s.ClientUUID.MustGetNull())
|
||||
} else {
|
||||
vals[26] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
|
@ -550,7 +454,7 @@ func (s PublicreportReportSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
|||
}
|
||||
|
||||
func (s PublicreportReportSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
exprs := make([]bob.Expression, 0, 27)
|
||||
exprs := make([]bob.Expression, 0, 21)
|
||||
|
||||
if s.AddressRaw.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
|
|
@ -559,48 +463,6 @@ func (s PublicreportReportSetter) Expressions(prefix ...string) []bob.Expression
|
|||
}})
|
||||
}
|
||||
|
||||
if s.AddressNumber.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "address_number")...),
|
||||
psql.Arg(s.AddressNumber),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.AddressStreet.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "address_street")...),
|
||||
psql.Arg(s.AddressStreet),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.AddressLocality.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "address_locality")...),
|
||||
psql.Arg(s.AddressLocality),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.AddressRegion.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "address_region")...),
|
||||
psql.Arg(s.AddressRegion),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.AddressPostalCode.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "address_postal_code")...),
|
||||
psql.Arg(s.AddressPostalCode),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.AddressCountry.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "address_country")...),
|
||||
psql.Arg(s.AddressCountry),
|
||||
}})
|
||||
}
|
||||
|
||||
if !s.AddressID.IsUnset() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "address_id")...),
|
||||
|
|
@ -2137,12 +1999,6 @@ func (publicreportReport0 *PublicreportReport) AttachSignals(ctx context.Context
|
|||
|
||||
type publicreportReportWhere[Q psql.Filterable] struct {
|
||||
AddressRaw psql.WhereMod[Q, string]
|
||||
AddressNumber psql.WhereMod[Q, string]
|
||||
AddressStreet psql.WhereMod[Q, string]
|
||||
AddressLocality psql.WhereMod[Q, string]
|
||||
AddressRegion psql.WhereMod[Q, string]
|
||||
AddressPostalCode psql.WhereMod[Q, string]
|
||||
AddressCountry psql.WhereMod[Q, string]
|
||||
AddressID psql.WhereNullMod[Q, int32]
|
||||
Created psql.WhereMod[Q, time.Time]
|
||||
Location psql.WhereNullMod[Q, string]
|
||||
|
|
@ -2174,12 +2030,6 @@ func (publicreportReportWhere[Q]) AliasedAs(alias string) publicreportReportWher
|
|||
func buildPublicreportReportWhere[Q psql.Filterable](cols publicreportReportColumns) publicreportReportWhere[Q] {
|
||||
return publicreportReportWhere[Q]{
|
||||
AddressRaw: psql.Where[Q, string](cols.AddressRaw),
|
||||
AddressNumber: psql.Where[Q, string](cols.AddressNumber),
|
||||
AddressStreet: psql.Where[Q, string](cols.AddressStreet),
|
||||
AddressLocality: psql.Where[Q, string](cols.AddressLocality),
|
||||
AddressRegion: psql.Where[Q, string](cols.AddressRegion),
|
||||
AddressPostalCode: psql.Where[Q, string](cols.AddressPostalCode),
|
||||
AddressCountry: psql.Where[Q, string](cols.AddressCountry),
|
||||
AddressID: psql.WhereNull[Q, int32](cols.AddressID),
|
||||
Created: psql.Where[Q, time.Time](cols.Created),
|
||||
Location: psql.WhereNull[Q, string](cols.Location),
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ func PublicReportMessageCreate(ctx context.Context, user User, report_id, messag
|
|||
return nil, errors.New("no contact methods available")
|
||||
}
|
||||
}
|
||||
func PublicReportUpdate(ctx context.Context, report_id string, report_setter models.PublicreportReportSetter, address *types.Address, location *types.Location) (*types.PublicReport, error) {
|
||||
func PublicReportUpdateCompliance(ctx context.Context, report_id string, report_setter models.PublicreportReportSetter, address *types.Address, location *types.Location) (*types.PublicReport, error) {
|
||||
txn, err := db.PGInstance.BobDB.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("create txn: %w", err)
|
||||
|
|
|
|||
|
|
@ -81,15 +81,9 @@ func (res *nuisanceR) Create(ctx context.Context, r *http.Request, n nuisanceFor
|
|||
log.Info().Str("address.raw", address.Raw).Str("address.gid", address.GID).Msg("making nuisance")
|
||||
setter_report := models.PublicreportReportSetter{
|
||||
//AddressID: omitnull.From(latlng.Cell.String()),
|
||||
AddressCountry: omit.From(""),
|
||||
AddressGid: omit.From(address.GID),
|
||||
AddressNumber: omit.From(""),
|
||||
AddressLocality: omit.From(""),
|
||||
AddressPostalCode: omit.From(""),
|
||||
AddressRaw: omit.From(address.Raw),
|
||||
AddressRegion: omit.From(""),
|
||||
AddressStreet: omit.From(""),
|
||||
Created: omit.From(time.Now()),
|
||||
AddressGid: omit.From(address.GID),
|
||||
AddressRaw: omit.From(address.Raw),
|
||||
Created: omit.From(time.Now()),
|
||||
//H3cell: omitnull.From(latlng.Cell.String()),
|
||||
LatlngAccuracyType: omit.From(enums.PublicreportAccuracytypeBrowser),
|
||||
LatlngAccuracyValue: omit.From(accuracy),
|
||||
|
|
|
|||
|
|
@ -40,20 +40,6 @@ func (res *publicreportR) ByID(ctx context.Context, r *http.Request, query Query
|
|||
populateReportURI(report, res.router)
|
||||
return report, nil
|
||||
}
|
||||
func (res *publicreportR) ByIDCompliance(ctx context.Context, r *http.Request, query QueryParams) (*types.PublicReportCompliance, *nhttp.ErrorWithStatus) {
|
||||
vars := mux.Vars(r)
|
||||
public_id := vars["id"]
|
||||
if public_id == "" {
|
||||
return nil, nhttp.NewBadRequest("You must provid an ID")
|
||||
}
|
||||
report, err := platform.PublicreportByIDCompliance(ctx, public_id)
|
||||
if err != nil {
|
||||
return nil, nhttp.NewError("get report: %w", err)
|
||||
}
|
||||
populateDistrictURI(&report.PublicReport, res.router)
|
||||
populateReportURI(&report.PublicReport, res.router)
|
||||
return report, nil
|
||||
}
|
||||
func (res *publicreportR) ByIDNuisance(ctx context.Context, r *http.Request, query QueryParams) (*types.PublicReportNuisance, *nhttp.ErrorWithStatus) {
|
||||
vars := mux.Vars(r)
|
||||
public_id := vars["id"]
|
||||
|
|
@ -104,21 +90,17 @@ func (res *publicreportR) ImageCreate(ctx context.Context, r *http.Request, n nu
|
|||
return &image{Status: "ok"}, nil
|
||||
}
|
||||
|
||||
type complianceForm struct {
|
||||
Comments *string `schema:"comments"`
|
||||
}
|
||||
|
||||
type publicreportForm struct {
|
||||
type publicreportComplianceForm struct {
|
||||
Address *types.Address `schema:"address"`
|
||||
ClientID string `schema:"client_id"`
|
||||
Compliance *complianceForm `schema:"compliance"`
|
||||
Comments *string `schema:"comments"`
|
||||
DistrictID string `schema:"district"`
|
||||
Location *types.Location `schema:"location"`
|
||||
Locator *Locator `schema:"locator"`
|
||||
Reporter *types.Contact `schema:"reporter"`
|
||||
}
|
||||
|
||||
func (res *publicreportR) Update(ctx context.Context, r *http.Request, prf publicreportForm) (*types.PublicReport, *nhttp.ErrorWithStatus) {
|
||||
func (res *publicreportR) UpdateCompliance(ctx context.Context, r *http.Request, prf publicreportComplianceForm) (*types.PublicReport, *nhttp.ErrorWithStatus) {
|
||||
vars := mux.Vars(r)
|
||||
public_id := vars["id"]
|
||||
if public_id == "" {
|
||||
|
|
@ -143,7 +125,7 @@ func (res *publicreportR) Update(ctx context.Context, r *http.Request, prf publi
|
|||
report_setter.ReporterPhone = omit.From(*prf.Reporter.Phone)
|
||||
}
|
||||
}
|
||||
report, err := platform.PublicReportUpdate(ctx, public_id, report_setter, prf.Address, prf.Location)
|
||||
report, err := platform.PublicReportUpdateCompliance(ctx, public_id, report_setter, prf.Address, prf.Location)
|
||||
if err != nil {
|
||||
return nil, nhttp.NewError("update report: %w", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ import (
|
|||
//"github.com/Gleipnir-Technology/nidus-sync/html"
|
||||
nhttp "github.com/Gleipnir-Technology/nidus-sync/http"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/platform"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/platform/types"
|
||||
"github.com/gorilla/mux"
|
||||
//"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
|
|
@ -30,18 +32,26 @@ type compliance struct {
|
|||
URI string `json:"uri"`
|
||||
}
|
||||
|
||||
func (res *complianceR) Create(ctx context.Context, r *http.Request, n publicreportForm) (*compliance, *nhttp.ErrorWithStatus) {
|
||||
func (res *complianceR) ByID(ctx context.Context, r *http.Request, query QueryParams) (*types.PublicReportCompliance, *nhttp.ErrorWithStatus) {
|
||||
vars := mux.Vars(r)
|
||||
public_id := vars["id"]
|
||||
if public_id == "" {
|
||||
return nil, nhttp.NewBadRequest("You must provid an ID")
|
||||
}
|
||||
report, err := platform.PublicreportByIDCompliance(ctx, public_id)
|
||||
if err != nil {
|
||||
return nil, nhttp.NewError("get report: %w", err)
|
||||
}
|
||||
populateDistrictURI(&report.PublicReport, res.router)
|
||||
populateReportURI(&report.PublicReport, res.router)
|
||||
return report, nil
|
||||
}
|
||||
func (res *complianceR) Create(ctx context.Context, r *http.Request, n publicreportComplianceForm) (*compliance, *nhttp.ErrorWithStatus) {
|
||||
setter_report := models.PublicreportReportSetter{
|
||||
//AddressID: omitnull.From(latlng.Cell.String()),
|
||||
AddressCountry: omit.From(""),
|
||||
AddressGid: omit.From(""),
|
||||
AddressNumber: omit.From(""),
|
||||
AddressLocality: omit.From(""),
|
||||
AddressPostalCode: omit.From(""),
|
||||
AddressRaw: omit.From(""),
|
||||
AddressRegion: omit.From(""),
|
||||
AddressStreet: omit.From(""),
|
||||
Created: omit.From(time.Now()),
|
||||
AddressGid: omit.From(""),
|
||||
AddressRaw: omit.From(""),
|
||||
Created: omit.From(time.Now()),
|
||||
//H3cell: omitnull.From(latlng.Cell.String()),
|
||||
LatlngAccuracyType: omit.From(enums.PublicreportAccuracytypeBrowser),
|
||||
LatlngAccuracyValue: omit.From(float32(0.0)),
|
||||
|
|
@ -70,14 +70,9 @@ func (res *waterR) Create(ctx context.Context, r *http.Request, w waterForm) (*w
|
|||
accuracy = *w.Location.Accuracy
|
||||
}
|
||||
setter_report := models.PublicreportReportSetter{
|
||||
AddressRaw: omit.From(address.Raw),
|
||||
AddressCountry: omit.From(""),
|
||||
AddressNumber: omit.From(""),
|
||||
AddressLocality: omit.From(""),
|
||||
AddressPostalCode: omit.From(""),
|
||||
AddressRegion: omit.From(""),
|
||||
AddressStreet: omit.From(""),
|
||||
Created: omit.From(time.Now()),
|
||||
AddressGid: omit.From(address.GID),
|
||||
AddressRaw: omit.From(address.Raw),
|
||||
Created: omit.From(time.Now()),
|
||||
//H3cell: omitnull.From(geospatial.Cell.String()),
|
||||
LatlngAccuracyType: omit.From(enums.PublicreportAccuracytypeBrowser),
|
||||
LatlngAccuracyValue: omit.From(accuracy),
|
||||
|
|
|
|||
|
|
@ -151,11 +151,7 @@ async function fetchExistingReport(report_uri: string) {
|
|||
return;
|
||||
}
|
||||
const body = await resp.json();
|
||||
report.value.comments = body.comments;
|
||||
report.value.id = body.id;
|
||||
report.value.images = body.images;
|
||||
report.value.uri = body.uri;
|
||||
report.value.address = body.address;
|
||||
report.value = body;
|
||||
isLoading.value = false;
|
||||
}
|
||||
async function updateReport(updates: ComplianceUpdate) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue