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
|
|
@ -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})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue