Bunch of work around assigning reports to districts
I added some DB schema to track logos and to relate reports to organizations. I reworked how GPS data comes from EXIF data on images because it wasn't working for JPEGs. I might have broken PNGs in the process. Also made the config options for domain names more standardized.
This commit is contained in:
parent
486a2d98c2
commit
61d8d14fc2
41 changed files with 3029 additions and 337 deletions
|
|
@ -2,30 +2,50 @@ package platform
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/stephenafamo/bob/dialect/psql"
|
||||
"github.com/stephenafamo/bob/dialect/psql/sm"
|
||||
)
|
||||
|
||||
func DistrictForLocation(ctx context.Context, lng float64, lat float64) (*models.ImportDistrict, error) {
|
||||
rows, err := models.ImportDistricts.Query(
|
||||
func DistrictForLocation(ctx context.Context, lng float64, lat float64) (*models.ImportDistrict, *models.Organization, error) {
|
||||
districts, err := models.ImportDistricts.Query(
|
||||
sm.Where(
|
||||
psql.F("ST_Contains", psql.Raw("geom_4326"), psql.F("ST_SetSRID", psql.F("ST_MakePoint", psql.Arg(lng), psql.Arg(lat)), psql.Arg(4326))),
|
||||
),
|
||||
).All(ctx, db.PGInstance.BobDB)
|
||||
|
||||
log.Debug().Int("len", len(districts)).Float64("lng", lng).Float64("lat", lat).Msg("Attempting district match")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to query district: %w", err)
|
||||
return nil, nil, fmt.Errorf("failed to query district: %w", err)
|
||||
}
|
||||
switch len(rows) {
|
||||
switch len(districts) {
|
||||
case 0:
|
||||
return nil, nil
|
||||
return nil, nil, nil
|
||||
case 1:
|
||||
return rows[0], nil
|
||||
district := districts[0]
|
||||
organizations, err := models.Organizations.Query(
|
||||
sm.Where(
|
||||
models.Organizations.Columns.ImportDistrictGid.EQ(psql.Arg(district.Gid)),
|
||||
),
|
||||
).All(ctx, db.PGInstance.BobDB)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("failed to query organization: %w", err)
|
||||
}
|
||||
switch len(organizations) {
|
||||
case 0:
|
||||
return nil, nil, nil
|
||||
case 1:
|
||||
return district, organizations[0], nil
|
||||
default:
|
||||
return nil, nil, errors.New("too many organizations")
|
||||
}
|
||||
default:
|
||||
return nil, nil
|
||||
return nil, nil, errors.New("too many districts")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue