diff options
Diffstat (limited to 'internal/admin/api_search.go')
| -rw-r--r-- | internal/admin/api_search.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/internal/admin/api_search.go b/internal/admin/api_search.go index 32ef292..d54e7f1 100644 --- a/internal/admin/api_search.go +++ b/internal/admin/api_search.go @@ -2,8 +2,12 @@ package admin import ( "net/http" + "os" + "path/filepath" "strconv" "strings" + + "gopkg.in/yaml.v3" ) func (s *AdminServer) handleSearch(w http.ResponseWriter, r *http.Request) { @@ -30,6 +34,7 @@ func (s *AdminServer) handleSearch(w http.ResponseWriter, r *http.Request) { Objects []searchResult `json:"objects"` Hazards []searchResult `json:"hazards"` Drops []searchResult `json:"drops"` + Courses []searchResult `json:"courses"` } var resp searchResponse @@ -98,5 +103,21 @@ func (s *AdminServer) handleSearch(w http.ResponseWriter, r *http.Request) { } } + courseIDs, _ := listYAMLFiles(s.dataDir, "courses") + for _, id := range courseIDs { + raw, err := os.ReadFile(filepath.Join(s.dataDir, "courses", id+".yaml")) + if err != nil { + continue + } + var c map[string]any + if err := yaml.Unmarshal(raw, &c); err != nil { + continue + } + name, _ := c["name"].(string) + if strings.Contains(strings.ToLower(id), q) || strings.Contains(strings.ToLower(name), q) { + resp.Courses = append(resp.Courses, searchResult{ID: id, Name: name}) + } + } + writeJSON(w, resp) } |
