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

Update the logic to handle the PUT request for userLocationEvenSubscription...

Update the logic to handle the PUT request for userLocationEvenSubscription and userLocationPeriodicSubscription without array in request body
parent ed9122ca
Loading
Loading
Loading
Loading
+162 −166
Original line number Diff line number Diff line
@@ -2893,8 +2893,8 @@ func userSubPOST(w http.ResponseWriter, r *http.Request) {
		return
	}

	var hasEventSubscription bool
	var hasPeriodicSubscription bool
	hasEventSubscription := false
	hasPeriodicSubscription := false

	if _, ok := requestBody["userLocationEventSubscription"]; ok {
		hasEventSubscription = true
@@ -3085,7 +3085,7 @@ func zoneSubPUT(w http.ResponseWriter, r *http.Request) {
	}
}
func userSubPUT(w http.ResponseWriter, r *http.Request) {
	var requestBody []map[string]interface{}
	var requestBody map[string]interface{}
	vars := mux.Vars(r)
	decoder := json.NewDecoder(r.Body)
	if err := decoder.Decode(&requestBody); err != nil {
@@ -3097,13 +3097,11 @@ func userSubPUT(w http.ResponseWriter, r *http.Request) {
	hasEventSubscription := false
	hasPeriodicSubscription := false

	for _, body := range requestBody {
		if _, ok := body["userLocationEventSubscription"]; ok {
	if _, ok := requestBody["userLocationEventSubscription"]; ok {
		hasEventSubscription = true
		} else if _, ok := body["userLocationPeriodicSubscription"]; ok {
	} else if _, ok := requestBody["userLocationPeriodicSubscription"]; ok {
		hasPeriodicSubscription = true
	}
	}

	// Check if both types of subscriptions are present
	if hasEventSubscription && hasPeriodicSubscription {
@@ -3305,9 +3303,9 @@ func handlezoneStatusSubscriptionPut(w http.ResponseWriter, requestBody []map[st
		}
	}
}
func handleUserLocationEventSubscriptionPut(w http.ResponseWriter, requestBody []map[string]interface{}, subscriptionID string) {
	for _, body := range requestBody {
		if eventSubscription, ok := body["userLocationEventSubscription"]; ok {
func handleUserLocationEventSubscriptionPut(w http.ResponseWriter, requestBody map[string]interface{}, subscriptionID string) {

	if eventSubscription, ok := requestBody["userLocationEventSubscription"]; ok {
		// Convert the event subscription to a map
		eventSubscriptionMap := eventSubscription.(map[string]interface{})
		// Convert _links to Links
@@ -3394,11 +3392,10 @@ func handleUserLocationEventSubscriptionPut(w http.ResponseWriter, requestBody [

	}
}
}

func handleUserLocationPeriodicSubscriptionPut(w http.ResponseWriter, requestBody []map[string]interface{}, subscriptionID string) {
	for _, body := range requestBody {
		if periodicSubscription, ok := body["userLocationPeriodicSubscription"]; ok {
func handleUserLocationPeriodicSubscriptionPut(w http.ResponseWriter, requestBody map[string]interface{}, subscriptionID string) {

	if periodicSubscription, ok := requestBody["userLocationPeriodicSubscription"]; ok {
		// Convert the periodic subscription to a map
		periodicSubscriptionMap := periodicSubscription.(map[string]interface{})
		// Decode the periodic subscription map into a struct
@@ -3484,7 +3481,6 @@ func handleUserLocationPeriodicSubscriptionPut(w http.ResponseWriter, requestBod

	}
}
}

func populateUserSubList1(data []byte, address string, subscriptions *[]Subscription) error {
	var userInfo UserLocationEventSubscription