f-21: dispatch: add a prepare step to dispatch

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2026-04-23 23:11:10 +02:00
commit 1d86c45ba4
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
7 changed files with 102 additions and 21 deletions

View file

@ -61,8 +61,15 @@ func (s *Server) getSubnet(w http.ResponseWriter, _ *http.Request, name string)
json.NewEncoder(w).Encode(sub)
}
func (s *Server) deleteSubnet(w http.ResponseWriter, r *http.Request, name string) {
s.dispatcher.Dispatch(dispatcher.DeleteSubnetCommand{Name: name})
func (s *Server) deleteSubnet(w http.ResponseWriter, _ *http.Request, name string) {
cmd := dispatcher.DeleteSubnetCommand{Name: name}
if err := s.dispatcher.Prepare(cmd); err != nil {
w.WriteHeader(http.StatusNotFound)
json.NewEncoder(w).Encode(ErrorResponse{Error: err.Error()})
return
}
s.dispatcher.Dispatch(cmd)
state, _ := kv.GetFromDB(s.db, "subnet/"+name+"/state")
w.WriteHeader(http.StatusAccepted)
json.NewEncoder(w).Encode(Subnet{Name: name, State: "deleting"})
json.NewEncoder(w).Encode(Subnet{Name: name, State: state})
}