feat: add global search across beneficiaries and drivers

This commit is contained in:
Arnaud Delcasse
2026-02-26 14:54:22 +01:00
parent bb525f174d
commit b79cc08b06
5 changed files with 103 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
package web
import (
"github.com/gorilla/mux"
)
func (ws *WebServer) setupSearchRoutes(appRouter *mux.Router) {
appRouter.HandleFunc("/search", ws.appHandler.GlobalSearchHTTPHandler())
}

View File

@@ -0,0 +1,26 @@
package application
import (
"net/http"
"github.com/rs/zerolog/log"
)
func (h *Handler) GlobalSearchHTTPHandler() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
query := r.URL.Query().Get("q")
if query == "" {
http.Redirect(w, r, "/app/", http.StatusFound)
return
}
result, err := h.applicationHandler.GlobalSearch(r.Context(), query)
if err != nil {
log.Error().Err(err).Msg("error performing global search")
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
return
}
h.renderer.GlobalSearchResults(w, r, query, result.Beneficiaries, result.SolidarityDrivers, result.OrganizedCarpoolDrivers)
}
}

View File

@@ -8,6 +8,7 @@ func (ws *WebServer) setupApplicationRoutes(r *mux.Router) {
application := r.PathPrefix("/app").Subrouter()
// Setup all application route groups
ws.setupSearchRoutes(application)
ws.setupDashboardRoutes(application)
setupMiscRoutes(application, ws.applicationHandler)
ws.setupDirectoryRoutes(application)