| 103 | } |
| 104 | |
| 105 | func handleSearch(dp *DataProvider) http.HandlerFunc { |
| 106 | return func(w http.ResponseWriter, r *http.Request) { |
| 107 | dp := effectiveDP(r, dp) |
| 108 | q := r.URL.Query().Get("q") |
| 109 | if q == "" { |
| 110 | http.Error(w, "query parameter 'q' is required", http.StatusBadRequest) |
| 111 | return |
| 112 | } |
| 113 | |
| 114 | tasks, err := getFilteredTasks(dp, r) |
| 115 | if err != nil { |
| 116 | http.Error(w, err.Error(), http.StatusInternalServerError) |
| 117 | return |
| 118 | } |
| 119 | |
| 120 | results := search.Search(tasks, q) |
| 121 | if results == nil { |
| 122 | results = []search.Result{} |
| 123 | } |
| 124 | |
| 125 | writeJSON(w, results) |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | func handleTasks(dp *DataProvider) http.HandlerFunc { |
| 130 | return func(w http.ResponseWriter, r *http.Request) { |