Update storage of reporter in contact
I failed to retrieve the data correctly before as part of the changeover to contact records. Issue: #13
This commit is contained in:
parent
b9f2107c79
commit
e3cc1e99d1
9 changed files with 132 additions and 50 deletions
|
|
@ -79,9 +79,12 @@ func byID(ctx context.Context, public_id string, is_public bool) (*types.PublicR
|
|||
return &reports[0], nil
|
||||
}
|
||||
func reportQueryToRows(ctx context.Context, reports []modelpublicreport.Report, is_public bool) ([]types.PublicReport, error) {
|
||||
txn := db.PGInstance.PGXPool
|
||||
address_ids := make([]int64, 0)
|
||||
contact_ids := make([]int64, len(reports))
|
||||
report_ids := make([]int32, len(reports))
|
||||
for i, report := range reports {
|
||||
contact_ids[i] = int64(report.ReporterContactID)
|
||||
report_ids[i] = report.ID
|
||||
if report.AddressID != nil {
|
||||
address_ids = append(address_ids, int64(*report.AddressID))
|
||||
|
|
@ -97,7 +100,7 @@ func reportQueryToRows(ctx context.Context, reports []modelpublicreport.Report,
|
|||
if err != nil {
|
||||
return nil, fmt.Errorf("log entries for reports: %w", err)
|
||||
}
|
||||
addresses, err := querypublic.AddressesFromIDs(ctx, db.PGInstance.PGXPool, address_ids)
|
||||
addresses, err := querypublic.AddressesFromIDs(ctx, txn, address_ids)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("addresses for reports: %w", err)
|
||||
}
|
||||
|
|
@ -105,6 +108,14 @@ func reportQueryToRows(ctx context.Context, reports []modelpublicreport.Report,
|
|||
for _, address := range addresses {
|
||||
addresses_by_id[int64(address.ID)] = address
|
||||
}
|
||||
contacts, err := ContactSimplesFromIDs(ctx, txn, contact_ids)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("contact simples from ids: %w", err)
|
||||
}
|
||||
contact_by_id := make(map[int64]types.ContactSimple, 0)
|
||||
for _, contact := range contacts {
|
||||
contact_by_id[int64(contact.ID)] = contact
|
||||
}
|
||||
|
||||
results := make([]types.PublicReport, len(reports))
|
||||
for i, row := range reports {
|
||||
|
|
@ -137,6 +148,7 @@ func reportQueryToRows(ctx context.Context, reports []modelpublicreport.Report,
|
|||
Raw: row.AddressRaw,
|
||||
}
|
||||
}
|
||||
contact := contact_by_id[int64(row.ReporterContactID)]
|
||||
results[i] = types.PublicReport{
|
||||
Address: *address,
|
||||
Concerns: nil,
|
||||
|
|
@ -148,17 +160,10 @@ func reportQueryToRows(ctx context.Context, reports []modelpublicreport.Report,
|
|||
DistrictID: &row.OrganizationID,
|
||||
District: nil,
|
||||
PublicID: row.PublicID,
|
||||
Reporter: types.ContactSimple{
|
||||
Email: row.ReporterEmail,
|
||||
Name: row.ReporterName,
|
||||
Phone: types.PhoneSimple{
|
||||
CanSMS: row.ReporterPhoneCanSms,
|
||||
Number: row.ReporterPhone,
|
||||
},
|
||||
},
|
||||
Status: row.Status.String(),
|
||||
Type: row.ReportType.String(),
|
||||
URI: "",
|
||||
Reporter: contact,
|
||||
Status: row.Status.String(),
|
||||
Type: row.ReportType.String(),
|
||||
URI: "",
|
||||
}
|
||||
}
|
||||
return results, nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue