Skip to content

Commit

Permalink
StopRequest type fix
Browse files Browse the repository at this point in the history
  • Loading branch information
andmat900 committed Jan 14, 2025
1 parent 62255c8 commit 228b309
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions pkg/iut/v1alpha1/v1alpha1.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,10 @@ type StatusRequest struct {
Id uuid.UUID `json:"id"`
}

type StopRequest struct {
type IUT struct {
Id uuid.UUID `json:"id"`
}
type StopRequest []IUT

// Start creates a number of IUTs and stores them in the ETCD database returning a checkout ID.
func (h V1Alpha1Handler) Start(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
Expand Down Expand Up @@ -171,6 +172,7 @@ func (h V1Alpha1Handler) Start(w http.ResponseWriter, r *http.Request, ps httpro
return
}
startResp := StartResponse{Id: checkOutID}
logger.Infof("Start response: %s", startResp)
w.WriteHeader(http.StatusOK)
response, _ := json.Marshal(startResp)
_, _ = w.Write(response)
Expand Down Expand Up @@ -209,6 +211,7 @@ func (h V1Alpha1Handler) Status(w http.ResponseWriter, r *http.Request, ps httpr
RespondWithError(w, http.StatusInternalServerError, err.Error())
return
}
logger.Infof("Status response: %s", statusResp)
w.WriteHeader(http.StatusOK)
_, _ = w.Write(response)

Expand All @@ -225,7 +228,12 @@ func (h V1Alpha1Handler) Stop(w http.ResponseWriter, r *http.Request, ps httprou
var stopReq StopRequest
defer r.Body.Close()
if err := json.NewDecoder(r.Body).Decode(&stopReq); err != nil {
logger.Errorf("Bad delete request: %s", err.Error())
body, _err := io.ReadAll(r.Body)
if _err != nil {
logger.Errorf("Failed to read request body: %s -> %s", err, _err)
} else {
logger.Errorf("Bad delete request: %s, request body: '%s'", err.Error(), body)
}
RespondWithError(w, http.StatusBadRequest, err.Error())
return
}
Expand All @@ -243,6 +251,7 @@ func (h V1Alpha1Handler) Stop(w http.ResponseWriter, r *http.Request, ps httprou
RespondWithError(w, http.StatusInternalServerError, err.Error())
return
}
logger.Infof("Stop request succeeded")
w.WriteHeader(http.StatusNoContent)
}

Expand Down

0 comments on commit 228b309

Please sign in to comment.