From 947ece00f13508777ebb4135c004b23e56bdc55e Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Thu, 5 Feb 2026 02:36:24 +0000 Subject: [PATCH] Only show image count, re-add timeline --- ...port_image_with_json_by_nuisance_id.bob.go | 112 ++++++++++++++++++ ...ort_image_with_json_by_nuisance_id.bob.sql | 18 +++ ...creport_image_with_json_by_nuisance_id.sql | 15 +++ rmo/status.go | 53 +++++---- rmo/template/status-by-id.html | 47 +------- 5 files changed, 180 insertions(+), 65 deletions(-) create mode 100644 db/sql/publicreport_image_with_json_by_nuisance_id.bob.go create mode 100644 db/sql/publicreport_image_with_json_by_nuisance_id.bob.sql create mode 100644 db/sql/publicreport_image_with_json_by_nuisance_id.sql diff --git a/db/sql/publicreport_image_with_json_by_nuisance_id.bob.go b/db/sql/publicreport_image_with_json_by_nuisance_id.bob.go new file mode 100644 index 00000000..f8ba3226 --- /dev/null +++ b/db/sql/publicreport_image_with_json_by_nuisance_id.bob.go @@ -0,0 +1,112 @@ +// Code generated by BobGen psql v0.42.5. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package sql + +import ( + "context" + _ "embed" + "io" + "iter" + "time" + + "github.com/Gleipnir-Technology/bob" + "github.com/Gleipnir-Technology/bob/dialect/psql" + "github.com/Gleipnir-Technology/bob/dialect/psql/dialect" + "github.com/Gleipnir-Technology/bob/orm" + "github.com/aarondl/opt/null" + "github.com/google/uuid" + "github.com/stephenafamo/scan" +) + +//go:embed publicreport_image_with_json_by_nuisance_id.bob.sql +var formattedQueries_publicreport_image_with_json_by_nuisance_id string + +var publicreportImageWithJSONByNuisanceIDSQL = formattedQueries_publicreport_image_with_json_by_nuisance_id[175:983] + +type PublicreportImageWithJSONByNuisanceIDQuery = orm.ModQuery[*dialect.SelectQuery, publicreportImageWithJSONByNuisanceID, PublicreportImageWithJSONByNuisanceIDRow, []PublicreportImageWithJSONByNuisanceIDRow, publicreportImageWithJSONByNuisanceIDTransformer] + +func PublicreportImageWithJSONByNuisanceID(NuisanceID int32) *PublicreportImageWithJSONByNuisanceIDQuery { + var expressionTypArgs publicreportImageWithJSONByNuisanceID + + expressionTypArgs.NuisanceID = psql.Arg(NuisanceID) + + return &PublicreportImageWithJSONByNuisanceIDQuery{ + Query: orm.Query[publicreportImageWithJSONByNuisanceID, PublicreportImageWithJSONByNuisanceIDRow, []PublicreportImageWithJSONByNuisanceIDRow, publicreportImageWithJSONByNuisanceIDTransformer]{ + ExecQuery: orm.ExecQuery[publicreportImageWithJSONByNuisanceID]{ + BaseQuery: bob.BaseQuery[publicreportImageWithJSONByNuisanceID]{ + Expression: expressionTypArgs, + Dialect: dialect.Dialect, + QueryType: bob.QueryTypeSelect, + }, + }, + Scanner: func(context.Context, []string) (func(*scan.Row) (any, error), func(any) (PublicreportImageWithJSONByNuisanceIDRow, error)) { + return func(row *scan.Row) (any, error) { + var t PublicreportImageWithJSONByNuisanceIDRow + row.ScheduleScanByIndex(0, &t.ID) + row.ScheduleScanByIndex(1, &t.ContentType) + row.ScheduleScanByIndex(2, &t.Created) + row.ScheduleScanByIndex(3, &t.Location) + row.ScheduleScanByIndex(4, &t.LocationJSON) + row.ScheduleScanByIndex(5, &t.ResolutionX) + row.ScheduleScanByIndex(6, &t.ResolutionY) + row.ScheduleScanByIndex(7, &t.StorageUUID) + row.ScheduleScanByIndex(8, &t.StorageSize) + row.ScheduleScanByIndex(9, &t.UploadedFilename) + return &t, nil + }, func(v any) (PublicreportImageWithJSONByNuisanceIDRow, error) { + return *(v.(*PublicreportImageWithJSONByNuisanceIDRow)), nil + } + }, + }, + Mod: bob.ModFunc[*dialect.SelectQuery](func(q *dialect.SelectQuery) { + q.AppendSelect(expressionTypArgs.subExpr(9, 549)) + q.SetTable(expressionTypArgs.subExpr(555, 751)) + q.AppendWhere(expressionTypArgs.subExpr(759, 807)) + }), + } +} + +type PublicreportImageWithJSONByNuisanceIDRow = struct { + ID int32 `db:"id"` + ContentType string `db:"content_type"` + Created time.Time `db:"created"` + Location null.Val[string] `db:"location"` + LocationJSON string `db:"location_json"` + ResolutionX int32 `db:"resolution_x"` + ResolutionY int32 `db:"resolution_y"` + StorageUUID uuid.UUID `db:"storage_uuid"` + StorageSize int64 `db:"storage_size"` + UploadedFilename string `db:"uploaded_filename"` +} + +type publicreportImageWithJSONByNuisanceIDTransformer = bob.SliceTransformer[PublicreportImageWithJSONByNuisanceIDRow, []PublicreportImageWithJSONByNuisanceIDRow] + +type publicreportImageWithJSONByNuisanceID struct { + NuisanceID bob.Expression +} + +func (o publicreportImageWithJSONByNuisanceID) args() iter.Seq[orm.ArgWithPosition] { + return func(yield func(arg orm.ArgWithPosition) bool) { + if !yield(orm.ArgWithPosition{ + Name: "nuisanceID", + Start: 805, + Stop: 807, + Expression: o.NuisanceID, + }) { + return + } + } +} + +func (o publicreportImageWithJSONByNuisanceID) raw(from, to int) string { + return publicreportImageWithJSONByNuisanceIDSQL[from:to] +} + +func (o publicreportImageWithJSONByNuisanceID) subExpr(from, to int) bob.Expression { + return orm.ArgsToExpression(publicreportImageWithJSONByNuisanceIDSQL, from, to, o.args()) +} + +func (o publicreportImageWithJSONByNuisanceID) WriteSQL(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.subExpr(0, len(publicreportImageWithJSONByNuisanceIDSQL)).WriteSQL(ctx, w, d, start) +} diff --git a/db/sql/publicreport_image_with_json_by_nuisance_id.bob.sql b/db/sql/publicreport_image_with_json_by_nuisance_id.bob.sql new file mode 100644 index 00000000..032e63dd --- /dev/null +++ b/db/sql/publicreport_image_with_json_by_nuisance_id.bob.sql @@ -0,0 +1,18 @@ +-- Code generated by BobGen psql v0.42.5. DO NOT EDIT. +-- This file is meant to be re-generated in place and/or deleted at any time. + +-- PublicreportImageWithJSONByNuisanceID +SELECT + "publicreport.image"."id" AS "id", + "publicreport.image"."content_type" AS "content_type", + "publicreport.image"."created" AS "created", + "publicreport.image"."location" AS "location", + ST_AsGeoJSON("publicreport.image"."location") AS "location_json", + "publicreport.image"."resolution_x" AS "resolution_x", + "publicreport.image"."resolution_y" AS "resolution_y", + "publicreport.image"."storage_uuid" AS "storage_uuid", + "publicreport.image"."storage_size" AS "storage_size", + "publicreport.image"."uploaded_filename" AS "uploaded_filename" +FROM "publicreport"."image" AS "publicreport.image" +INNER JOIN "publicreport"."nuisance_image" AS "publicreport.nuisance_image" ON ("publicreport.image"."id" = "publicreport.nuisance_image"."image_id") +WHERE ("publicreport.nuisance_image"."nuisance_id" = $1); diff --git a/db/sql/publicreport_image_with_json_by_nuisance_id.sql b/db/sql/publicreport_image_with_json_by_nuisance_id.sql new file mode 100644 index 00000000..ed9396ff --- /dev/null +++ b/db/sql/publicreport_image_with_json_by_nuisance_id.sql @@ -0,0 +1,15 @@ +-- PublicreportImageWithJSONByNuisanceID +SELECT + "publicreport.image"."id" AS "id", + "publicreport.image"."content_type" AS "content_type", + "publicreport.image"."created" AS "created", + "publicreport.image"."location" AS "location", + ST_AsGeoJSON("publicreport.image"."location") AS "location_json", + "publicreport.image"."resolution_x" AS "resolution_x", + "publicreport.image"."resolution_y" AS "resolution_y", + "publicreport.image"."storage_uuid" AS "storage_uuid", + "publicreport.image"."storage_size" AS "storage_size", + "publicreport.image"."uploaded_filename" AS "uploaded_filename" +FROM "publicreport"."image" AS "publicreport.image" +INNER JOIN "publicreport"."nuisance_image" AS "publicreport.nuisance_image" ON ("publicreport.image"."id" = "publicreport.nuisance_image"."image_id") +WHERE ("publicreport.nuisance_image"."nuisance_id" = $1) diff --git a/rmo/status.go b/rmo/status.go index 8522ae96..fb7be6f7 100644 --- a/rmo/status.go +++ b/rmo/status.go @@ -37,26 +37,28 @@ type ContentStatusByID struct { District *ContentDistrict MapboxToken string Report Report + Timeline []TimelineEntry URL ContentURL } type DetailEntry struct { Name string Value string } -type Image struct { - Location string - URL string -} type Report struct { - Address string - Comments string - Created time.Time - Details []DetailEntry - ID string - Images []Image - Location string // GeoJSON - Status string - Type string + Address string + Comments string + Created time.Time + Details []DetailEntry + ID string + ImageCount int + Location string // GeoJSON + Status string + Type string +} +type TimelineEntry struct { + At time.Time + Detail string + Title string } var ( @@ -109,9 +111,16 @@ func contentFromNuisance(ctx context.Context, report_id string) (result ContentS if err != nil { return result, fmt.Errorf("Failed to query nuisance %s: %w", report_id, err) } + + images, err := sql.PublicreportImageWithJSONByNuisanceID(nuisance.ID).All(ctx, db.PGInstance.BobDB) + if err != nil { + return result, fmt.Errorf("Failed to get images %s: %w", report_id, err) + } + result.Report.ID = report_id result.Report.Address = nuisance.Address result.Report.Created = nuisance.Created + result.Report.ImageCount = len(images) result.Report.Status = nuisance.Status.String() result.Report.Type = nuisance.Status.String() result.Report.Details = []DetailEntry{ @@ -136,6 +145,13 @@ func contentFromNuisance(ctx context.Context, report_id string) (result ContentS Value: "guess not", }, } + result.Timeline = []TimelineEntry{ + TimelineEntry{ + At: nuisance.Created, + Detail: "Initial report was submitted", + Title: "Created", + }, + } type LocationGeoJSON struct { Location string @@ -165,23 +181,12 @@ func contentFromQuick(ctx context.Context, report_id string) (result ContentStat return result, fmt.Errorf("Failed to query nuisance %s: %w", report_id, err) } - images, err := sql.PublicreportImageWithJSONByQuickID(quick.ID).All(ctx, db.PGInstance.BobDB) - if err != nil { - return result, fmt.Errorf("Failed to get images %s: %w", report_id, err) - } - result.Report.ID = report_id result.Report.Address = quick.Address result.Report.Comments = quick.Comments result.Report.Created = quick.Created result.Report.Type = "Quick" - for _, image := range images { - result.Report.Images = append(result.Report.Images, Image{ - Location: image.LocationJSON, - URL: config.MakeURLReport("/image/%s", image.StorageUUID.String()), - }) - } type LocationGeoJSON struct { Location string } diff --git a/rmo/template/status-by-id.html b/rmo/template/status-by-id.html index 10610b78..b1b54b69 100644 --- a/rmo/template/status-by-id.html +++ b/rmo/template/status-by-id.html @@ -42,11 +42,6 @@