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

@ -62,7 +62,14 @@ func (s *Server) postVpc(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(ErrorResponse{Error: "name is required"})
return
}
s.dispatcher.Dispatch(dispatcher.CreateVPCCommand{Name: req.Name})
cmd := dispatcher.CreateVPCCommand{Name: req.Name}
if err := s.dispatcher.Prepare(cmd); err != nil {
w.WriteHeader(http.StatusConflict)
json.NewEncoder(w).Encode(ErrorResponse{Error: err.Error()})
return
}
s.dispatcher.Dispatch(cmd)
state, _ := kv.GetFromDB(s.db, "vpc/"+req.Name+"/state")
w.WriteHeader(http.StatusAccepted)
json.NewEncoder(w).Encode(VPC{Name: req.Name, State: "creating"})
json.NewEncoder(w).Encode(VPC{Name: req.Name, State: state})
}