Skip to content

Commit

Permalink
Improve PUT /deliveryservice_request_comments id (#8071)
Browse files Browse the repository at this point in the history
  • Loading branch information
zrhoffman authored and rimashah25 committed Sep 27, 2024
1 parent 830541b commit 3b77390
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

##[8.0.2] - 2024-09-27
- [#8081](https://github.com/apache/trafficcontrol/pull/8081) *GH Actions* Updates the versions used for actions/artifact-download and actions/artifact-upload.
- [#8071](https://github.com/apache/trafficcontrol/pull/8071) *Traffic Ops* Improve validation for the `id` field of the `PUT /deliveryservice_request_comments` endpoint.
- [#8056](https://github.com/apache/trafficcontrol/pull/8056) Remove the `version` key from compose files and use `docker compose` instead of `docker-compose`.

## [8.0.1] - 2024-03-19
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ func Get(w http.ResponseWriter, r *http.Request) {
// Validate is used to ensure that the DeliveryServiceRequestCommentV5 struct passed in to the function is valid.
func Validate(dsrc tc.DeliveryServiceRequestCommentV5) error {
errs := validation.Errors{
"id": validation.Validate(dsrc.ID, validation.NotNil),
"deliveryServiceRequestId": validation.Validate(dsrc.DeliveryServiceRequestID, validation.NotNil),
"value": validation.Validate(dsrc.Value, validation.NotNil),
}
Expand All @@ -286,14 +287,21 @@ func Update(w http.ResponseWriter, r *http.Request) {
api.HandleErr(w, r, tx, http.StatusBadRequest, err, nil)
return
}
idParam := inf.Params["id"]
id, parseErr := strconv.Atoi(idParam)
if parseErr != nil {
api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("id must be an integer"), nil)
return
}
deliveryServiceRequestComment.ID = id

if err := Validate(deliveryServiceRequestComment); err != nil {
api.HandleErr(w, r, tx, http.StatusBadRequest, err, nil)
return
}

var current tc.DeliveryServiceRequestCommentV5
err := inf.Tx.QueryRowx(selectQuery() + `WHERE dsrc.id=` + inf.Params["id"]).StructScan(&current)
err := inf.Tx.QueryRowx(selectQuery() + `WHERE dsrc.id=` + strconv.Itoa(deliveryServiceRequestComment.ID)).StructScan(&current)
if err != nil {
api.HandleErr(w, r, tx, http.StatusInternalServerError, nil, errors.New("scanning deliveryservice_request_comment: "+err.Error()))
return
Expand All @@ -305,13 +313,6 @@ func Update(w http.ResponseWriter, r *http.Request) {
return
}
deliveryServiceRequestComment.AuthorID = current.AuthorID
idParam := inf.Params["id"]
id, parseErr := strconv.Atoi(idParam)
if parseErr != nil {
api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("id must be an integer"), nil)
return
}
deliveryServiceRequestComment.ID = id
userErr, sysErr, sc := api.CheckIfUnModified(r.Header, inf.Tx, id, "deliveryservice_request_comment")
if userErr != nil || sysErr != nil {
api.HandleErr(w, r, tx, sc, userErr, sysErr)
Expand Down

0 comments on commit 3b77390

Please sign in to comment.