Create district catch-all, make organization on public reports not null
This commit is contained in:
parent
5d86da626b
commit
1a9a72adc0
11 changed files with 140 additions and 75 deletions
|
|
@ -13,6 +13,11 @@ import (
|
|||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func DistrictCatchall(ctx context.Context) (*models.Organization, error) {
|
||||
return models.Organizations.Query(
|
||||
models.SelectWhere.Organizations.IsCatchall.EQ(true),
|
||||
).One(ctx, db.PGInstance.BobDB)
|
||||
}
|
||||
func DistrictForLocation(ctx context.Context, lng float64, lat float64) (*models.Organization, error) {
|
||||
organizations, err := models.Organizations.Query(
|
||||
sm.Where(
|
||||
|
|
@ -54,8 +59,12 @@ func MatchDistrict(ctx context.Context, longitude, latitude *float64, images []I
|
|||
}
|
||||
}
|
||||
if longitude == nil || latitude == nil {
|
||||
log.Debug().Msg("No location from images, no latlng for the report itself, cannot match")
|
||||
return nil, nil
|
||||
org, err = DistrictCatchall(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("get catchall: %w", err)
|
||||
}
|
||||
log.Debug().Int32("id", org.ID).Msg("No location from images, no latlng for the report itself, using catchall")
|
||||
return &org.ID, nil
|
||||
}
|
||||
org, err = DistrictForLocation(ctx, *longitude, *latitude)
|
||||
if err != nil {
|
||||
|
|
@ -63,8 +72,12 @@ func MatchDistrict(ctx context.Context, longitude, latitude *float64, images []I
|
|||
return nil, fmt.Errorf("Failed to get district for location: %w", err)
|
||||
}
|
||||
if org == nil {
|
||||
log.Debug().Err(err).Float64("lng", *longitude).Float64("lat", *latitude).Msg("No district match by report location")
|
||||
return nil, nil
|
||||
org, err = DistrictCatchall(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("get catchall: %w", err)
|
||||
}
|
||||
log.Debug().Err(err).Float64("lng", *longitude).Float64("lat", *latitude).Int32("id", org.ID).Msg("No district match by report location, using catchall")
|
||||
return &org.ID, nil
|
||||
}
|
||||
log.Debug().Err(err).Int32("org_id", org.ID).Float64("lng", *longitude).Float64("lat", *latitude).Msg("Found district match by report location")
|
||||
return &org.ID, nil
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ func NuisanceCreate(ctx context.Context, setter models.PublicreportNuisanceSette
|
|||
setter.AddressID = omitnull.From(a.ID)
|
||||
}
|
||||
if organization_id != nil {
|
||||
setter.OrganizationID = omitnull.FromPtr(organization_id)
|
||||
setter.OrganizationID = omit.FromPtr(organization_id)
|
||||
}
|
||||
nuisance, err := models.PublicreportNuisances.Insert(&setter).One(ctx, txn)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ func WaterCreate(ctx context.Context, setter models.PublicreportWaterSetter, lat
|
|||
setter.AddressID = omitnull.From(a.ID)
|
||||
}
|
||||
if organization_id != nil {
|
||||
setter.OrganizationID = omitnull.FromPtr(organization_id)
|
||||
setter.OrganizationID = omit.FromPtr(organization_id)
|
||||
}
|
||||
|
||||
water, err := models.PublicreportWaters.Insert(&setter).One(ctx, txn)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue