aboutsummaryrefslogtreecommitdiff
path: root/internal/admin/api_rooms_bulk.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-09-16 17:05:17 -0400
committerhistoria <[not public]>2026-09-16 17:05:17 -0400
commit1dad15698845d370e998f7cc5feb8aece3fab58f (patch)
tree8d58058782de9f422573e1f8efd5d130ce7d1ce9 /internal/admin/api_rooms_bulk.go
parenta6cf03a6ae98e4fb675da25046d148e92bcf7206 (diff)
downloadthehouseoficarus-1dad15698845d370e998f7cc5feb8aece3fab58f.tar.gz
refactor: remove dead code, consolidate save/error handling, add lint gate
Diffstat (limited to 'internal/admin/api_rooms_bulk.go')
-rw-r--r--internal/admin/api_rooms_bulk.go26
1 files changed, 13 insertions, 13 deletions
diff --git a/internal/admin/api_rooms_bulk.go b/internal/admin/api_rooms_bulk.go
index a7fcee7..d10e0e3 100644
--- a/internal/admin/api_rooms_bulk.go
+++ b/internal/admin/api_rooms_bulk.go
@@ -44,23 +44,23 @@ func (s *AdminServer) handleBulkEdit(w http.ResponseWriter, r *http.Request) {
body, readErr := io.ReadAll(r.Body)
r.Body.Close()
if readErr != nil {
- writeJSON(w, map[string]any{"error": fmt.Sprintf("read body: %v", readErr)})
+ failJSON(w, fmt.Sprintf("read body: %v", readErr))
return
}
var req bulkEditRequest
if err := json.Unmarshal(body, &req); err != nil {
- writeJSON(w, map[string]any{"error": fmt.Sprintf("invalid json: %v", err)})
+ failJSON(w, fmt.Sprintf("invalid json: %v", err))
return
}
if len(req.IDs) == 0 {
- writeJSON(w, map[string]any{"error": "no room ids"})
+ failJSON(w, "no room ids")
return
}
if isEmptyPatch(req.Patch) {
- writeJSON(w, map[string]any{"error": "no patch fields"})
+ failJSON(w, "no patch fields")
return
}
@@ -78,17 +78,17 @@ func (s *AdminServer) handleBulkEdit(w http.ResponseWriter, r *http.Request) {
for _, id := range req.IDs {
path, ok := s.world.GetRoomPath(id)
if !ok {
- writeJSON(w, map[string]any{"error": fmt.Sprintf("room %d not found", id)})
+ failJSON(w, fmt.Sprintf("room %d not found", id))
return
}
oldContent, err := os.ReadFile(path)
if err != nil {
- writeJSON(w, map[string]any{"error": fmt.Sprintf("read room %d: %v", id, err)})
+ failJSON(w, fmt.Sprintf("read room %d: %v", id, err))
return
}
m, yamlErr := yamlToMap(oldContent)
if yamlErr != nil {
- writeJSON(w, map[string]any{"error": fmt.Sprintf("parse room %d: %v", id, yamlErr)})
+ failJSON(w, fmt.Sprintf("parse room %d: %v", id, yamlErr))
return
}
@@ -110,13 +110,13 @@ func (s *AdminServer) handleBulkEdit(w http.ResponseWriter, r *http.Request) {
if patch.Dir != nil && *patch.Dir != "" {
destDir := filepath.Join(s.dataDir, "rooms", *patch.Dir)
if _, statErr := os.Stat(destDir); os.IsNotExist(statErr) {
- writeJSON(w, map[string]any{"error": fmt.Sprintf("directory does not exist: %s", *patch.Dir)})
+ failJSON(w, fmt.Sprintf("directory does not exist: %s", *patch.Dir))
return
}
newPath = filepath.Join(destDir, strconv.Itoa(id)+".yaml")
if newPath != path {
if _, statErr := os.Stat(newPath); statErr == nil {
- writeJSON(w, map[string]any{"error": fmt.Sprintf("room %d already exists in target directory", id)})
+ failJSON(w, fmt.Sprintf("room %d already exists in target directory", id))
return
}
}
@@ -127,7 +127,7 @@ func (s *AdminServer) handleBulkEdit(w http.ResponseWriter, r *http.Request) {
newContent, marshalErr := marshalMapYAML(m)
if marshalErr != nil {
- writeJSON(w, map[string]any{"error": fmt.Sprintf("marshal room %d: %v", id, marshalErr)})
+ failJSON(w, fmt.Sprintf("marshal room %d: %v", id, marshalErr))
return
}
writes = append(writes, roomWrite{id: id, oldPath: path, newPath: newPath, oldContent: oldContent, newContent: newContent})
@@ -138,17 +138,17 @@ func (s *AdminServer) handleBulkEdit(w http.ResponseWriter, r *http.Request) {
for _, wr := range writes {
if wr.newPath != wr.oldPath {
if err := txn.Move(wr.oldPath, wr.newPath); err != nil {
- writeJSON(w, map[string]any{"error": fmt.Sprintf("move room %d: %v", wr.id, err)})
+ failJSON(w, fmt.Sprintf("move room %d: %v", wr.id, err))
return
}
}
if err := txn.Replace(wr.newPath, wr.newContent, 0644); err != nil {
- writeJSON(w, map[string]any{"error": fmt.Sprintf("write room %d: %v", wr.id, err)})
+ failJSON(w, fmt.Sprintf("write room %d: %v", wr.id, err))
return
}
}
if err := txn.Commit(); err != nil {
- writeJSON(w, map[string]any{"error": fmt.Sprintf("commit bulk edit: %v", err)})
+ failJSON(w, fmt.Sprintf("commit bulk edit: %v", err))
return
}