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

@ -40,7 +40,14 @@ func (s *Server) getVpc(w http.ResponseWriter, _ *http.Request, name string) {
}
func (s *Server) deleteVpc(w http.ResponseWriter, _ *http.Request, name string) {
s.dispatcher.Dispatch(dispatcher.DeleteVPCCommand{Name: name})
cmd := dispatcher.DeleteVPCCommand{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, "vpc/"+name+"/state")
w.WriteHeader(http.StatusAccepted)
json.NewEncoder(w).Encode(VPC{Name: name, State: "deleting"})
json.NewEncoder(w).Encode(VPC{Name: name, State: state})
}