From 342d15566eb23ba406cff59223b46ef304e3350d Mon Sep 17 00:00:00 2001 From: Jonathon Leight Date: Sat, 20 Jun 2026 15:41:00 -0400 Subject: [PATCH] Organization region field --- internal/store/migrations/0010_org_region.sql | 7 + internal/store/orgs.go | 16 ++- internal/web/orgs.go | 7 +- internal/web/templates/base.html | 6 +- internal/web/templates/icons.html | 1 + internal/web/templates/org.html | 31 +++-- internal/web/templates/org_public.html | 123 +++++++++++++----- 7 files changed, 136 insertions(+), 55 deletions(-) create mode 100644 internal/store/migrations/0010_org_region.sql diff --git a/internal/store/migrations/0010_org_region.sql b/internal/store/migrations/0010_org_region.sql new file mode 100644 index 0000000..f5071fe --- /dev/null +++ b/internal/store/migrations/0010_org_region.sql @@ -0,0 +1,7 @@ +-- +goose Up +-- Freeform region/location for an organization (e.g. "Buffalo, NY"), shown on +-- the org page and public directory. +ALTER TABLE organizations ADD COLUMN region TEXT NOT NULL DEFAULT ''; + +-- +goose Down +ALTER TABLE organizations DROP COLUMN region; diff --git a/internal/store/orgs.go b/internal/store/orgs.go index 964e3e7..4e824d7 100644 --- a/internal/store/orgs.go +++ b/internal/store/orgs.go @@ -14,6 +14,7 @@ type Org struct { ID int64 Name string Description string + Region string CreatedBy *int64 CreatedAt time.Time } @@ -61,8 +62,8 @@ func (s *Store) CreateOrg(ctx context.Context, name string, creatorID int64) (*O var o Org if err := tx.QueryRow(ctx, `INSERT INTO organizations (name, created_by) VALUES ($1, $2) - RETURNING id, name, description, created_by, created_at`, - name, creatorID).Scan(&o.ID, &o.Name, &o.Description, &o.CreatedBy, &o.CreatedAt); err != nil { + RETURNING id, name, description, region, created_by, created_at`, + name, creatorID).Scan(&o.ID, &o.Name, &o.Description, &o.Region, &o.CreatedBy, &o.CreatedAt); err != nil { return nil, fmt.Errorf("insert org: %w", err) } if _, err := tx.Exec(ctx, @@ -100,8 +101,8 @@ func (s *Store) CreateOrg(ctx context.Context, name string, creatorID int64) (*O func (s *Store) GetOrg(ctx context.Context, id int64) (*Org, error) { var o Org err := s.pool.QueryRow(ctx, - `SELECT id, name, description, created_by, created_at FROM organizations WHERE id = $1`, id). - Scan(&o.ID, &o.Name, &o.Description, &o.CreatedBy, &o.CreatedAt) + `SELECT id, name, description, region, created_by, created_at FROM organizations WHERE id = $1`, id). + Scan(&o.ID, &o.Name, &o.Description, &o.Region, &o.CreatedBy, &o.CreatedAt) if errors.Is(err, pgx.ErrNoRows) { return nil, ErrNotFound } @@ -111,10 +112,11 @@ func (s *Store) GetOrg(ctx context.Context, id int64) (*Org, error) { return &o, nil } -// UpdateOrg updates an org's name and description. -func (s *Store) UpdateOrg(ctx context.Context, orgID int64, name, description string) error { +// UpdateOrg updates an org's name, description, and region. +func (s *Store) UpdateOrg(ctx context.Context, orgID int64, name, description, region string) error { tag, err := s.pool.Exec(ctx, - `UPDATE organizations SET name = $2, description = $3 WHERE id = $1`, orgID, name, description) + `UPDATE organizations SET name = $2, description = $3, region = $4 WHERE id = $1`, + orgID, name, description, region) if err != nil { return fmt.Errorf("update org: %w", err) } diff --git a/internal/web/orgs.go b/internal/web/orgs.go index 7210923..38976a2 100644 --- a/internal/web/orgs.go +++ b/internal/web/orgs.go @@ -130,7 +130,6 @@ func (s *Server) pageOrg(w http.ResponseWriter, r *http.Request) { "MemberCount": len(members), "RepeaterCount": len(repeaters), "AdminCount": adminCount, - "MappedCount": mapped, "Self": uid, "Error": r.URL.Query().Get("error"), } @@ -198,6 +197,7 @@ func (s *Server) handleEditOrg(w http.ResponseWriter, r *http.Request) { } name := strings.TrimSpace(r.FormValue("name")) desc := strings.TrimSpace(r.FormValue("description")) + region := strings.TrimSpace(r.FormValue("region")) if name == "" || len(name) > 80 { orgErr(w, r, id, "Enter an organization name.") return @@ -205,7 +205,10 @@ func (s *Server) handleEditOrg(w http.ResponseWriter, r *http.Request) { if len(desc) > 2000 { desc = desc[:2000] } - if err := s.store.UpdateOrg(r.Context(), id, name, desc); err != nil { + if len(region) > 120 { + region = region[:120] + } + if err := s.store.UpdateOrg(r.Context(), id, name, desc, region); err != nil { orgErr(w, r, id, "Could not save changes.") return } diff --git a/internal/web/templates/base.html b/internal/web/templates/base.html index 276100b..187ed9b 100644 --- a/internal/web/templates/base.html +++ b/internal/web/templates/base.html @@ -17,7 +17,7 @@ - {{template "icon-tower" "me-2"}}MeshTender + {{template "icon-tower" "me-1"}}MeshTender