feat: delete task/account, edit endpoint, richer event log
- store: DeleteAccount, DeleteTask, UpdateEndpoint (+ cascade/update tests)
- httpapi: DELETE /tasks/{id}, DELETE /tasks/{id}/accounts/{accountId},
PUT /endpoints/{id}; delete guarded with 409 while task running
- orchestrator: enrich WS events with login/host/port/error (test + run + errors)
- web: delete buttons (task, account) with confirm, endpoint edit form,
human-readable event log (source/dest, host:port, error text)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MMHQTtnQtQqL8muAXHr9kd
This commit is contained in:
@@ -31,6 +31,29 @@ func (s *Server) handleCreateEndpoint(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, http.StatusCreated, map[string]int64{"id": id})
|
||||
}
|
||||
|
||||
func (s *Server) handleUpdateEndpoint(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := pathID(r, "id")
|
||||
if err != nil {
|
||||
http.Error(w, "bad id", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
var e store.Endpoint
|
||||
if err := json.NewDecoder(r.Body).Decode(&e); err != nil {
|
||||
http.Error(w, "bad json", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if e.TLSMode != "ssl" && e.TLSMode != "starttls" && e.TLSMode != "plain" {
|
||||
http.Error(w, "tls_mode must be ssl|starttls|plain", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
e.ID = id
|
||||
if err := s.store.UpdateEndpoint(r.Context(), e); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
}
|
||||
|
||||
func (s *Server) handleListEndpoints(w http.ResponseWriter, r *http.Request) {
|
||||
eps, err := s.store.ListEndpoints(r.Context())
|
||||
if err != nil {
|
||||
|
||||
@@ -14,10 +14,13 @@ func (s *Server) Router() http.Handler {
|
||||
api := http.NewServeMux()
|
||||
api.HandleFunc("GET /api/endpoints", s.handleListEndpoints)
|
||||
api.HandleFunc("POST /api/endpoints", s.handleCreateEndpoint)
|
||||
api.HandleFunc("PUT /api/endpoints/{id}", s.handleUpdateEndpoint)
|
||||
api.HandleFunc("GET /api/tasks", s.handleListTasks)
|
||||
api.HandleFunc("POST /api/tasks", s.handleCreateTask)
|
||||
api.HandleFunc("GET /api/tasks/{id}", s.handleGetTask)
|
||||
api.HandleFunc("DELETE /api/tasks/{id}", s.handleDeleteTask)
|
||||
api.HandleFunc("POST /api/tasks/{id}/accounts", s.handleCreateAccount)
|
||||
api.HandleFunc("DELETE /api/tasks/{id}/accounts/{accountId}", s.handleDeleteAccount)
|
||||
api.HandleFunc("POST /api/tasks/{id}/import", s.handleImportCSV)
|
||||
api.HandleFunc("POST /api/tasks/{id}/test", s.handleTestAccounts)
|
||||
api.HandleFunc("POST /api/tasks/{id}/run", s.handleRun)
|
||||
|
||||
@@ -84,3 +84,52 @@ func (s *Server) handleRun(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
writeJSON(w, http.StatusAccepted, map[string]int64{"run_id": runID})
|
||||
}
|
||||
|
||||
func (s *Server) handleDeleteTask(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := pathID(r, "id")
|
||||
if err != nil {
|
||||
http.Error(w, "bad id", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
task, err := s.store.GetTask(r.Context(), id)
|
||||
if err != nil {
|
||||
http.Error(w, "not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
if task.Status == "running" {
|
||||
http.Error(w, "cannot delete a running task", http.StatusConflict)
|
||||
return
|
||||
}
|
||||
if err := s.store.DeleteTask(r.Context(), id); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
}
|
||||
|
||||
func (s *Server) handleDeleteAccount(w http.ResponseWriter, r *http.Request) {
|
||||
taskID, err := pathID(r, "id")
|
||||
if err != nil {
|
||||
http.Error(w, "bad id", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
accID, err := pathID(r, "accountId")
|
||||
if err != nil {
|
||||
http.Error(w, "bad account id", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
task, err := s.store.GetTask(r.Context(), taskID)
|
||||
if err != nil {
|
||||
http.Error(w, "not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
if task.Status == "running" {
|
||||
http.Error(w, "cannot modify accounts while task is running", http.StatusConflict)
|
||||
return
|
||||
}
|
||||
if err := s.store.DeleteAccount(r.Context(), accID); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user