Connected nodes

This commit is contained in:
Magnus Åhall 2025-07-08 20:14:28 +02:00
parent dff17cad5b
commit 2b8472bcd1
6 changed files with 280 additions and 84 deletions

View file

@ -41,6 +41,7 @@ func initWebserver() (err error) {
http.HandleFunc("/nodes/connections/{nodeID}", actionNodeConnections)
http.HandleFunc("/nodes/create", actionNodeCreate)
http.HandleFunc("/nodes/move", actionNodeMove)
http.HandleFunc("/nodes/search", actionNodeSearch)
http.HandleFunc("/types/{typeID}", actionType)
http.HandleFunc("/types/", actionTypesAll)
@ -286,6 +287,47 @@ func actionNodeMove(w http.ResponseWriter, r *http.Request) { // {{{
j, _ := json.Marshal(out)
w.Write(j)
} // }}}
func actionNodeSearch(w http.ResponseWriter, r *http.Request) { // {{{
maxResults := 25
typeIDStr := r.URL.Query().Get("type_id")
typeID, err := strconv.Atoi(typeIDStr)
if err != nil {
typeID = -1
}
searchText := r.URL.Query().Get("search")
var nodes []Node
nodes, err = SearchNodes(typeID, searchText, maxResults)
if err != nil {
err = werr.Wrap(err)
httpError(w, err)
return
}
moreExist := len(nodes) > maxResults
if moreExist {
nodes = nodes[:maxResults]
}
out := struct {
OK bool
Nodes []Node
MoreExistThan int
}{
true,
nodes,
0,
}
if moreExist {
out.MoreExistThan = maxResults
}
j, _ := json.Marshal(out)
w.Write(j)
} // }}}
func actionType(w http.ResponseWriter, r *http.Request) { // {{{
typeID := 0
typeIDStr := r.PathValue("typeID")