Remove hidden water inputs, add missing duration input

This commit is contained in:
Eli Ribble 2026-04-24 22:21:01 +00:00
parent 203d2014b0
commit 5e638bdf1d
No known key found for this signature in database
5 changed files with 107 additions and 96 deletions

View file

@ -168,6 +168,15 @@ var PublicreportWaters = Table[
Generated: false,
AutoIncr: false,
},
Duration: column{
Name: "duration",
DBType: "publicreport.nuisancedurationtype",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
},
Indexes: publicreportWaterIndexes{
WaterPkey: index{
@ -226,11 +235,12 @@ type publicreportWaterColumns struct {
OwnerName column
OwnerPhone column
ReportID column
Duration column
}
func (c publicreportWaterColumns) AsSlice() []column {
return []column{
c.AccessComments, c.AccessGate, c.AccessFence, c.AccessLocked, c.AccessDog, c.AccessOther, c.Comments, c.IsReporterConfidential, c.IsReporterOwner, c.HasAdult, c.HasBackyardPermission, c.HasLarvae, c.HasPupae, c.OwnerEmail, c.OwnerName, c.OwnerPhone, c.ReportID,
c.AccessComments, c.AccessGate, c.AccessFence, c.AccessLocked, c.AccessDog, c.AccessOther, c.Comments, c.IsReporterConfidential, c.IsReporterOwner, c.HasAdult, c.HasBackyardPermission, c.HasLarvae, c.HasPupae, c.OwnerEmail, c.OwnerName, c.OwnerPhone, c.ReportID, c.Duration,
}
}

View file

@ -0,0 +1,6 @@
-- +goose Up
ALTER TABLE publicreport.water ADD COLUMN duration publicreport.NuisanceDurationType;
UPDATE publicreport.water SET duration = 'none';
ALTER TABLE publicreport.water ALTER COLUMN duration SET NOT NULL;
-- +goose Down
ALTER TABLE publicreport.water DROP COLUMN duration;

View file

@ -17,28 +17,30 @@ import (
"github.com/Gleipnir-Technology/bob/expr"
"github.com/Gleipnir-Technology/bob/orm"
"github.com/Gleipnir-Technology/bob/types/pgtypes"
enums "github.com/Gleipnir-Technology/nidus-sync/db/enums"
"github.com/aarondl/opt/omit"
)
// PublicreportWater is an object representing the database table.
type PublicreportWater struct {
AccessComments string `db:"access_comments" `
AccessGate bool `db:"access_gate" `
AccessFence bool `db:"access_fence" `
AccessLocked bool `db:"access_locked" `
AccessDog bool `db:"access_dog" `
AccessOther bool `db:"access_other" `
Comments string `db:"comments" `
IsReporterConfidential bool `db:"is_reporter_confidential" `
IsReporterOwner bool `db:"is_reporter_owner" `
HasAdult bool `db:"has_adult" `
HasBackyardPermission bool `db:"has_backyard_permission" `
HasLarvae bool `db:"has_larvae" `
HasPupae bool `db:"has_pupae" `
OwnerEmail string `db:"owner_email" `
OwnerName string `db:"owner_name" `
OwnerPhone string `db:"owner_phone" `
ReportID int32 `db:"report_id,pk" `
AccessComments string `db:"access_comments" `
AccessGate bool `db:"access_gate" `
AccessFence bool `db:"access_fence" `
AccessLocked bool `db:"access_locked" `
AccessDog bool `db:"access_dog" `
AccessOther bool `db:"access_other" `
Comments string `db:"comments" `
IsReporterConfidential bool `db:"is_reporter_confidential" `
IsReporterOwner bool `db:"is_reporter_owner" `
HasAdult bool `db:"has_adult" `
HasBackyardPermission bool `db:"has_backyard_permission" `
HasLarvae bool `db:"has_larvae" `
HasPupae bool `db:"has_pupae" `
OwnerEmail string `db:"owner_email" `
OwnerName string `db:"owner_name" `
OwnerPhone string `db:"owner_phone" `
ReportID int32 `db:"report_id,pk" `
Duration enums.PublicreportNuisancedurationtype `db:"duration" `
R publicreportWaterR `db:"-" `
}
@ -61,7 +63,7 @@ type publicreportWaterR struct {
func buildPublicreportWaterColumns(alias string) publicreportWaterColumns {
return publicreportWaterColumns{
ColumnsExpr: expr.NewColumnsExpr(
"access_comments", "access_gate", "access_fence", "access_locked", "access_dog", "access_other", "comments", "is_reporter_confidential", "is_reporter_owner", "has_adult", "has_backyard_permission", "has_larvae", "has_pupae", "owner_email", "owner_name", "owner_phone", "report_id",
"access_comments", "access_gate", "access_fence", "access_locked", "access_dog", "access_other", "comments", "is_reporter_confidential", "is_reporter_owner", "has_adult", "has_backyard_permission", "has_larvae", "has_pupae", "owner_email", "owner_name", "owner_phone", "report_id", "duration",
).WithParent("publicreport.water"),
tableAlias: alias,
AccessComments: psql.Quote(alias, "access_comments"),
@ -81,6 +83,7 @@ func buildPublicreportWaterColumns(alias string) publicreportWaterColumns {
OwnerName: psql.Quote(alias, "owner_name"),
OwnerPhone: psql.Quote(alias, "owner_phone"),
ReportID: psql.Quote(alias, "report_id"),
Duration: psql.Quote(alias, "duration"),
}
}
@ -104,6 +107,7 @@ type publicreportWaterColumns struct {
OwnerName psql.Expression
OwnerPhone psql.Expression
ReportID psql.Expression
Duration psql.Expression
}
func (c publicreportWaterColumns) Alias() string {
@ -118,27 +122,28 @@ func (publicreportWaterColumns) AliasedAs(alias string) publicreportWaterColumns
// All values are optional, and do not have to be set
// Generated columns are not included
type PublicreportWaterSetter struct {
AccessComments omit.Val[string] `db:"access_comments" `
AccessGate omit.Val[bool] `db:"access_gate" `
AccessFence omit.Val[bool] `db:"access_fence" `
AccessLocked omit.Val[bool] `db:"access_locked" `
AccessDog omit.Val[bool] `db:"access_dog" `
AccessOther omit.Val[bool] `db:"access_other" `
Comments omit.Val[string] `db:"comments" `
IsReporterConfidential omit.Val[bool] `db:"is_reporter_confidential" `
IsReporterOwner omit.Val[bool] `db:"is_reporter_owner" `
HasAdult omit.Val[bool] `db:"has_adult" `
HasBackyardPermission omit.Val[bool] `db:"has_backyard_permission" `
HasLarvae omit.Val[bool] `db:"has_larvae" `
HasPupae omit.Val[bool] `db:"has_pupae" `
OwnerEmail omit.Val[string] `db:"owner_email" `
OwnerName omit.Val[string] `db:"owner_name" `
OwnerPhone omit.Val[string] `db:"owner_phone" `
ReportID omit.Val[int32] `db:"report_id,pk" `
AccessComments omit.Val[string] `db:"access_comments" `
AccessGate omit.Val[bool] `db:"access_gate" `
AccessFence omit.Val[bool] `db:"access_fence" `
AccessLocked omit.Val[bool] `db:"access_locked" `
AccessDog omit.Val[bool] `db:"access_dog" `
AccessOther omit.Val[bool] `db:"access_other" `
Comments omit.Val[string] `db:"comments" `
IsReporterConfidential omit.Val[bool] `db:"is_reporter_confidential" `
IsReporterOwner omit.Val[bool] `db:"is_reporter_owner" `
HasAdult omit.Val[bool] `db:"has_adult" `
HasBackyardPermission omit.Val[bool] `db:"has_backyard_permission" `
HasLarvae omit.Val[bool] `db:"has_larvae" `
HasPupae omit.Val[bool] `db:"has_pupae" `
OwnerEmail omit.Val[string] `db:"owner_email" `
OwnerName omit.Val[string] `db:"owner_name" `
OwnerPhone omit.Val[string] `db:"owner_phone" `
ReportID omit.Val[int32] `db:"report_id,pk" `
Duration omit.Val[enums.PublicreportNuisancedurationtype] `db:"duration" `
}
func (s PublicreportWaterSetter) SetColumns() []string {
vals := make([]string, 0, 17)
vals := make([]string, 0, 18)
if s.AccessComments.IsValue() {
vals = append(vals, "access_comments")
}
@ -190,6 +195,9 @@ func (s PublicreportWaterSetter) SetColumns() []string {
if s.ReportID.IsValue() {
vals = append(vals, "report_id")
}
if s.Duration.IsValue() {
vals = append(vals, "duration")
}
return vals
}
@ -245,6 +253,9 @@ func (s PublicreportWaterSetter) Overwrite(t *PublicreportWater) {
if s.ReportID.IsValue() {
t.ReportID = s.ReportID.MustGet()
}
if s.Duration.IsValue() {
t.Duration = s.Duration.MustGet()
}
}
func (s *PublicreportWaterSetter) Apply(q *dialect.InsertQuery) {
@ -253,7 +264,7 @@ func (s *PublicreportWaterSetter) 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, 17)
vals := make([]bob.Expression, 18)
if s.AccessComments.IsValue() {
vals[0] = psql.Arg(s.AccessComments.MustGet())
} else {
@ -356,6 +367,12 @@ func (s *PublicreportWaterSetter) Apply(q *dialect.InsertQuery) {
vals[16] = psql.Raw("DEFAULT")
}
if s.Duration.IsValue() {
vals[17] = psql.Arg(s.Duration.MustGet())
} else {
vals[17] = psql.Raw("DEFAULT")
}
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
}))
}
@ -365,7 +382,7 @@ func (s PublicreportWaterSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
}
func (s PublicreportWaterSetter) Expressions(prefix ...string) []bob.Expression {
exprs := make([]bob.Expression, 0, 17)
exprs := make([]bob.Expression, 0, 18)
if s.AccessComments.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
@ -486,6 +503,13 @@ func (s PublicreportWaterSetter) Expressions(prefix ...string) []bob.Expression
}})
}
if s.Duration.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "duration")...),
psql.Arg(s.Duration),
}})
}
return exprs
}
@ -802,6 +826,7 @@ type publicreportWaterWhere[Q psql.Filterable] struct {
OwnerName psql.WhereMod[Q, string]
OwnerPhone psql.WhereMod[Q, string]
ReportID psql.WhereMod[Q, int32]
Duration psql.WhereMod[Q, enums.PublicreportNuisancedurationtype]
}
func (publicreportWaterWhere[Q]) AliasedAs(alias string) publicreportWaterWhere[Q] {
@ -827,6 +852,7 @@ func buildPublicreportWaterWhere[Q psql.Filterable](cols publicreportWaterColumn
OwnerName: psql.Where[Q, string](cols.OwnerName),
OwnerPhone: psql.Where[Q, string](cols.OwnerPhone),
ReportID: psql.Where[Q, int32](cols.ReportID),
Duration: psql.Where[Q, enums.PublicreportNuisancedurationtype](cols.Duration),
}
}

