Populate district from image location on standing water

This commit is contained in:
Eli Ribble 2026-02-10 15:22:27 +00:00
parent c74fff6da9
commit ef205bd622
No known key found for this signature in database
2 changed files with 51 additions and 43 deletions

View file

@ -13,13 +13,11 @@ import (
"github.com/Gleipnir-Technology/nidus-sync/db"
"github.com/Gleipnir-Technology/nidus-sync/db/enums"
"github.com/Gleipnir-Technology/nidus-sync/db/models"
"github.com/Gleipnir-Technology/nidus-sync/h3utils"
"github.com/Gleipnir-Technology/nidus-sync/html"
"github.com/Gleipnir-Technology/nidus-sync/platform/report"
"github.com/aarondl/opt/omit"
"github.com/aarondl/opt/omitnull"
"github.com/rs/zerolog/log"
"github.com/uber/h3-go/v4"
)
type ContentNuisance struct {
@ -140,6 +138,12 @@ func postNuisance(w http.ResponseWriter, r *http.Request) {
return
}
geospatial, err := geospatialFromForm(r)
if err != nil {
respondError(w, "Failed to handle geospatial data", err, http.StatusInternalServerError)
return
}
txn, err := db.PGInstance.BobDB.BeginTx(ctx, nil)
if err != nil {
respondError(w, "Failed to create transaction", err, http.StatusInternalServerError)
@ -159,27 +163,22 @@ func postNuisance(w http.ResponseWriter, r *http.Request) {
return
}
var organization_id *int32
var h3cell h3.Cell
organization_id, err = matchDistrict(ctx, latlng.Longitude, latlng.Latitude, uploads)
if err != nil {
log.Warn().Err(err).Msg("Failed to match district")
}
h3cell, err = h3utils.GetCell(*latlng.Longitude, *latlng.Latitude, 15)
if err != nil {
respondError(w, "Failedt o get h3 cell", err, http.StatusInternalServerError)
}
setter := models.PublicreportNuisanceSetter{
AdditionalInfo: omit.From(additional_info),
Address: omit.From(address),
AddressCountry: omit.From(address_country),
AddressPlace: omit.From(address_place),
AddressPostcode: omit.From(address_postcode),
AddressRegion: omit.From(address_region),
AddressStreet: omit.From(address_street),
Created: omit.From(time.Now()),
Duration: omit.From(duration),
H3cell: omitnull.From(h3cell.String()),
AdditionalInfo: omit.From(additional_info),
Address: omit.From(address),
AddressCountry: omit.From(address_country),
AddressPlace: omit.From(address_place),
AddressPostcode: omit.From(address_postcode),
AddressRegion: omit.From(address_region),
AddressStreet: omit.From(address_street),
Created: omit.From(time.Now()),
Duration: omit.From(duration),
//H3cell: omitnull.From(geospatial.Cell.String()),
IsLocationBackyard: omit.From(is_location_backyard),
IsLocationFrontyard: omit.From(is_location_frontyard),
IsLocationGarden: omit.From(is_location_garden),
@ -210,11 +209,6 @@ func postNuisance(w http.ResponseWriter, r *http.Request) {
respondError(w, "Failed to create database record", err, http.StatusInternalServerError)
return
}
geospatial, err := geospatialFromForm(r)
if err != nil {
respondError(w, "Failed to handle geospatial data", err, http.StatusInternalServerError)
return
}
if geospatial.Populated {
_, err = psql.Update(
um.Table("publicreport.nuisance"),

View file

@ -15,6 +15,7 @@ import (
"github.com/Gleipnir-Technology/nidus-sync/html"
"github.com/Gleipnir-Technology/nidus-sync/platform/report"
"github.com/aarondl/opt/omit"
"github.com/aarondl/opt/omitnull"
"github.com/rs/zerolog/log"
)
@ -86,6 +87,12 @@ func postWater(w http.ResponseWriter, r *http.Request) {
respondError(w, "Failed to parse lat lng for pool report", err, http.StatusInternalServerError)
return
}
geospatial, err := geospatialFromForm(r)
if err != nil {
respondError(w, "Failed to handle geospatial data", err, http.StatusInternalServerError)
return
}
public_id, err := report.GenerateReportID()
if err != nil {
respondError(w, "Failed to create pool report public ID", err, http.StatusInternalServerError)
@ -100,6 +107,23 @@ func postWater(w http.ResponseWriter, r *http.Request) {
}
defer tx.Rollback(ctx)
uploads, err := extractImageUploads(r)
if err != nil {
respondError(w, "Failed to extract image uploads", err, http.StatusInternalServerError)
return
}
images, err := saveImageUploads(r.Context(), tx, uploads)
if err != nil {
respondError(w, "Failed to save image uploads", err, http.StatusInternalServerError)
return
}
var organization_id *int32
organization_id, err = matchDistrict(ctx, latlng.Longitude, latlng.Latitude, uploads)
if err != nil {
log.Warn().Err(err).Msg("Failed to match district")
}
setter := models.PublicreportPoolSetter{
AccessComments: omit.From(access_comments),
AccessDog: omit.From(access_dog),
@ -115,7 +139,7 @@ func postWater(w http.ResponseWriter, r *http.Request) {
AddressRegion: omit.From(address_region),
Comments: omit.From(comments),
Created: omit.From(time.Now()),
//H3cell: add later
//H3cell: omitnull.From(geospatial.Cell.String()),
HasAdult: omit.From(has_adult),
HasBackyardPermission: omit.From(has_backyard_permission),
HasLarvae: omit.From(has_larvae),
@ -123,15 +147,16 @@ func postWater(w http.ResponseWriter, r *http.Request) {
IsReporterConfidential: omit.From(is_reporter_confidential),
IsReporterOwner: omit.From(is_reporter_owner),
//Location: add later
MapZoom: omit.From(latlng.MapZoom),
OwnerEmail: omit.From(owner_email),
OwnerName: omit.From(owner_name),
OwnerPhone: omit.From(owner_phone),
PublicID: omit.From(public_id),
ReporterEmail: omit.From(""),
ReporterName: omit.From(""),
ReporterPhone: omit.From(""),
Status: omit.From(enums.PublicreportReportstatustypeReported),
MapZoom: omit.From(latlng.MapZoom),
OrganizationID: omitnull.FromPtr(organization_id),
OwnerEmail: omit.From(owner_email),
OwnerName: omit.From(owner_name),
OwnerPhone: omit.From(owner_phone),
PublicID: omit.From(public_id),
ReporterEmail: omit.From(""),
ReporterName: omit.From(""),
ReporterPhone: omit.From(""),
Status: omit.From(enums.PublicreportReportstatustypeReported),
}
pool, err := models.PublicreportPools.Insert(&setter).One(ctx, tx)
if err != nil {
@ -139,11 +164,6 @@ func postWater(w http.ResponseWriter, r *http.Request) {
return
}
geospatial, err := geospatialFromForm(r)
if err != nil {
respondError(w, "Failed to handle geospatial data", err, http.StatusInternalServerError)
return
}
if geospatial.Populated {
_, err = psql.Update(
um.Table("publicreport.pool"),
@ -157,12 +177,6 @@ func postWater(w http.ResponseWriter, r *http.Request) {
}
}
log.Info().Int32("id", pool.ID).Str("public_id", pool.PublicID).Msg("Created pool report")
uploads, err := extractImageUploads(r)
if err != nil {
respondError(w, "Failed to extract image uploads", err, http.StatusInternalServerError)
return
}
images, err := saveImageUploads(r.Context(), tx, uploads)
setters := make([]*models.PublicreportPoolImageSetter, 0)
for _, image := range images {
setters = append(setters, &models.PublicreportPoolImageSetter{