f-21: dispatch: add a prepare step to dispatch
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
19434b1848
commit
1d86c45ba4
7 changed files with 102 additions and 21 deletions
|
|
@ -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})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue