Adding new func
All checks were successful
gitea-deepak/gogmagog/pipeline/pr-master This commit looks good

This commit is contained in:
Deepak Mallubhotla 2021-01-10 10:38:03 -06:00
parent 0faef20441
commit a5528be456
Signed by: deepak
GPG Key ID: 6CB12CEDEC85EA3C

View File

@ -124,3 +124,52 @@ func postActionFunc(m *models.Model) http.HandlerFunc {
} }
} }
func putActionFunc(m *models.Model) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
r.Body = http.MaxBytesReader(w, r.Body, 1024)
dec := json.NewDecoder(r.Body)
dec.DisallowUnknownFields()
var a models.Action
err := dec.Decode(&a)
if err != nil {
badRequestError(w, err)
return
}
err = dec.Decode(&struct{}{})
if err != io.EOF {
badRequestError(w, err)
return
}
action := &models.Action{
ActionDescription: a.ActionDescription,
EstimatedChunks: a.EstimatedChunks,
CompletedChunks: a.CompletedChunks,
CompletedOn: a.CompletedOn,
PlanID: a.PlanID,
}
id, err := m.AddAction(action)
if err != nil {
serverError(w, err)
return
}
action, err = m.Action(id)
if err != nil {
serverError(w, err)
return
}
response := &createActionResponse{
CreatedAction: action,
ID: int64(id),
}
w.WriteHeader(http.StatusCreated)
w.Header().Add("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(response); err != nil {
serverError(w, err)
}
}
}