Commit 77bda78b authored by Mubeena Ishaq's avatar Mubeena Ishaq
Browse files

add individual subscription GET method in meep-vis

parent 6f6e40e4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ func IndividualSubscriptionDELETE(w http.ResponseWriter, r *http.Request) {
}

func IndividualSubscriptionGET(w http.ResponseWriter, r *http.Request) {
	notImplemented(w, r)
	individualSubscriptionGET(w, r)
}

func IndividualSubscriptionPUT(w http.ResponseWriter, r *http.Request) {
+31 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import (
	scc "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-sandbox-ctrl-client"
	smc "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-service-mgmt-client"
	sm "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-subscriptions"
	"github.com/gorilla/mux"
)

const moduleName = "meep-vis"
@@ -991,6 +992,36 @@ func subscriptionsPost(w http.ResponseWriter, r *http.Request) {
	fmt.Fprint(w, jsonResponse)
}

func individualSubscriptionGET(w http.ResponseWriter, r *http.Request) {
	log.Info("subGet")

	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	vars := mux.Vars(r)
	subsIdStr := vars["subsId"]

	keyName := baseKey + "subscriptions:" + subsIdStr

	// Find subscription entry in Redis DB
	v2xMsgJson, err := rc.JSONGetEntry(keyName, ".")
	if v2xMsgJson == "" {
		w.WriteHeader(http.StatusNotFound)
		return
	}

	// Prepare & send v2xMsgSubscription as a response
	var v2xMsgSubResp V2xMsgSubscription
	err = json.Unmarshal([]byte(v2xMsgJson), &v2xMsgSubResp)
	if err != nil {
		log.Error(err.Error())
		errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError)
		return
	}
	jsonResponse := convertV2xMsgSubscriptionToJson(&v2xMsgSubResp)

	w.WriteHeader(http.StatusOK)
	fmt.Fprint(w, jsonResponse)
}

func registerV2xSub(v2xMsgSubscription *V2xMsgSubscription, subId string) {
	subsId, _ := strconv.Atoi(subId)
	mutex.Lock()