aboutsummaryrefslogtreecommitdiff
path: root/internal/admin/api_techs.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/admin/api_techs.go')
-rw-r--r--internal/admin/api_techs.go22
1 files changed, 11 insertions, 11 deletions
diff --git a/internal/admin/api_techs.go b/internal/admin/api_techs.go
index ba3288a..91eb929 100644
--- a/internal/admin/api_techs.go
+++ b/internal/admin/api_techs.go
@@ -20,7 +20,7 @@ func (s *AdminServer) handleTechs(w http.ResponseWriter, r *http.Request) {
case http.MethodGet:
tree, err := listYAMLTree(s.dataDir, "techs")
if err != nil {
- writeJSON(w, map[string]any{"error": err.Error()})
+ failJSON(w, err.Error())
return
}
if tree == nil {
@@ -30,23 +30,23 @@ func (s *AdminServer) handleTechs(w http.ResponseWriter, r *http.Request) {
case http.MethodPost:
var m map[string]any
if err := readJSON(r, &m); err != nil {
- writeJSON(w, map[string]any{"error": "invalid json"})
+ failJSON(w, "invalid json")
return
}
id, ok := m["id"].(string)
if !ok || strings.TrimSpace(id) == "" {
- writeJSON(w, map[string]any{"error": "missing id"})
+ failJSON(w, "missing id")
return
}
delete(m, "id")
if _, _, err := s.findTechFile(id); err == nil {
- writeJSON(w, map[string]any{"error": "tech already exists"})
+ failJSON(w, "tech already exists")
return
}
path := filepath.Join(s.dataDir, "techs", id+".yaml")
newContent, err := writeMapAsYAML(path, m)
if err != nil {
- writeJSON(w, map[string]any{"error": "write error: " + err.Error()})
+ failJSON(w, "write error: "+err.Error())
return
}
s.undoStack.Push(ChangeDesc{
@@ -76,12 +76,12 @@ func (s *AdminServer) handleTechByID(w http.ResponseWriter, r *http.Request) {
case http.MethodGet:
data, path, err := s.findTechFile(id)
if err != nil {
- writeJSON(w, map[string]any{"error": "not found: " + id})
+ failJSON(w, "not found: "+id)
return
}
raw, err := yamlToMap(data)
if err != nil {
- writeJSON(w, map[string]any{"error": "parse error: " + err.Error()})
+ failJSON(w, "parse error: "+err.Error())
return
}
raw["id"] = id
@@ -92,7 +92,7 @@ func (s *AdminServer) handleTechByID(w http.ResponseWriter, r *http.Request) {
case http.MethodPost, http.MethodPut:
var body map[string]any
if err := readJSON(r, &body); err != nil {
- writeJSON(w, map[string]any{"error": "invalid JSON: " + err.Error()})
+ failJSON(w, "invalid JSON: "+err.Error())
return
}
delete(body, "id")
@@ -114,7 +114,7 @@ func (s *AdminServer) handleTechByID(w http.ResponseWriter, r *http.Request) {
newContent, err := writeMapAsYAML(path, body)
if err != nil {
- writeJSON(w, map[string]any{"error": "write error: " + err.Error()})
+ failJSON(w, "write error: "+err.Error())
return
}
@@ -134,12 +134,12 @@ func (s *AdminServer) handleTechByID(w http.ResponseWriter, r *http.Request) {
case http.MethodDelete:
_, path, err := s.findTechFile(id)
if err != nil {
- writeJSON(w, map[string]any{"error": "not found: " + id})
+ failJSON(w, "not found: "+id)
return
}
oldContent, _ := snapshotFile(path)
if err := os.Remove(path); err != nil {
- writeJSON(w, map[string]any{"error": "delete error: " + err.Error()})
+ failJSON(w, "delete error: "+err.Error())
return
}
s.undoStack.Push(ChangeDesc{