This is an automated email from the ASF dual-hosted git repository.

mitchell852 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-trafficcontrol.git

commit 95f7a1ef269aebab537dca29b0efa127ebb3b0d8
Author: Dewayne Richardson <dewr...@apache.org>
AuthorDate: Tue Apr 3 12:30:50 2018 -0600

    removed the PUT for profileparameters because it isnt relevant
---
 .../profileparameter/profile_parameters.go         | 127 ++++++---------------
 .../profileparameter/profile_parameters_test.go    |  19 ++-
 traffic_ops/traffic_ops_golang/routes.go           |   1 -
 3 files changed, 46 insertions(+), 101 deletions(-)

diff --git 
a/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters.go 
b/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters.go
index 893a792..696cfef 100644
--- a/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters.go
+++ b/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters.go
@@ -37,6 +37,11 @@ import (
        "github.com/lib/pq"
 )
 
+const (
+       ProfileIDQueryParam   = "profileId"
+       ParameterIDQueryParam = "parameterId"
+)
+
 //we need a type alias to define functions on
 type TOProfileParameter v13.ProfileParameterNullable
 
@@ -48,23 +53,29 @@ func GetRefType() *TOProfileParameter {
 }
 
 func (pp TOProfileParameter) GetKeyFieldsInfo() []api.KeyFieldInfo {
-       return []api.KeyFieldInfo{{"profile", api.GetIntKey}, {"parameter", 
api.GetIntKey}}
+       return []api.KeyFieldInfo{{ProfileIDQueryParam, api.GetIntKey}, 
{ParameterIDQueryParam, api.GetIntKey}}
 }
 
 //Implementation of the Identifier, Validator interface functions
 func (pp TOProfileParameter) GetKeys() (map[string]interface{}, bool) {
-       if pp.ProfileId == nil {
-               return map[string]interface{}{"profile": 0}, false
+       if pp.ProfileID == nil {
+               return map[string]interface{}{ProfileIDQueryParam: 0}, false
        }
-       if pp.ParameterId == nil {
-               return map[string]interface{}{"parameter": 0}, false
+       if pp.ParameterID == nil {
+               return map[string]interface{}{ParameterIDQueryParam: 0}, false
        }
-       return map[string]interface{}{"id": *pp.Profile}, true
+       keys := make(map[string]interface{})
+       profileID := *pp.ProfileID
+       parameterID := *pp.ParameterID
+
+       keys[ProfileIDQueryParam] = profileID
+       keys[ParameterIDQueryParam] = parameterID
+       return keys, true
 }
 
 func (pp *TOProfileParameter) GetAuditName() string {
-       if pp.ProfileId != nil {
-               return strconv.Itoa(*pp.ProfileId) + "-" + 
strconv.Itoa(*pp.ParameterId)
+       if pp.ProfileID != nil {
+               return strconv.Itoa(*pp.ProfileID) + "-" + 
strconv.Itoa(*pp.ParameterID)
        }
        return "unknown"
 }
@@ -74,19 +85,19 @@ func (pp *TOProfileParameter) GetType() string {
 }
 
 func (pp *TOProfileParameter) SetKeys(keys map[string]interface{}) {
-       profId, _ := keys["profile"].(int) //this utilizes the non panicking 
type assertion, if the thrown away ok variable is false i will be the zero of 
the type, 0 here.
-       pp.ProfileId = &profId
+       profId, _ := keys[ProfileIDQueryParam].(int) //this utilizes the non 
panicking type assertion, if the thrown away ok variable is false i will be the 
zero of the type, 0 here.
+       pp.ProfileID = &profId
 
-       paramId, _ := keys["parameter"].(int) //this utilizes the non panicking 
type assertion, if the thrown away ok variable is false i will be the zero of 
the type, 0 here.
-       pp.ParameterId = &paramId
+       paramId, _ := keys[ParameterIDQueryParam].(int) //this utilizes the non 
panicking type assertion, if the thrown away ok variable is false i will be the 
zero of the type, 0 here.
+       pp.ParameterID = &paramId
 }
 
 // Validate fulfills the api.Validator interface
-func (pp TOProfileParameter) Validate(db *sqlx.DB) []error {
+func (pp *TOProfileParameter) Validate(db *sqlx.DB) []error {
 
        errs := validation.Errors{
-               "profile":   validation.Validate(pp.Profile, 
validation.Required),
-               "parameter": validation.Validate(pp.Parameter, 
validation.Required),
+               "profile":   validation.Validate(pp.ProfileID, 
validation.Required),
+               "parameter": validation.Validate(pp.ParameterID, 
validation.Required),
        }
 
        return tovalidate.ToErrors(errs)
@@ -152,7 +163,7 @@ func (pp *TOProfileParameter) Create(db *sqlx.DB, user 
auth.CurrentUser) (error,
                return tc.DBError, tc.SystemError
        }
 
-       pp.SetKeys(map[string]interface{}{"profile": profile, "parameter": 
parameter})
+       pp.SetKeys(map[string]interface{}{ProfileIDQueryParam: profile, 
ParameterIDQueryParam: parameter})
        pp.LastUpdated = &lastUpdated
        err = tx.Commit()
        if err != nil {
@@ -167,8 +178,8 @@ func insertQuery() string {
        query := `INSERT INTO profile_parameter (
 profile,
 parameter) VALUES (
-:profile,
-:parameter) RETURNING profile_profile,last_updated`
+:profile_id,
+:parameter_id) RETURNING profile, parameter, last_updated`
        return query
 }
 
@@ -178,9 +189,9 @@ func (pp *TOProfileParameter) Read(db *sqlx.DB, parameters 
map[string]string, us
        // Query Parameters to Database Query column mappings
        // see the fields mapped in the SQL query
        queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
-               "profile":      dbhelpers.WhereColumnInfo{"pp.profile", nil},
-               "parameter":    dbhelpers.WhereColumnInfo{"pp.parameter", nil},
-               "last_updated": dbhelpers.WhereColumnInfo{"pp.last_updated", 
nil},
+               "profileId":   dbhelpers.WhereColumnInfo{"pp.profile", nil},
+               "parameterId": dbhelpers.WhereColumnInfo{"pp.parameter", nil},
+               "lastUpdated": dbhelpers.WhereColumnInfo{"pp.last_updated", 
nil},
        }
 
        where, orderBy, queryValues, errs := 
dbhelpers.BuildWhereAndOrderBy(parameters, queryParamsToQueryCols)
@@ -212,70 +223,6 @@ func (pp *TOProfileParameter) Read(db *sqlx.DB, parameters 
map[string]string, us
 
 }
 
-//The TOProfileParameter implementation of the Updater interface
-//all implementations of Updater should use transactions and return the proper 
errorType
-//ParsePQUniqueConstraintError is used to determine if a parameter with 
conflicting values exists
-//if so, it will return an errorType of DataConflict and the type should be 
appended to the
-//generic error message returned
-func (pp *TOProfileParameter) Update(db *sqlx.DB, user auth.CurrentUser) 
(error, tc.ApiErrorType) {
-       rollbackTransaction := true
-       tx, err := db.Beginx()
-       defer func() {
-               if tx == nil || !rollbackTransaction {
-                       return
-               }
-               err := tx.Rollback()
-               if err != nil {
-                       log.Errorln(errors.New("rolling back transaction: " + 
err.Error()))
-               }
-       }()
-
-       if err != nil {
-               log.Error.Printf("could not begin transaction: %v", err)
-               return tc.DBError, tc.SystemError
-       }
-       log.Debugf("about to run exec query: %s with parameter: %++v", 
updateQuery(), pp)
-       resultRows, err := tx.NamedQuery(updateQuery(), pp)
-       if err != nil {
-               if pqErr, ok := err.(*pq.Error); ok {
-                       err, eType := 
dbhelpers.ParsePQUniqueConstraintError(pqErr)
-                       if eType == tc.DataConflictError {
-                               return errors.New("a parameter with " + 
err.Error()), eType
-                       }
-                       return err, eType
-               }
-               log.Errorf("received error: %++v from update execution", err)
-               return tc.DBError, tc.SystemError
-       }
-       defer resultRows.Close()
-
-       // get LastUpdated field -- updated by trigger in the db
-       var lastUpdated tc.TimeNoMod
-       rowsAffected := 0
-       for resultRows.Next() {
-               rowsAffected++
-               if err := resultRows.Scan(&lastUpdated); err != nil {
-                       log.Error.Printf("could not scan lastUpdated from 
insert: %s\n", err)
-                       return tc.DBError, tc.SystemError
-               }
-       }
-       log.Debugf("lastUpdated: %++v", lastUpdated)
-       pp.LastUpdated = &lastUpdated
-       if rowsAffected != 1 {
-               if rowsAffected < 1 {
-                       return errors.New("no parameter found with this id"), 
tc.DataMissingError
-               }
-               return fmt.Errorf("this update affected too many rows: %d", 
rowsAffected), tc.SystemError
-       }
-       err = tx.Commit()
-       if err != nil {
-               log.Errorln("Could not commit transaction: ", err)
-               return tc.DBError, tc.SystemError
-       }
-       rollbackTransaction = false
-       return nil, tc.NoError
-}
-
 //The Parameter implementation of the Deleter interface
 //all implementations of Deleter should use transactions and return the proper 
errorType
 func (pp *TOProfileParameter) Delete(db *sqlx.DB, user auth.CurrentUser) 
(error, tc.ApiErrorType) {
@@ -338,14 +285,16 @@ JOIN parameter param ON param.id = pp.parameter`
 func updateQuery() string {
        query := `UPDATE
 profile_parameter SET
-profile=:profile,
-parameter=:parameter
-WHERE id=:id RETURNING last_updated`
+profile=:profile_id,
+parameter=:parameter_id
+WHERE profile=:profile_id AND 
+      parameter = :parameter_id 
+      RETURNING last_updated`
        return query
 }
 
 func deleteQuery() string {
        query := `DELETE FROM profile_parameter
-       WHERE profile=:profile and parameter=:parameter`
+       WHERE profile=:profile_id and parameter=:parameter_id`
        return query
 }
diff --git 
a/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters_test.go 
b/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters_test.go
index a066c2e..5ad3d28 100644
--- a/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters_test.go
+++ b/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters_test.go
@@ -36,19 +36,19 @@ func getTestProfileParameters() 
[]tc.ProfileParameterNullable {
        pps := []tc.ProfileParameterNullable{}
        lastUpdated := tc.TimeNoMod{}
        lastUpdated.Scan(time.Now())
-       profileId := 1
-       parameterId := 1
+       profileID := 1
+       parameterID := 1
 
        pp := tc.ProfileParameterNullable{
                LastUpdated: &lastUpdated,
-               ProfileId:   &profileId,
-               ParameterId: &parameterId,
+               ProfileID:   &profileID,
+               ParameterID: &parameterID,
        }
        pps = append(pps, pp)
 
        pp2 := pp
-       pp2.ProfileId = &profileId
-       pp2.ParameterId = &parameterId
+       pp2.ProfileID = &profileID
+       pp2.ParameterID = &parameterID
        pps = append(pps, pp2)
 
        return pps
@@ -72,9 +72,9 @@ func TestGetProfileParameters(t *testing.T) {
                rows = rows.AddRow(
                        ts.LastUpdated,
                        ts.Profile,
-                       ts.ProfileId,
+                       ts.ProfileID,
                        ts.Parameter,
-                       ts.ParameterId,
+                       ts.ParameterID,
                )
        }
        mock.ExpectQuery("SELECT").WillReturnRows(rows)
@@ -101,9 +101,6 @@ func TestInterfaces(t *testing.T) {
        if _, ok := i.(api.Reader); !ok {
                t.Errorf("ProfileParameter must be Reader")
        }
-       if _, ok := i.(api.Updater); !ok {
-               t.Errorf("ProfileParameter must be Updater")
-       }
        if _, ok := i.(api.Deleter); !ok {
                t.Errorf("ProfileParameter must be Deleter")
        }
diff --git a/traffic_ops/traffic_ops_golang/routes.go 
b/traffic_ops/traffic_ops_golang/routes.go
index d981111..6eac8bc 100644
--- a/traffic_ops/traffic_ops_golang/routes.go
+++ b/traffic_ops/traffic_ops_golang/routes.go
@@ -195,7 +195,6 @@ func Routes(d ServerData) ([]Route, http.Handler, error) {
                //ProfileParameters
                {1.3, http.MethodGet, `profileparameters/?(\.json)?$`, 
api.ReadHandler(profileparameter.GetRefType(), d.DB), auth.PrivLevelReadOnly, 
Authenticated, nil},
                {1.3, http.MethodGet, `profileparameters/{id}$`, 
api.ReadHandler(profileparameter.GetRefType(), d.DB), auth.PrivLevelReadOnly, 
Authenticated, nil},
-               {1.3, http.MethodPut, `profileparameters/{id}$`, 
api.UpdateHandler(profileparameter.GetRefType(), d.DB), 
auth.PrivLevelOperations, Authenticated, nil},
                {1.3, http.MethodPost, `profileparameters/?$`, 
api.CreateHandler(profileparameter.GetRefType(), d.DB), 
auth.PrivLevelOperations, Authenticated, nil},
                {1.3, http.MethodDelete, `profilesparameters/{id}$`, 
api.DeleteHandler(profileparameter.GetRefType(), d.DB), 
auth.PrivLevelOperations, Authenticated, nil},
 

-- 
To stop receiving notification emails like this one, please contact
mitchell...@apache.org.

Reply via email to