diff --git a/platform/publicreport.go b/platform/publicreport.go index ebba8993..aee2ea65 100644 --- a/platform/publicreport.go +++ b/platform/publicreport.go @@ -37,8 +37,8 @@ func PublicreportByIDNuisance(ctx context.Context, report_id string) (*types.Pub func PublicreportByIDWater(ctx context.Context, report_id string) (*types.PublicReportWater, error) { return publicreport.ByIDWater(ctx, report_id) } -func PublicreportInvalid(ctx context.Context, user User, report_id string) error { - report, err := publicReportFromID(ctx, report_id) +func PublicreportInvalid(ctx context.Context, user User, public_id string) error { + report, err := publicReportFromID(ctx, public_id) if err != nil { return fmt.Errorf("query report existence: %w", err) } @@ -53,18 +53,18 @@ func PublicreportInvalid(ctx context.Context, user User, report_id string) error }) log.Info().Int32("id", report.ID).Msg("Report marked as invalid") - event.Updated(event.TypeRMOPublicReport, user.Organization.ID, report_id) + event.Updated(event.TypeRMOPublicReport, user.Organization.ID, public_id) return nil } -func PublicReportMessageCreate(ctx context.Context, user User, report_id, message string) (message_id *int32, err error) { +func PublicReportMessageCreate(ctx context.Context, user User, public_id, message string) (message_id *int32, err error) { txn, err := db.PGInstance.BobDB.BeginTx(ctx, nil) if err != nil { return nil, fmt.Errorf("create txn: %w", err) } defer txn.Rollback(ctx) - report, err := publicReportFromID(ctx, report_id) + report, err := publicReportFromID(ctx, public_id) if err != nil { return nil, fmt.Errorf("query report existence: %w", err) } @@ -72,7 +72,7 @@ func PublicReportMessageCreate(ctx context.Context, user User, report_id, messag return nil, fmt.Errorf("user is from a different organization") } if report.ReporterPhone != "" { - log.Debug().Str("report_id", report_id).Msg("contacting via phone") + log.Debug().Str("public_id", public_id).Msg("contacting via phone") p, err := text.ParsePhoneNumber(report.ReporterPhone) if err != nil { return nil, fmt.Errorf("parse phone: %w", err) @@ -85,24 +85,24 @@ func PublicReportMessageCreate(ctx context.Context, user User, report_id, messag //log.Debug().Int32("msg_id", *msg_id).Msg("Created text.ReportMessage") return msg_id, nil } else if report.ReporterEmail != "" { - msg_id, err := email.ReportMessage(ctx, int32(user.ID), report_id, report.ReporterEmail, message) + msg_id, err := email.ReportMessage(ctx, int32(user.ID), public_id, report.ReporterEmail, message) if err != nil { return nil, fmt.Errorf("send email: %w", err) } txn.Commit(ctx) return msg_id, nil } else { - log.Debug().Str("report_id", report_id).Msg("contacting via email") + log.Debug().Str("public_id", public_id).Msg("contacting via email") return nil, errors.New("no contact methods available") } } -func PublicReportUpdateCompliance(ctx context.Context, report_id string, report_setter models.PublicreportReportSetter, address *types.Address, location *types.Location) (*types.PublicReport, error) { +func PublicReportUpdateCompliance(ctx context.Context, public_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) } defer txn.Rollback(ctx) - report, err := publicReportFromID(ctx, report_id) + report, err := publicReportFromID(ctx, public_id) if err != nil { return nil, fmt.Errorf("query report existence: %w", err) } @@ -129,7 +129,7 @@ func PublicReportUpdateCompliance(ctx context.Context, report_id string, report_ } } txn.Commit(ctx) - return publicreport.ByID(ctx, report_id) + return publicreport.ByID(ctx, public_id) } func PublicReportReporterUpdated(ctx context.Context, org_id int32, report_id string) { event.Updated(event.TypeRMOPublicReport, org_id, report_id) @@ -147,14 +147,14 @@ func PublicReportComplianceCreate(ctx context.Context, setter_report models.Publ return nil }) } -func PublicReportImageCreate(ctx context.Context, report_id string, images []ImageUpload) error { +func PublicReportImageCreate(ctx context.Context, public_id string, images []ImageUpload) error { txn, err := db.PGInstance.BobDB.BeginTx(ctx, nil) if err != nil { return fmt.Errorf("create txn: %w", err) } defer txn.Rollback(ctx) - report, err := publicReportFromID(ctx, report_id) + report, err := publicReportFromID(ctx, public_id) if err != nil { return fmt.Errorf("report from ID: %w", err) } @@ -294,9 +294,9 @@ func publicReportCreate(ctx context.Context, setter_report models.PublicreportRe } return result, nil } -func publicReportFromID(ctx context.Context, report_id string) (*models.PublicreportReport, error) { +func publicReportFromID(ctx context.Context, public_id string) (*models.PublicreportReport, error) { report, err := models.PublicreportReports.Query( - models.SelectWhere.PublicreportReports.PublicID.EQ(report_id), + models.SelectWhere.PublicreportReports.PublicID.EQ(public_id), ).One(ctx, db.PGInstance.BobDB) if err != nil { return nil, err diff --git a/platform/publicreport/report.go b/platform/publicreport/report.go index 0dce0a68..0ed0f5f8 100644 --- a/platform/publicreport/report.go +++ b/platform/publicreport/report.go @@ -151,14 +151,14 @@ func copyReportContent(src *types.PublicReport, dst *types.PublicReport) { func reportQuery() bob.BaseQuery[*dialect.SelectQuery] { return psql.Select( sm.Columns( - "a.country AS \"address.country\"", + "COALESCE(a.country, '') AS \"address.country\"", "a.id AS \"address.id\"", - "a.gid AS \"address.gid\"", - "a.locality AS \"address.locality\"", - "a.number_ AS \"address.number\"", - "a.postal_code AS \"address.postal_code\"", - "a.region AS \"address.region\"", - "a.street AS \"address.street\"", + "COALESCE(a.gid, '') AS \"address.gid\"", + "COALESCE(a.locality, '') AS \"address.locality\"", + "COALESCE(a.number_, '') AS \"address.number\"", + "COALESCE(a.postal_code, '') AS \"address.postal_code\"", + "COALESCE(a.region, '') AS \"address.region\"", + "COALESCE(a.street, '') AS \"address.street\"", "r.address_raw AS \"address.raw\"", "r.created", "r.id", @@ -174,7 +174,7 @@ func reportQuery() bob.BaseQuery[*dialect.SelectQuery] { "r.status", ), sm.From("publicreport.report").As("r"), - sm.InnerJoin("address").As("a").OnEQ( + sm.LeftJoin("address").As("a").OnEQ( psql.Quote("r", "address_id"), psql.Quote("a", "id"), ), diff --git a/resource/publicreport.go b/resource/publicreport.go index 1e2d3a8b..e165a972 100644 --- a/resource/publicreport.go +++ b/resource/publicreport.go @@ -127,7 +127,7 @@ func (res *publicreportR) UpdateCompliance(ctx context.Context, r *http.Request, } report, err := platform.PublicReportUpdateCompliance(ctx, public_id, report_setter, prf.Address, prf.Location) if err != nil { - return nil, nhttp.NewError("update report: %w", err) + return nil, nhttp.NewError("platform update report compliance: %w", err) } return report, nil }