Update the address when provided on a report
This commit is contained in:
parent
bac55774f8
commit
12aedaf543
6 changed files with 82 additions and 9 deletions
|
|
@ -87,7 +87,7 @@ func PublicReportMessageCreate(ctx context.Context, user User, report_id, messag
|
|||
return nil, errors.New("no contact methods available")
|
||||
}
|
||||
}
|
||||
func PublicReportUpdate(ctx context.Context, report_id string, report_setter models.PublicreportReportSetter, location *types.Location) (*types.Report, error) {
|
||||
func PublicReportUpdate(ctx context.Context, report_id string, report_setter models.PublicreportReportSetter, address *types.Address, location *types.Location) (*types.Report, error) {
|
||||
txn, err := db.PGInstance.BobDB.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("create txn: %w", err)
|
||||
|
|
@ -101,6 +101,12 @@ func PublicReportUpdate(ctx context.Context, report_id string, report_setter mod
|
|||
if err != nil {
|
||||
return nil, fmt.Errorf("update report: %w", err)
|
||||
}
|
||||
if address != nil {
|
||||
err = reportUpdateAddress(ctx, txn, report, *address)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("update address: %w", err)
|
||||
}
|
||||
}
|
||||
if location != nil {
|
||||
err = reportUpdateLocation(ctx, txn, report.ID, *location)
|
||||
if err != nil {
|
||||
|
|
@ -254,6 +260,16 @@ func reportFromID(ctx context.Context, report_id string) (*models.PublicreportRe
|
|||
}
|
||||
return report, nil
|
||||
}
|
||||
func reportUpdateAddress(ctx context.Context, txn bob.Executor, report *models.PublicreportReport, address types.Address) error {
|
||||
err := report.Update(ctx, txn, &models.PublicreportReportSetter{
|
||||
AddressGid: omit.From(address.GID),
|
||||
AddressRaw: omit.From(address.Raw),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("update report: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func reportUpdateLocation(ctx context.Context, txn bob.Executor, id int32, location types.Location) error {
|
||||
h3cell, _ := location.H3Cell()
|
||||
geom_query, _ := location.GeometryQuery()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue