Rudimentary creating of nodes
This commit is contained in:
parent
08fd2cf4e9
commit
c0255fadb8
7 changed files with 363 additions and 55 deletions
43
webserver.go
43
webserver.go
|
|
@ -34,6 +34,7 @@ func initWebserver() (err error) {
|
|||
http.HandleFunc("/nodes/tree/{startNode}", actionNodesTree)
|
||||
http.HandleFunc("/nodes/{nodeID}", actionNode)
|
||||
http.HandleFunc("/nodes/update/{nodeID}", actionNodeUpdate)
|
||||
http.HandleFunc("/nodes/create", actionNodeCreate)
|
||||
http.HandleFunc("/types/{typeID}", actionType)
|
||||
http.HandleFunc("/types/", actionTypesAll)
|
||||
|
||||
|
|
@ -62,7 +63,16 @@ func pageIndex(w http.ResponseWriter, r *http.Request) { // {{{
|
|||
} // }}}
|
||||
func pageApp(w http.ResponseWriter, r *http.Request) { // {{{
|
||||
page := NewPage("app")
|
||||
err := engine.Render(page, w, r)
|
||||
|
||||
ts, err := GetTypes()
|
||||
if err != nil {
|
||||
httpError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
page.Data["Types"] = ts
|
||||
|
||||
err = engine.Render(page, w, r)
|
||||
if err != nil {
|
||||
w.Write([]byte(err.Error()))
|
||||
}
|
||||
|
|
@ -132,7 +142,34 @@ func actionNodeUpdate(w http.ResponseWriter, r *http.Request) { // {{{
|
|||
}
|
||||
|
||||
out := struct {
|
||||
OK bool
|
||||
OK bool
|
||||
}{
|
||||
true,
|
||||
}
|
||||
j, _ := json.Marshal(out)
|
||||
w.Write(j)
|
||||
} // }}}
|
||||
func actionNodeCreate(w http.ResponseWriter, r *http.Request) { // {{{
|
||||
var req struct {
|
||||
ParentNodeID int
|
||||
TypeID int
|
||||
Name string
|
||||
}
|
||||
data, _ := io.ReadAll(r.Body)
|
||||
err := json.Unmarshal(data, &req)
|
||||
if err != nil {
|
||||
httpError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
err = CreateNode(req.ParentNodeID, req.TypeID, req.Name)
|
||||
if err != nil {
|
||||
httpError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
out := struct {
|
||||
OK bool
|
||||
}{
|
||||
true,
|
||||
}
|
||||
|
|
@ -161,7 +198,7 @@ func actionTypesAll(w http.ResponseWriter, r *http.Request) { // {{{
|
|||
}
|
||||
|
||||
out := struct {
|
||||
OK bool
|
||||
OK bool
|
||||
Types []NodeType
|
||||
}{
|
||||
true,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue