Fix populating water report from ID, make ContactSimple

ContactSimple is the replacement for ContactReporter, which was the
simplified form of a contact from a report. I made the name more generic
and use it in the general report structures for consistency.
This commit is contained in:
Eli Ribble 2026-05-21 03:23:10 +00:00
parent 75d0283453
commit 5e103f46a0
No known key found for this signature in database
14 changed files with 103 additions and 108 deletions

View file

@ -38,15 +38,20 @@ func ByIDNuisance(ctx context.Context, public_id string, is_public bool) (*types
}
return nuisance(ctx, public_id, *report)
}
func ByIDWater(ctx context.Context, public_id string, is_public bool) (*types.PublicReportWater, error) {
func ByIDWater(ctx context.Context, public_id string, is_public bool) (types.PublicReportWater, error) {
report, err := byID(ctx, public_id, is_public)
if err != nil {
return nil, fmt.Errorf("base report byid: %w", err)
return types.PublicReportWater{}, fmt.Errorf("base report byid: %w", err)
}
if report == nil {
return nil, nil
return types.PublicReportWater{}, nil
}
return water(ctx, public_id, *report)
txn := db.PGInstance.PGXPool
water, err := querypublicreport.WaterFromReportID(ctx, txn, int64(report.ID))
if err != nil {
return types.PublicReportWater{}, fmt.Errorf("water from report id %d: %w", report.ID, err)
}
return types.PublicReportWaterFromModel(*report, water), nil
}
func UnreviewedForOrganization(ctx context.Context, txn db.Ex, org_id int64, is_public bool) ([]types.PublicReport, error) {
reports, err := querypublicreport.ReportsUnreviewedForOrganization(ctx, txn, org_id)
@ -143,10 +148,10 @@ func reportQueryToRows(ctx context.Context, reports []modelpublicreport.Report,
DistrictID: &row.OrganizationID,
District: nil,
PublicID: row.PublicID,
Reporter: types.ContactReporter{
Reporter: types.ContactSimple{
Email: row.ReporterEmail,
Name: row.ReporterName,
Phone: types.PhoneReporter{
Phone: types.PhoneSimple{
CanSMS: row.ReporterPhoneCanSms,
Number: row.ReporterPhone,
},

View file

@ -1,50 +0,0 @@
package publicreport
import (
"context"
"fmt"
"github.com/Gleipnir-Technology/bob"
"github.com/Gleipnir-Technology/bob/dialect/psql"
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
//"source.gleipnir.technology/Gleipnir/nidus-sync/config"
"source.gleipnir.technology/Gleipnir/nidus-sync/db"
"source.gleipnir.technology/Gleipnir/nidus-sync/platform/types"
//"source.gleipnir.technology/Gleipnir/nidus-sync/db/models"
//"github.com/google/uuid"
//"github.com/rs/zerolog/log"
"github.com/stephenafamo/scan"
)
func water(ctx context.Context, public_id string, report types.PublicReport) (*types.PublicReportWater, error) {
row, err := bob.One(ctx, db.PGInstance.BobDB, psql.Select(
sm.Columns(
"access_comments",
"access_gate",
"access_fence",
"access_locked",
"access_dog",
"access_other",
"comments",
"has_adult",
"has_backyard_permission",
"has_larvae",
"has_pupae",
"is_reporter_confidential",
"is_reporter_owner",
"owner_email AS \"owner.email\"",
"owner_name AS \"owner.name\"",
"owner_phone AS \"owner.phone\"",
"report_id",
),
sm.From("publicreport.water"),
sm.Where(psql.Quote("report_id").EQ(
psql.Arg(report.ID),
)),
), scan.StructMapper[types.PublicReportWater]())
if err != nil {
return nil, fmt.Errorf("query water: %w", err)
}
copyReportContent(report, &row.PublicReport)
return &row, nil
}