Commit cfa7f10e authored by Ikram Haq's avatar Ikram Haq
Browse files

Implement logic to handle multiple zoneId's

parent a841a92d
Loading
Loading
Loading
Loading
+21 −7
Original line number Diff line number Diff line
@@ -1899,7 +1899,7 @@ func zonesGet(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")

	// Parse query parameters
	zoneID := r.URL.Query().Get("zoneId")
	zoneIDs := r.URL.Query()["zoneId"]

	var response InlineZoneList
	var zoneList ZoneList
@@ -1914,18 +1914,23 @@ func zonesGet(w http.ResponseWriter, r *http.Request) {
		return
	}

	// Filter zone list if zoneId parameter is provided
	if zoneID != "" {
	// Filter zone list if zoneId parameters are provided
	if len(zoneIDs) > 0 {
		filteredZoneList := ZoneList{}
		for _, zoneID := range zoneIDs {
			for _, zone := range zoneList.Zone {
				if zone.ZoneId == zoneID {
					filteredZoneList.Zone = append(filteredZoneList.Zone, zone)
					break // Assuming zone IDs are unique, stop after finding the match
				}
			}
		}
		response.ZoneList = &filteredZoneList
	}

	// Set the resourceURL to include base URL with or without parameters
	response.ZoneList.ResourceURL = buildResourceURL(hostUrl.String(), basePath, zoneIDs)

	jsonResponse, err := json.Marshal(response)
	if err != nil {
		log.Error(err.Error())
@@ -1936,6 +1941,15 @@ func zonesGet(w http.ResponseWriter, r *http.Request) {
	fmt.Fprint(w, string(jsonResponse))
}

// Function to build resource URL with or without parameters
func buildResourceURL(baseURL, basePath string, zoneIDs []string) string {
	url := baseURL + basePath + "queries/zones"
	if len(zoneIDs) > 0 {
		url += "?zoneId=" + strings.Join(zoneIDs, "&zoneId=")
	}
	return url
}

func zonesByIdGet(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	vars := mux.Vars(r)