Commit 30852bd9 authored by Mubeena Ishaq's avatar Mubeena Ishaq
Browse files

add individual subscription DELETE method in meep-vis

parent 6585e22e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ func SubPOST(w http.ResponseWriter, r *http.Request) {
}

func IndividualSubscriptionDELETE(w http.ResponseWriter, r *http.Request) {
	notImplemented(w, r)
	individualSubscriptionDelete(w, r)
}

func IndividualSubscriptionGET(w http.ResponseWriter, r *http.Request) {
+34 −12
Original line number Diff line number Diff line
@@ -1301,18 +1301,6 @@ func individualSubscriptionPut(w http.ResponseWriter, r *http.Request) {
		return
	}

	if subscriptionCommon.FilterCriteria == nil {
		log.Error("FilterCriteria should not be null for this subscription type")
		errHandlerProblemDetails(w, "Mandatory attribute FilterCriteria is missing for this subscription type", http.StatusBadRequest)
		return
	}

	if subscriptionCommon.CallbackReference == "" && subscriptionCommon.WebsockNotifConfig.WebsocketUri == "" {
		log.Error("At least one of CallbackReference and WebsockNotifConfig parameters should be present")
		errHandlerProblemDetails(w, "At least one of CallbackReference and WebsockNotifConfig parameters should be present.", http.StatusBadRequest)
		return
	}

	link := subscriptionCommon.Links
	if link == nil || link.Self == nil {
		log.Error("Mandatory Link parameter not present")
@@ -1348,6 +1336,18 @@ func individualSubscriptionPut(w http.ResponseWriter, r *http.Request) {
			return
		}

		if subscriptionCommon.FilterCriteria == nil {
			log.Error("FilterCriteria should not be null for this subscription type")
			errHandlerProblemDetails(w, "Mandatory attribute FilterCriteria is missing for this subscription type", http.StatusBadRequest)
			return
		}

		if subscriptionCommon.CallbackReference == "" && subscriptionCommon.WebsockNotifConfig.WebsocketUri == "" {
			log.Error("At least one of CallbackReference and WebsockNotifConfig parameters should be present")
			errHandlerProblemDetails(w, "At least one of CallbackReference and WebsockNotifConfig parameters should be present.", http.StatusBadRequest)
			return
		}

		for _, msgTypeString := range subscription.FilterCriteria.MsgType {
			msgTypeInt, err := strconv.Atoi(msgTypeString)
			if msgTypeInt < 1 || msgTypeInt > 13 {
@@ -1385,3 +1385,25 @@ func individualSubscriptionPut(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(http.StatusNotFound)
	}
}

func individualSubscriptionDelete(w http.ResponseWriter, r *http.Request) {
	log.Info("individualSubDel")

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

	jsonRespDB, _ := rc.JSONGetEntry(baseKey+"subscriptions:"+subIdParamStr, ".")
	if jsonRespDB == "" {
		w.WriteHeader(http.StatusNotFound)
		return
	}

	err := delSubscription(baseKey+"subscriptions", subIdParamStr, false)
	if err != nil {
		errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError)
		return
	}

	w.WriteHeader(http.StatusNoContent)
}