rimashah25 commented on code in PR #7079:
URL: https://github.com/apache/trafficcontrol/pull/7079#discussion_r1006427072


##########
traffic_ops/traffic_ops_golang/server/servers_server_capability.go:
##########
@@ -453,77 +443,185 @@ func AssignMultipleServerCapabilities(w 
http.ResponseWriter, r *http.Request) {
        }
        defer inf.Close()
 
-       var msc tc.MultipleServerCapabilities
-       if err := json.NewDecoder(r.Body).Decode(&msc); err != nil {
-               api.HandleErr(w, r, tx, http.StatusBadRequest, err, nil)
+       var mssc tc.MultipleServersCapabilities
+       if err := json.NewDecoder(r.Body).Decode(&mssc); err != nil {
+               api.HandleErr(w, r, tx, http.StatusBadRequest, 
fmt.Errorf("error decoding POST request body into MultipleServersCapabilities 
struct %w", err), nil)
                return
        }
 
-       // Check existence prior to checking type
-       _, exists, err := dbhelpers.GetServerNameFromID(tx, int64(msc.ServerID))
-       if err != nil {
-               api.HandleErr(w, r, tx, http.StatusInternalServerError, nil, 
err)
-       }
-       if !exists {
-               userErr := fmt.Errorf("server %d does not exist", msc.ServerID)
-               api.HandleErr(w, r, tx, http.StatusNotFound, userErr, nil)
-               return
+       if len(mssc.ServerIDs) >= 1 {
+               errCode, userErr, sysErr = checkExistingServer(tx, 
mssc.ServerIDs, inf.User.UserName)
+               if userErr != nil || sysErr != nil {
+                       api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+                       return
+               }
        }
 
        // Ensure type is correct
-       correctType := true
-       if err := tx.QueryRow(scCheckServerTypeQuery(), 
msc.ServerID).Scan(&correctType); err != nil {
-               api.HandleErr(w, r, tx, http.StatusInternalServerError, nil, 
fmt.Errorf("checking server type: %w", err))
+       errCode, userErr, sysErr = checkServerType(tx, mssc.ServerIDs)
+       if userErr != nil || sysErr != nil {
+               api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
                return
        }
-       if !correctType {
-               userErr := fmt.Errorf("server %d has an incorrect server type. 
Server capabilities can only be assigned to EDGE or MID servers", msc.ServerID)
-               api.HandleErr(w, r, tx, http.StatusBadRequest, userErr, nil)
-               return
+
+       // Insert rows in DB
+       sid := make([]int64, len(mssc.ServerCapabilities))
+       scs := make([]string, len(mssc.ServerIDs))
+       if len(mssc.ServerIDs) == 1 {

Review Comment:
   we can replace it with `PageType` but it is not necessary. 



-- 
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.

To unsubscribe, e-mail: issues-unsubscr...@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to