2026-01-22 03:27:32 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
|
|
"github.com/Gleipnir-Technology/nidus-sync/db"
|
|
|
|
|
"github.com/Gleipnir-Technology/nidus-sync/db/models"
|
2026-03-12 23:49:16 +00:00
|
|
|
"github.com/Gleipnir-Technology/nidus-sync/platform/file"
|
2026-04-01 16:57:33 +00:00
|
|
|
"github.com/gorilla/mux"
|
2026-01-22 03:27:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func apiGetDistrictLogo(w http.ResponseWriter, r *http.Request) {
|
2026-04-01 16:57:33 +00:00
|
|
|
vars := mux.Vars(r)
|
|
|
|
|
slug := vars["slug"]
|
2026-01-24 19:13:55 +00:00
|
|
|
ctx := r.Context()
|
|
|
|
|
rows, err := models.Organizations.Query(
|
|
|
|
|
models.SelectWhere.Organizations.Slug.EQ(slug),
|
|
|
|
|
).All(ctx, db.PGInstance.BobDB)
|
2026-01-22 03:27:32 +00:00
|
|
|
if err != nil {
|
2026-01-24 19:13:55 +00:00
|
|
|
http.Error(w, "Failed to query", http.StatusInternalServerError)
|
2026-01-22 03:27:32 +00:00
|
|
|
return
|
|
|
|
|
}
|
2026-01-24 19:13:55 +00:00
|
|
|
switch len(rows) {
|
|
|
|
|
case 0:
|
2026-01-22 03:27:32 +00:00
|
|
|
http.Error(w, "Organization not found", http.StatusNotFound)
|
|
|
|
|
return
|
2026-01-24 19:13:55 +00:00
|
|
|
case 1:
|
|
|
|
|
org := rows[0]
|
|
|
|
|
if org.LogoUUID.IsNull() {
|
|
|
|
|
http.Error(w, "Logo not found", http.StatusNotFound)
|
|
|
|
|
return
|
|
|
|
|
}
|
2026-04-01 21:23:28 +00:00
|
|
|
file.ImageFileToWriter(file.CollectionLogo, org.LogoUUID.MustGet(), w)
|
2026-01-24 19:13:55 +00:00
|
|
|
return
|
|
|
|
|
default:
|
|
|
|
|
http.Error(w, "Too many organizations, this is a programmer error", http.StatusInternalServerError)
|
2026-01-22 03:27:32 +00:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|