Push geocoding down a layer

This makes it possible to always save address information from our
geocoder.
This commit is contained in:
Eli Ribble 2026-03-04 18:29:52 +00:00
parent 80e14568c6
commit daa8cb1748
No known key found for this signature in database
26 changed files with 576 additions and 431 deletions

View file

@ -15,6 +15,7 @@ import (
"github.com/Gleipnir-Technology/nidus-sync/db/models"
"github.com/Gleipnir-Technology/nidus-sync/html"
nhttp "github.com/Gleipnir-Technology/nidus-sync/http"
"github.com/Gleipnir-Technology/nidus-sync/platform"
"github.com/go-chi/chi/v5"
"github.com/google/uuid"
)
@ -30,12 +31,12 @@ type contentSource struct {
Treatments []Treatment
//TreatmentCadence TreatmentCadence
TreatmentModels []TreatmentModel
User User
User platform.User
}
type contentTrap struct {
MapData ComponentMap
Trap Trap
User User
User platform.User
}
type contentDashboard struct {
CountTraps int
@ -49,7 +50,7 @@ type contentDashboard struct {
}
type contentLayoutTest struct {
User User
User platform.User
}
type ContentDistrict struct {
MapboxToken string
@ -103,7 +104,7 @@ func getSource(ctx context.Context, r *http.Request, org *models.Organization, u
if err != nil {
return nil, nhttp.NewError("globalid is not a UUID: %w", nil)
}
userContent, err := contentForUser(r.Context(), user)
userContent, err := auth.ContentForUser(r.Context(), user)
if err != nil {
return nil, nhttp.NewError("Failed to get user content: %w", err)
}
@ -172,7 +173,7 @@ func getTrap(ctx context.Context, r *http.Request, org *models.Organization, use
if err != nil {
return nil, nhttp.NewError("globalid is not a UUID: %w", nil)
}
userContent, err := contentForUser(r.Context(), user)
userContent, err := auth.ContentForUser(r.Context(), user)
if err != nil {
return nil, nhttp.NewError("Failed to get user content: %w", err)
}
@ -254,7 +255,7 @@ func dashboard(ctx context.Context, w http.ResponseWriter, org *models.Organizat
},
RecentRequests: requests,
}
userContent, err := contentForUser(ctx, user)
userContent, err := auth.ContentForUser(ctx, user)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return

View file

@ -9,6 +9,7 @@ import (
"github.com/Gleipnir-Technology/nidus-sync/db/models"
"github.com/Gleipnir-Technology/nidus-sync/html"
nhttp "github.com/Gleipnir-Technology/nidus-sync/http"
"github.com/Gleipnir-Technology/nidus-sync/platform"
"github.com/rs/zerolog/log"
)
@ -19,14 +20,14 @@ type contentAuthenticated[T any] struct {
Config html.ContentConfig
Organization *models.Organization
URL html.ContentURL
User User
User platform.User
}
// w http.ResponseWriter, r *http.Request, u *models.User) {
func authenticatedHandler[T any](f handlerFunctionGet[T]) http.Handler {
return auth.NewEnsureAuth(func(w http.ResponseWriter, r *http.Request, u *models.User) {
ctx := r.Context()
userContent, err := contentForUser(ctx, u)
userContent, err := auth.ContentForUser(ctx, u)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return

View file

@ -3,7 +3,6 @@ package sync
import (
"time"
"github.com/Gleipnir-Technology/nidus-sync/notification"
"github.com/google/uuid"
"github.com/uber/h3-go/v4"
)
@ -48,9 +47,6 @@ type ContentReportDetail struct {
}
type ContentReportDiagnostic struct {
}
type ContentDashboardLoading struct {
User User
}
type Inspection struct {
Action string
@ -63,20 +59,8 @@ type Link struct {
Href string
Title string
}
type Organization struct {
ID int
Name string
}
type ServiceRequestSummary struct {
Date time.Time
Location string
Status string
}
type User struct {
DisplayName string
Initials string
Notifications []notification.Notification
Organization Organization
Role string
Username string
}

View file

@ -85,7 +85,7 @@ func postUploadCommit(ctx context.Context, r *http.Request, org *models.Organiza
}
err = platform.UploadCommit(ctx, org, int32(file_id_))
if err != nil {
return "", nhttp.NewError("Failed to mark discarded: %w", err)
return "", nhttp.NewError("Failed to mark committed: %w", err)
}
return "/configuration/upload", nil
}

View file

@ -12,7 +12,6 @@ import (
"github.com/Gleipnir-Technology/nidus-sync/db"
"github.com/Gleipnir-Technology/nidus-sync/db/models"
"github.com/Gleipnir-Technology/nidus-sync/db/sql"
"github.com/Gleipnir-Technology/nidus-sync/notification"
"github.com/google/uuid"
"github.com/uber/h3-go/v4"
)
@ -77,41 +76,6 @@ func sourceByGlobalId(ctx context.Context, org *models.Organization, id uuid.UUI
return toTemplateBreedingSource(row), nil
}
func extractInitials(name string) string {
parts := strings.Fields(name)
var initials strings.Builder
for _, part := range parts {
if len(part) > 0 {
initials.WriteString(strings.ToUpper(string(part[0])))
}
}
return initials.String()
}
func contentForUser(ctx context.Context, user *models.User) (User, error) {
notifications, err := notification.ForUser(ctx, user)
if err != nil {
return User{}, err
}
org := user.R.Organization
var organization Organization
if org != nil {
organization.ID = int(org.ID)
organization.Name = org.Name
}
return User{
DisplayName: user.DisplayName,
Initials: extractInitials(user.DisplayName),
Notifications: notifications,
Organization: organization,
Role: user.Role.String(),
Username: user.Username,
}, nil
}
func trapsBySource(ctx context.Context, org *models.Organization, sourceID uuid.UUID) ([]TrapNearby, error) {
locations, err := sql.TrapLocationBySourceID(org.ID, sourceID).All(ctx, db.PGInstance.BobDB)
if err != nil {