Loading go-apps/meep-loc-serv/server/loc-serv.go +68 −25 Original line number Diff line number Diff line Loading @@ -1742,30 +1742,8 @@ func apGet(w http.ResponseWriter, r *http.Request) { var userData ApUserData vars := mux.Vars(r) // Retrieve query parameters u, _ := url.Parse(r.URL.String()) log.Info("url: ", u.RequestURI()) q := u.Query() userData.queryInterestRealm = q.Get("interestRealm") validQueryParams := []string{"interestRealm"} //look for all query parameters to reject if any invalid ones found := false for queryParam := range q { found = false for _, validQueryParam := range validQueryParams { if queryParam == validQueryParam { found = true break } } if !found { log.Error("Query param not valid: ", queryParam) w.WriteHeader(http.StatusBadRequest) return } } // Parse query parameters accessPointIDs := r.URL.Query()["accessPointId"] // Get user list from DB var response InlineAccessPointList Loading @@ -1775,7 +1753,7 @@ func apGet(w http.ResponseWriter, r *http.Request) { response.AccessPointList = &apList userData.apList = &apList //make sure the zone exists first // Make sure the zone exists first jsonZoneInfo, _ := rc.JSONGetEntry(baseKey+typeZone+":"+vars["zoneId"], ".") if jsonZoneInfo == "" { w.WriteHeader(http.StatusNotFound) Loading @@ -1790,6 +1768,23 @@ func apGet(w http.ResponseWriter, r *http.Request) { return } // Filter access point list if accessPointId parameters are provided if len(accessPointIDs) > 0 { filteredAccessPointList := AccessPointList{} for _, accessPointID := range accessPointIDs { for _, accessPoint := range apList.AccessPoint { if accessPoint.AccessPointId == accessPointID { filteredAccessPointList.AccessPoint = append(filteredAccessPointList.AccessPoint, accessPoint) break // Assuming accessPoint IDs are unique, stop after finding the match } } } response.AccessPointList = &filteredAccessPointList } // Set the resourceURL to include base URL with or without parameters response.AccessPointList.ResourceURL = buildResourceURL_(hostUrl.String(), basePath, "queries/zones/"+vars["zoneId"]+"/accessPoints", accessPointIDs) // Send response jsonResponse, err := json.Marshal(response) if err != nil { Loading @@ -1801,6 +1796,54 @@ func apGet(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, string(jsonResponse)) } // Function to build resource URL with or without parameters func buildResourceURL_(baseURL, basePath, endpoint string, parameters []string) string { url := baseURL + basePath + endpoint if len(parameters) > 0 { url += "?" + strings.Join(parameters, "&") } return url } // func apGet(w http.ResponseWriter, r *http.Request) { // w.Header().Set("Content-Type", "application/json; charset=UTF-8") // var userData ApUserData // vars := mux.Vars(r) // // Get user list from DB // var response InlineAccessPointList // var apList AccessPointList // apList.ZoneId = vars["zoneId"] // apList.ResourceURL = hostUrl.String() + basePath + "queries/zones/" + vars["zoneId"] + "/accessPoints" // response.AccessPointList = &apList // userData.apList = &apList // //make sure the zone exists first // jsonZoneInfo, _ := rc.JSONGetEntry(baseKey+typeZone+":"+vars["zoneId"], ".") // if jsonZoneInfo == "" { // w.WriteHeader(http.StatusNotFound) // return // } // keyName := baseKey + typeZone + ":" + vars["zoneId"] + ":*" // err := rc.ForEachJSONEntry(keyName, populateApList, &userData) // if err != nil { // log.Error(err.Error()) // errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) // return // } // // Send response // jsonResponse, err := json.Marshal(response) // if err != nil { // log.Error(err.Error()) // errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) // return // } // w.WriteHeader(http.StatusOK) // fmt.Fprint(w, string(jsonResponse)) // } func apByIdGet(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json; charset=UTF-8") vars := mux.Vars(r) Loading Loading
go-apps/meep-loc-serv/server/loc-serv.go +68 −25 Original line number Diff line number Diff line Loading @@ -1742,30 +1742,8 @@ func apGet(w http.ResponseWriter, r *http.Request) { var userData ApUserData vars := mux.Vars(r) // Retrieve query parameters u, _ := url.Parse(r.URL.String()) log.Info("url: ", u.RequestURI()) q := u.Query() userData.queryInterestRealm = q.Get("interestRealm") validQueryParams := []string{"interestRealm"} //look for all query parameters to reject if any invalid ones found := false for queryParam := range q { found = false for _, validQueryParam := range validQueryParams { if queryParam == validQueryParam { found = true break } } if !found { log.Error("Query param not valid: ", queryParam) w.WriteHeader(http.StatusBadRequest) return } } // Parse query parameters accessPointIDs := r.URL.Query()["accessPointId"] // Get user list from DB var response InlineAccessPointList Loading @@ -1775,7 +1753,7 @@ func apGet(w http.ResponseWriter, r *http.Request) { response.AccessPointList = &apList userData.apList = &apList //make sure the zone exists first // Make sure the zone exists first jsonZoneInfo, _ := rc.JSONGetEntry(baseKey+typeZone+":"+vars["zoneId"], ".") if jsonZoneInfo == "" { w.WriteHeader(http.StatusNotFound) Loading @@ -1790,6 +1768,23 @@ func apGet(w http.ResponseWriter, r *http.Request) { return } // Filter access point list if accessPointId parameters are provided if len(accessPointIDs) > 0 { filteredAccessPointList := AccessPointList{} for _, accessPointID := range accessPointIDs { for _, accessPoint := range apList.AccessPoint { if accessPoint.AccessPointId == accessPointID { filteredAccessPointList.AccessPoint = append(filteredAccessPointList.AccessPoint, accessPoint) break // Assuming accessPoint IDs are unique, stop after finding the match } } } response.AccessPointList = &filteredAccessPointList } // Set the resourceURL to include base URL with or without parameters response.AccessPointList.ResourceURL = buildResourceURL_(hostUrl.String(), basePath, "queries/zones/"+vars["zoneId"]+"/accessPoints", accessPointIDs) // Send response jsonResponse, err := json.Marshal(response) if err != nil { Loading @@ -1801,6 +1796,54 @@ func apGet(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, string(jsonResponse)) } // Function to build resource URL with or without parameters func buildResourceURL_(baseURL, basePath, endpoint string, parameters []string) string { url := baseURL + basePath + endpoint if len(parameters) > 0 { url += "?" + strings.Join(parameters, "&") } return url } // func apGet(w http.ResponseWriter, r *http.Request) { // w.Header().Set("Content-Type", "application/json; charset=UTF-8") // var userData ApUserData // vars := mux.Vars(r) // // Get user list from DB // var response InlineAccessPointList // var apList AccessPointList // apList.ZoneId = vars["zoneId"] // apList.ResourceURL = hostUrl.String() + basePath + "queries/zones/" + vars["zoneId"] + "/accessPoints" // response.AccessPointList = &apList // userData.apList = &apList // //make sure the zone exists first // jsonZoneInfo, _ := rc.JSONGetEntry(baseKey+typeZone+":"+vars["zoneId"], ".") // if jsonZoneInfo == "" { // w.WriteHeader(http.StatusNotFound) // return // } // keyName := baseKey + typeZone + ":" + vars["zoneId"] + ":*" // err := rc.ForEachJSONEntry(keyName, populateApList, &userData) // if err != nil { // log.Error(err.Error()) // errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) // return // } // // Send response // jsonResponse, err := json.Marshal(response) // if err != nil { // log.Error(err.Error()) // errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) // return // } // w.WriteHeader(http.StatusOK) // fmt.Fprint(w, string(jsonResponse)) // } func apByIdGet(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json; charset=UTF-8") vars := mux.Vars(r) Loading