mhoppa commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object URL: https://github.com/apache/trafficcontrol/pull/4356#discussion_r379063930
########## File path: traffic_ops/traffic_ops_golang/api/shared_handlers.go ########## @@ -395,34 +397,125 @@ func CreateHandler(creator Creator) http.HandlerFunc { obj := reflect.New(objectType).Interface().(Creator) obj.SetInfo(inf) - err := decodeAndValidateRequestBody(r, obj) - if err != nil { - HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, err, nil) - return - } + if c, ok := obj.(MultipleCreator); ok && c.AllowMultipleCreates() { + data, err := ioutil.ReadAll(r.Body) + if err != nil { + HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, err, nil) + return + } - if t, ok := obj.(Tenantable); ok { - authorized, err := t.IsTenantAuthorized(inf.User) + objSlice, err := parseMultipleCreates(data, objectType, inf) if err != nil { - HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, errors.New("checking tenant authorized: "+err.Error())) + HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, err) return } - if !authorized { - HandleErr(w, r, inf.Tx.Tx, http.StatusForbidden, errors.New("not authorized on this tenant"), nil) + + for _, objElemInt := range objSlice { Review comment: this looks great! but I wonder if there is a different approach so we dont have to loop through and do n db calls but just one to do a bulk insert. Not blocking but more of a comment to think about. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services