View file

@ -33,26 +33,27 @@ type water struct {
URI string `json:"uri"`
}
type waterForm struct {
AccessComments string `schema:"access-comments"`
AccessDog bool `schema:"access-dog"`
AccessFence bool `schema:"access-fence"`
AccessGate bool `schema:"access-gate"`
AccessLocked bool `schema:"access-locked"`
AccessOther bool `schema:"access-other"`
Address types.Address `schema:"address"`
AddressGID string `schema:"address-gid"`
ClientID uuid.UUID `schema:"client_id" json:"client_id"`
Comments string `schema:"comments"`
HasAdult bool `schema:"has-adult"`
HasBackyardPermission bool `schema:"backyard-permission"`
HasLarvae bool `schema:"has-larvae"`
HasPupae bool `schema:"has-pupae"`
IsReporterConfidential bool `schema:"reporter-confidential"`
IsReporter_owner bool `schema:"property-ownership"`
Location types.Location `schema:"location"`
OwnerEmail string `schema:"owner-email"`
OwnerName string `schema:"owner-name"`
OwnerPhone string `schema:"owner-phone"`
AccessComments string `schema:"access-comments"`
AccessDog bool `schema:"access-dog"`
AccessFence bool `schema:"access-fence"`
AccessGate bool `schema:"access-gate"`
AccessLocked bool `schema:"access-locked"`
AccessOther bool `schema:"access-other"`
Address types.Address `schema:"address"`
AddressGID string `schema:"address-gid"`
ClientID uuid.UUID `schema:"client_id" json:"client_id"`
Comments string `schema:"comments"`
Duration omit.Val[enums.PublicreportNuisancedurationtype] `schema:"duration"`
HasAdult bool `schema:"has-adult"`
HasBackyardPermission bool `schema:"backyard-permission"`
HasLarvae bool `schema:"has-larvae"`
HasPupae bool `schema:"has-pupae"`
IsReporterConfidential bool `schema:"reporter-confidential"`
IsReporter_owner bool `schema:"property-ownership"`
Location types.Location `schema:"location"`
OwnerEmail string `schema:"owner-email"`
OwnerName string `schema:"owner-name"`
OwnerPhone string `schema:"owner-phone"`
}
func (res *waterR) ByID(ctx context.Context, r *http.Request, query QueryParams) (*types.PublicReportWater, *nhttp.ErrorWithStatus) {
@ -115,6 +116,7 @@ func (res *waterR) Create(ctx context.Context, r *http.Request, w waterForm) (*w
AccessLocked: omit.From(w.AccessLocked),
AccessOther: omit.From(w.AccessOther),
Comments: omit.From(w.Comments),
Duration: w.Duration,
HasAdult: omit.From(w.HasAdult),
HasBackyardPermission: omit.From(w.HasBackyardPermission),
HasLarvae: omit.From(w.HasLarvae),

View file

@ -207,36 +207,6 @@ select.tall {
</div>
</div>
<div class="row mb-3">
<!-- Hidden fields for location data -->
<input type="hidden" id="address-country" name="address-country" />
<input
type="hidden"
id="address-locality"
name="address-locality"
/>
<input type="hidden" id="address-number" name="address-number" />
<input
type="hidden"
id="address-postalcode"
name="address-postalcode"
/>
<input type="hidden" id="address-region" name="address-region" />
<input type="hidden" id="address-street" name="address-street" />
<input type="hidden" id="latitude" name="latitude" />
<input type="hidden" id="longitude" name="longitude" />
<input
type="hidden"
id="latlng-accuracy-type"
name="latlng-accuracy-type"
/>
<input
type="hidden"
id="latlng-accuracy-value"
name="latlng-accuracy-value"
/>
</div>
<p class="small text-muted mb-2">
You can also click on the map to mark the location precisely
</p>
@ -266,17 +236,14 @@ select.tall {
<label for="duration" class="form-label"
>How long has this production source been present?</label
>
<select
class="form-select"
id="duration"
name="source-duration"
>
<select class="form-select" id="duration" name="duration">
<option value="none">I don't know</option>
<option value="less-than-week">Less than a week</option>
<option value="just-noticed">Just noticed</option>
<option value="few-days">Less than a week</option>
<option value="1-2-weeks">1-2 weeks</option>
<option value="2-4-weeks">2-4 weeks</option>
<option value="1-3-months">1-3 months</option>
<option value="more-than-3-months">More than 3 months</option>
<option value="seasonal">More than 3 months</option>
</select>
</div>