Wire up events for creating new public reports
This involved moving a lot of stuff to the platform layer since I don't want event interfaces leaking out. Also this includes a fix to the user authentication which I had previously broken by making a platform-layer user object independent of the database layer.
This commit is contained in:
parent
9a5cc4cf97
commit
e8d865d0ab
24 changed files with 915 additions and 541 deletions
|
|
@ -1,8 +1,6 @@
|
|||
package rmo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
|
||||
|
|
@ -10,9 +8,7 @@ import (
|
|||
"github.com/Gleipnir-Technology/nidus-sync/db"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/html"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/platform"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type ContentDistrict struct {
|
||||
|
|
@ -57,42 +53,6 @@ func getDistrictList(w http.ResponseWriter, r *http.Request) {
|
|||
)
|
||||
|
||||
}
|
||||
func matchDistrict(ctx context.Context, longitude, latitude *float64, images []ImageUpload) (*int32, error) {
|
||||
var err error
|
||||
var org *models.Organization
|
||||
for _, image := range images {
|
||||
if image.Exif == nil {
|
||||
continue
|
||||
}
|
||||
if image.Exif.GPS == nil {
|
||||
continue
|
||||
}
|
||||
org, err = platform.DistrictForLocation(ctx, image.Exif.GPS.Longitude, image.Exif.GPS.Latitude)
|
||||
if err != nil {
|
||||
log.Warn().Err(err).Msg("Failed to get district for location")
|
||||
continue
|
||||
}
|
||||
if org != nil {
|
||||
return &org.ID, nil
|
||||
}
|
||||
}
|
||||
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 = platform.DistrictForLocation(ctx, *longitude, *latitude)
|
||||
if err != nil {
|
||||
log.Warn().Err(err).Msg("Failed to get district for location")
|
||||
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
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
func newContentDistrict(d *models.Organization) *ContentDistrict {
|
||||
if d == nil {
|
||||
return nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue