Route my-family straight to the family page and build crumbs from URL state

This commit is contained in:
Ian Gulliver
2026-08-15 23:43:35 -07:00
parent 8ddf729a92
commit 2a800135b7
5 changed files with 105 additions and 33 deletions
+17 -1
View File
@@ -6,12 +6,13 @@ import (
"html/template"
"log"
"net/http"
"net/url"
"strings"
"heliosian/internal/auth"
)
var sections = []string{"people", "classrooms", "my-family", "staff", "map", "email-list"}
var sections = []string{"people", "classrooms", "staff", "map", "email-list"}
var legacy = map[string]string{
"people": "/people",
@@ -32,6 +33,7 @@ func Register(mux *http.ServeMux, cache *Cache, mapsKey string) {
for _, section := range sections {
mux.HandleFunc("GET /"+section, a.page)
}
mux.HandleFunc("GET /my-family", a.myFamily)
mux.HandleFunc("GET /profile", a.page)
mux.HandleFunc("GET /people/{email}", a.page)
mux.HandleFunc("GET /families/{key}", a.page)
@@ -41,6 +43,20 @@ func Register(mux *http.ServeMux, cache *Cache, mapsKey string) {
mux.HandleFunc("GET /api/directory/model", a.model)
}
func (a app) myFamily(w http.ResponseWriter, r *http.Request) {
model := a.cache.Model()
email := auth.Email(r)
for _, p := range model.People {
if p.Email == email && p.FamilyKey != "" {
if _, ok := model.Families[p.FamilyKey]; ok {
http.Redirect(w, r, "/families/"+url.PathEscape(p.FamilyKey), http.StatusFound)
return
}
}
}
http.Error(w, "no family record for "+email, http.StatusNotFound)
}
func (a app) legacyRedirect(w http.ResponseWriter, r *http.Request) {
first, _, _ := strings.Cut(strings.TrimPrefix(r.URL.Path, "/dl/"), "/")
target, ok := legacy[first]