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

Implement Method to GET the individual zones subscriptions

parent 4eb359be
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -164,6 +164,9 @@ func ZoneSubListGET(w http.ResponseWriter, r *http.Request) {
func ZoneSubPOST(w http.ResponseWriter, r *http.Request) {
	zoneSubPOST(w, r)
}
func ZoneSubGET(w http.ResponseWriter, r *http.Request) {
	zoneSubGET(w, r)
}

func ZonalTrafficSubPOST(w http.ResponseWriter, r *http.Request) {
	zonalTrafficSubPost(w, r)
+40 −0
Original line number Diff line number Diff line
@@ -3785,6 +3785,46 @@ func zonalTrafficSubGet(w http.ResponseWriter, r *http.Request) {
	fmt.Fprint(w, string(jsonResponse))
}

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

	jsonZonalTrafficSub, _ := rc.JSONGetEntry(baseKey+typeZonalSubscription+":"+vars["subscriptionId"], ".")
	if jsonZonalTrafficSub != "" {
		var jsonZoneSub ZoneLocationEventSubscription
		if err := json.Unmarshal([]byte(jsonZonalTrafficSub), &jsonZoneSub); err != nil {
			log.Error(err.Error())
			errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError)
			return
		}
		response = InlineZoneLocationEventSubscription{ZoneLocationEventSubscription: &jsonZoneSub}
	} else {
		var statusSub ZoneStatusSubscription
		jsonZoneStatusSub, _ := rc.JSONGetEntry(baseKey+typeZoneStatusSubscription+":"+vars["subscriptionId"], ".")
		if jsonZoneStatusSub == "" {
			w.WriteHeader(http.StatusNotFound)
			return
		}
		if err := json.Unmarshal([]byte(jsonZoneStatusSub), &statusSub); err != nil {
			log.Error(err.Error())
			errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError)
			return
		}
		response = InlineZoneStatusSubscription{ZoneStatusSubscription: &statusSub}
	}
	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 zoneSubPOST(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	var response InlineZoneStatusSubscription
+7 −0
Original line number Diff line number Diff line
@@ -330,6 +330,13 @@ var routes = Routes{
		ZoneSubPOST,
	},

	Route{
		"ZoneSubGET",
		strings.ToUpper("Post"),
		"/location/v2/subscriptions/zones/{subscriptionId}",
		ZoneSubGET,
	},

	Route{
		"ZonalTrafficSubPOST",
		strings.ToUpper("Post"),