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

Update the Logic to handle the post request for userLocationEventSubscription...

Update the Logic to handle the post request for userLocationEventSubscription and userLocationPeriodicsubscription without array
parent 4892dc30
Loading
Loading
Loading
Loading
+117 −129
Original line number Diff line number Diff line
@@ -2883,8 +2883,8 @@ func userSubGET(w http.ResponseWriter, r *http.Request) {
}

func userSubPOST(w http.ResponseWriter, r *http.Request) {
	// Decode the request body into a slice of maps
	var requestBody []map[string]interface{}

	var requestBody map[string]interface{}

	decoder := json.NewDecoder(r.Body)
	if err := decoder.Decode(&requestBody); err != nil {
@@ -2893,16 +2893,14 @@ func userSubPOST(w http.ResponseWriter, r *http.Request) {
		return
	}

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

	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 {
@@ -2919,10 +2917,9 @@ func userSubPOST(w http.ResponseWriter, r *http.Request) {
		return
	}
}
func handleUserLocationEventSubscription(w http.ResponseWriter, requestBody []map[string]interface{}) {
	// Iterate over each item in the request body
	for _, body := range requestBody {
		if eventSubscription, ok := body["userLocationEventSubscription"]; ok {
func handleUserLocationEventSubscription(w http.ResponseWriter, requestBody map[string]interface{}) {

	if eventSubscription, ok := requestBody["userLocationEventSubscription"]; ok {
		// Convert the event subscription to a map
		eventSubscriptionMap := eventSubscription.(map[string]interface{})

@@ -2987,14 +2984,9 @@ func handleUserLocationEventSubscription(w http.ResponseWriter, requestBody []ma
	}
}

	// If no event-based subscription found in the request body
	errHandlerProblemDetails(w, "No valid event-based subscription found in the request body", http.StatusBadRequest)
}
func handleUserLocationPeriodicSubscription(w http.ResponseWriter, requestBody map[string]interface{}) {

func handleUserLocationPeriodicSubscription(w http.ResponseWriter, requestBody []map[string]interface{}) {
	// Iterate over each item in the request body
	for _, body := range requestBody {
		if periodicSubscription, ok := body["userLocationPeriodicSubscription"]; ok {
	if periodicSubscription, ok := requestBody["userLocationPeriodicSubscription"]; ok {
		// Convert the periodic subscription to a map
		periodicSubscriptionMap := periodicSubscription.(map[string]interface{})

@@ -3056,10 +3048,6 @@ func handleUserLocationPeriodicSubscription(w http.ResponseWriter, requestBody [
	}
}

	// If no periodic-based subscription found in the request body
	errHandlerProblemDetails(w, "No valid periodic-based subscription found in the request body", http.StatusBadRequest)
}

func zoneSubPUT(w http.ResponseWriter, r *http.Request) {
	var requestBody []map[string]interface{}
	vars := mux.Vars(r)