Loading go-apps/meep-loc-serv/server/loc-serv.go +103 −24 Original line number Diff line number Diff line Loading @@ -4075,40 +4075,67 @@ func zonalTrafficSubDelete(w http.ResponseWriter, r *http.Request) { deregisterZonal(vars["subscriptionId"]) w.WriteHeader(http.StatusNoContent) } func zoneSubListGET(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json; charset=UTF-8") // Check if the 'subscription_type' and 'event' query parameters exist and get their values queryParams := r.URL.Query() subscriptionType := queryParams.Get("subscription_type") zoneId := queryParams.Get("zoneId") var response InlineNotificationSubscriptionList var zonalSubList NotificationSubscriptionList zonalSubList.ResourceURL = hostUrl.String() + basePath + "subscriptions/zones" response.NotificationSubscriptionList = &zonalSubList var err error switch subscriptionType { case "event": keyName := baseKey + typeZonalSubscription + "*" err := rc.ForEachJSONEntry(keyName, populateZonalTrafficList, &zonalSubList) if err != nil { log.Error(err.Error()) errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) return // If event parameter is provided, filter subscriptions by event if zoneId != "" { keyName += ":" + zoneId } jsonResponse, err := json.Marshal(response) if err != nil { log.Error(err.Error()) errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) err = rc.ForEachJSONEntry(keyName, populateZonalTrafficList, &zonalSubList) case "status": keyName := baseKey + typeZoneStatusSubscription + "*" // If event parameter is provided, filter subscriptions by event if zoneId != "" { keyName += ":" + zoneId } err = rc.ForEachJSONEntry(keyName, populateZoneStatusList, &zonalSubList) default: // If no subscription_type is provided, return both responses var userSubListZoneEvent NotificationSubscriptionList keyNameEventZone := baseKey + typeZonalSubscription + "*" // If event parameter is provided, filter subscriptions by event errEvent := rc.ForEachJSONEntry(keyNameEventZone, populateZonalTrafficList, &userSubListZoneEvent) if errEvent != nil { log.Error(errEvent.Error()) errHandlerProblemDetails(w, errEvent.Error(), http.StatusInternalServerError) return } w.WriteHeader(http.StatusOK) fmt.Fprint(w, string(jsonResponse)) var userSubListStatus NotificationSubscriptionList keyNameEventZone = baseKey + typeZoneStatusSubscription + "*" // If event parameter is provided, filter subscriptions by event errStatus := rc.ForEachJSONEntry(keyNameEventZone, populateZoneStatusList, &userSubListStatus) if errStatus != nil { log.Error(errStatus.Error()) errHandlerProblemDetails(w, errStatus.Error(), http.StatusInternalServerError) return } func zonalTrafficSubListGet(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json; charset=UTF-8") var response InlineNotificationSubscriptionList var zonalTrafficSubList NotificationSubscriptionList zonalTrafficSubList.ResourceURL = hostUrl.String() + basePath + "subscriptions/zonalTraffic" response.NotificationSubscriptionList = &zonalTrafficSubList // Merge both lists zonalSubList.ZoneLocationEventSubscription = append(zonalSubList.ZoneLocationEventSubscription, userSubListZoneEvent.ZoneLocationEventSubscription...) zonalSubList.ZoneStatusSubscription = append(zonalSubList.ZoneStatusSubscription, userSubListStatus.ZoneStatusSubscription...) // No error since we're combining the lists err = nil } keyName := baseKey + typeZonalSubscription + "*" err := rc.ForEachJSONEntry(keyName, populateZonalTrafficList, &zonalTrafficSubList) if err != nil { log.Error(err.Error()) errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) Loading @@ -4121,10 +4148,62 @@ func zonalTrafficSubListGet(w http.ResponseWriter, r *http.Request) { errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) return } w.WriteHeader(http.StatusOK) fmt.Fprint(w, string(jsonResponse)) } // func zoneSubListGET(w http.ResponseWriter, r *http.Request) { // w.Header().Set("Content-Type", "application/json; charset=UTF-8") // var response InlineNotificationSubscriptionList // var zonalSubList NotificationSubscriptionList // zonalSubList.ResourceURL = hostUrl.String() + basePath + "subscriptions/zones" // response.NotificationSubscriptionList = &zonalSubList // keyName := baseKey + typeZonalSubscription + "*" // err := rc.ForEachJSONEntry(keyName, populateZonalTrafficList, &zonalSubList) // if err != nil { // log.Error(err.Error()) // errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) // return // } // 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 zonalTrafficSubListGet(w http.ResponseWriter, r *http.Request) { // w.Header().Set("Content-Type", "application/json; charset=UTF-8") // var response InlineNotificationSubscriptionList // var zonalTrafficSubList NotificationSubscriptionList // zonalTrafficSubList.ResourceURL = hostUrl.String() + basePath + "subscriptions/zonalTraffic" // response.NotificationSubscriptionList = &zonalTrafficSubList // keyName := baseKey + typeZonalSubscription + "*" // err := rc.ForEachJSONEntry(keyName, populateZonalTrafficList, &zonalTrafficSubList) // if err != nil { // log.Error(err.Error()) // errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) // return // } // 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 zonalTrafficSubGet(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 +103 −24 Original line number Diff line number Diff line Loading @@ -4075,40 +4075,67 @@ func zonalTrafficSubDelete(w http.ResponseWriter, r *http.Request) { deregisterZonal(vars["subscriptionId"]) w.WriteHeader(http.StatusNoContent) } func zoneSubListGET(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json; charset=UTF-8") // Check if the 'subscription_type' and 'event' query parameters exist and get their values queryParams := r.URL.Query() subscriptionType := queryParams.Get("subscription_type") zoneId := queryParams.Get("zoneId") var response InlineNotificationSubscriptionList var zonalSubList NotificationSubscriptionList zonalSubList.ResourceURL = hostUrl.String() + basePath + "subscriptions/zones" response.NotificationSubscriptionList = &zonalSubList var err error switch subscriptionType { case "event": keyName := baseKey + typeZonalSubscription + "*" err := rc.ForEachJSONEntry(keyName, populateZonalTrafficList, &zonalSubList) if err != nil { log.Error(err.Error()) errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) return // If event parameter is provided, filter subscriptions by event if zoneId != "" { keyName += ":" + zoneId } jsonResponse, err := json.Marshal(response) if err != nil { log.Error(err.Error()) errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) err = rc.ForEachJSONEntry(keyName, populateZonalTrafficList, &zonalSubList) case "status": keyName := baseKey + typeZoneStatusSubscription + "*" // If event parameter is provided, filter subscriptions by event if zoneId != "" { keyName += ":" + zoneId } err = rc.ForEachJSONEntry(keyName, populateZoneStatusList, &zonalSubList) default: // If no subscription_type is provided, return both responses var userSubListZoneEvent NotificationSubscriptionList keyNameEventZone := baseKey + typeZonalSubscription + "*" // If event parameter is provided, filter subscriptions by event errEvent := rc.ForEachJSONEntry(keyNameEventZone, populateZonalTrafficList, &userSubListZoneEvent) if errEvent != nil { log.Error(errEvent.Error()) errHandlerProblemDetails(w, errEvent.Error(), http.StatusInternalServerError) return } w.WriteHeader(http.StatusOK) fmt.Fprint(w, string(jsonResponse)) var userSubListStatus NotificationSubscriptionList keyNameEventZone = baseKey + typeZoneStatusSubscription + "*" // If event parameter is provided, filter subscriptions by event errStatus := rc.ForEachJSONEntry(keyNameEventZone, populateZoneStatusList, &userSubListStatus) if errStatus != nil { log.Error(errStatus.Error()) errHandlerProblemDetails(w, errStatus.Error(), http.StatusInternalServerError) return } func zonalTrafficSubListGet(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json; charset=UTF-8") var response InlineNotificationSubscriptionList var zonalTrafficSubList NotificationSubscriptionList zonalTrafficSubList.ResourceURL = hostUrl.String() + basePath + "subscriptions/zonalTraffic" response.NotificationSubscriptionList = &zonalTrafficSubList // Merge both lists zonalSubList.ZoneLocationEventSubscription = append(zonalSubList.ZoneLocationEventSubscription, userSubListZoneEvent.ZoneLocationEventSubscription...) zonalSubList.ZoneStatusSubscription = append(zonalSubList.ZoneStatusSubscription, userSubListStatus.ZoneStatusSubscription...) // No error since we're combining the lists err = nil } keyName := baseKey + typeZonalSubscription + "*" err := rc.ForEachJSONEntry(keyName, populateZonalTrafficList, &zonalTrafficSubList) if err != nil { log.Error(err.Error()) errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) Loading @@ -4121,10 +4148,62 @@ func zonalTrafficSubListGet(w http.ResponseWriter, r *http.Request) { errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) return } w.WriteHeader(http.StatusOK) fmt.Fprint(w, string(jsonResponse)) } // func zoneSubListGET(w http.ResponseWriter, r *http.Request) { // w.Header().Set("Content-Type", "application/json; charset=UTF-8") // var response InlineNotificationSubscriptionList // var zonalSubList NotificationSubscriptionList // zonalSubList.ResourceURL = hostUrl.String() + basePath + "subscriptions/zones" // response.NotificationSubscriptionList = &zonalSubList // keyName := baseKey + typeZonalSubscription + "*" // err := rc.ForEachJSONEntry(keyName, populateZonalTrafficList, &zonalSubList) // if err != nil { // log.Error(err.Error()) // errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) // return // } // 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 zonalTrafficSubListGet(w http.ResponseWriter, r *http.Request) { // w.Header().Set("Content-Type", "application/json; charset=UTF-8") // var response InlineNotificationSubscriptionList // var zonalTrafficSubList NotificationSubscriptionList // zonalTrafficSubList.ResourceURL = hostUrl.String() + basePath + "subscriptions/zonalTraffic" // response.NotificationSubscriptionList = &zonalTrafficSubList // keyName := baseKey + typeZonalSubscription + "*" // err := rc.ForEachJSONEntry(keyName, populateZonalTrafficList, &zonalTrafficSubList) // if err != nil { // log.Error(err.Error()) // errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) // return // } // 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 zonalTrafficSubGet(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json; charset=UTF-8") vars := mux.Vars(r) Loading