feat: add global search across beneficiaries and drivers
This commit is contained in:
9
servers/web/app_search_routes.go
Normal file
9
servers/web/app_search_routes.go
Normal 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())
|
||||
}
|
||||
26
servers/web/application/search.go
Normal file
26
servers/web/application/search.go
Normal 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)
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user