Render organization logos by 'slug'

This avoids leaking org IDs in the URL, and makes it possible to have a
district-specific root mock that works in both dev and prod.
This commit is contained in:
Eli Ribble 2026-01-24 19:13:55 +00:00
parent 45868e4bde
commit f549243c10
No known key found for this signature in database
10 changed files with 259 additions and 17 deletions

View file

@ -54,21 +54,29 @@ func apiGetDistrict(w http.ResponseWriter, r *http.Request) {
}
func apiGetDistrictLogo(w http.ResponseWriter, r *http.Request) {
id_str := chi.URLParam(r, "id")
org_id, err := strconv.ParseInt(id_str, 10, 32)
slug := chi.URLParam(r, "slug")
ctx := r.Context()
rows, err := models.Organizations.Query(
models.SelectWhere.Organizations.Slug.EQ(slug),
).All(ctx, db.PGInstance.BobDB)
if err != nil {
render.Render(w, r, errRender(fmt.Errorf("%s is not a recognized organization ID: %w", id_str, err)))
http.Error(w, "Failed to query", http.StatusInternalServerError)
return
}
ctx := r.Context()
org, err := models.FindOrganization(ctx, db.PGInstance.BobDB, int32(org_id))
if err != nil {
switch len(rows) {
case 0:
http.Error(w, "Organization not found", http.StatusNotFound)
return
}
if org.LogoUUID.IsNull() {
http.Error(w, "Logo not found", http.StatusNotFound)
case 1:
org := rows[0]
if org.LogoUUID.IsNull() {
http.Error(w, "Logo not found", http.StatusNotFound)
return
}
userfile.ImageFileContentWriteLogo(w, org.LogoUUID.MustGet())
return
default:
http.Error(w, "Too many organizations, this is a programmer error", http.StatusInternalServerError)
return
}
userfile.ImageFileContentWriteLogo(w, org.LogoUUID.MustGet())
}