Skip to content

Commit

Permalink
Addressed review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
rimashah25 committed Aug 24, 2023
1 parent 77c9ee5 commit db32e70
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- [#7716](https://github.com/apache/trafficcontrol/pull/7716) *Apache Traffic Server* Use GCC 11 for building.

### Fixed
- [#7734](https://github.com/apache/trafficcontrol/pull/7734) *Traffic Ops* *Traffic Ops* Fixed `Profiles` V5 apis to respond with `RFC3339` date/time Format.
- [#7734](https://github.com/apache/trafficcontrol/pull/7734) *Traffic Ops* Fixed `/profiles` V5 APIs to respond with `RFC3339` date/time format.
- [#7730](https://github.com/apache/trafficcontrol/pull/7730) *Traffic Monitor* Fixed the panic seen in TM when `plugin.system_stats.timestamp_ms` appears as float and not string.
- [#4393](https://github.com/apache/trafficcontrol/issues/4393) *Traffic Ops* Fixed the error code and alert structure when TO is queried for a delivery service with no ssl keys.
- [#7690](https://github.com/apache/trafficcontrol/pull/7690) *Traffic Ops* Fixes Logs V5 apis to respond with RFC3339 tiestamps.
Expand Down
5 changes: 3 additions & 2 deletions traffic_ops/traffic_ops_golang/dbhelpers/db_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2248,7 +2248,7 @@ func DivisionExists(tx *sql.Tx, id string) (bool, error) {
return true, nil
}

// PhysLocationExists confirms whether the PhysLocationExists exists, and an error (if one occurs).
// PhysLocationExists confirms whether the PhysLocation exists, and an error (if one occurs).
func PhysLocationExists(tx *sql.Tx, id string) (bool, error) {
var count int
if err := tx.QueryRow("SELECT count(name) FROM phys_location WHERE id=$1", id).Scan(&count); err != nil {
Expand All @@ -2263,7 +2263,8 @@ func PhysLocationExists(tx *sql.Tx, id string) (bool, error) {
return true, nil
}

func ProfileExists(tx *sql.Tx, id string) (bool, error) {
// ProfileExists confirms whether the profile exists, and an error (if one occurs).
func ProfileExists(tx *sql.Tx, id int) (bool, error) {
var count int
if err := tx.QueryRow(`SELECT count(name) FROM profile WHERE id=$1`, id).Scan(&count); err != nil {
return false, fmt.Errorf("error getting profile info: %w", err)
Expand Down
15 changes: 6 additions & 9 deletions traffic_ops/traffic_ops_golang/profile/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"time"

"github.com/apache/trafficcontrol/lib/go-log"
"github.com/apache/trafficcontrol/lib/go-rfc"
"github.com/apache/trafficcontrol/lib/go-tc"
"github.com/apache/trafficcontrol/lib/go-tc/tovalidate"
"github.com/apache/trafficcontrol/lib/go-util"
Expand Down Expand Up @@ -499,7 +500,7 @@ func Create(w http.ResponseWriter, r *http.Request) {
}

alerts := tc.CreateAlerts(tc.SuccessLevel, "profile was created.")
w.Header().Set("Location", fmt.Sprintf("/api/%d.%d/profiles?id=%d", inf.Version.Major, inf.Version.Minor, profile.ID))
w.Header().Set(rfc.Location, fmt.Sprintf("/api/%s/profiles?id=%d", inf.Version, profile.ID))
api.WriteAlertsObj(w, r, http.StatusCreated, alerts, profile)
return
}
Expand Down Expand Up @@ -567,20 +568,16 @@ func Update(w http.ResponseWriter, r *http.Request) {

// Delete an profile for APIv5
func Delete(w http.ResponseWriter, r *http.Request) {
inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
inf, userErr, sysErr, errCode := api.NewInfo(r, []string{"id"}, []string{"id"})
tx := inf.Tx.Tx
if userErr != nil || sysErr != nil {
api.HandleErr(w, r, tx, errCode, userErr, sysErr)
return
}
defer inf.Close()

id := inf.Params["id"]
idInt, idConvErr := strconv.Atoi(id)
if idConvErr != nil {
api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, fmt.Errorf("profile delete error: %w, while converting from string to int", idConvErr), nil)
}
cdnName, err := dbhelpers.GetCDNNameFromProfileID(tx, idInt)
id := inf.IntParams["id"]
cdnName, err := dbhelpers.GetCDNNameFromProfileID(tx, id)
if err != nil {
api.HandleErr(w, r, tx, http.StatusInternalServerError, nil, sysErr)
return
Expand All @@ -602,7 +599,7 @@ func Delete(w http.ResponseWriter, r *http.Request) {
return
}
if !exists {
if id != "" {
if id != 0 {
api.HandleErr(w, r, tx, http.StatusNotFound, fmt.Errorf("no profile exists by id: %s", id), nil)

Check failure on line 603 in traffic_ops/traffic_ops_golang/profile/profiles.go

View workflow job for this annotation

GitHub Actions / go-vet

fmt.Errorf format %s has arg id of wrong type int
return
} else {
Expand Down

0 comments on commit db32e70

Please sign in to comment.