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

Fix data model issue in UserAreaNotification and UserAreaSubscription

parent 159bba76
Loading
Loading
Loading
Loading
+21 −16
Original line number Diff line number Diff line
@@ -1238,7 +1238,8 @@ func checkNotificationAreaCircle(addressToCheck string) {
				}
				subsIdStr := strconv.Itoa(subsId)
				var areaCircleNotif UserAreaNotification
				areaCircleNotif.UserLocationEvent = areaCircleCheck.Subscription.LocationEventCriteria
				//areaCircleNotif.UserLocationEvent = areaCircleCheck.Subscription.LocationEventCriteria
				areaCircleNotif.UserLocationEvent = &event
				areaCircleNotif.Links = &SubscriptionLinks{
					Subscription: areaCircleCheck.Subscription.Links.Self,
				}
@@ -3250,17 +3251,19 @@ func areaSubPOST(w http.ResponseWriter, r *http.Request) {
		errHandlerProblemDetails(w, "Mandatory Radius parameter not present", http.StatusBadRequest)
		return
	}
	if len(areaCircleSub.LocationEventCriteria) == 0 {
		log.Error("LocationEventCriteria not present")
		errHandlerProblemDetails(w, "LocationEventCriteria not present", http.StatusBadRequest)
		return
	}

	if areaCircleSub.SubscriptionType != "UserAreaSubscription" {
		log.Error("Mandatory SubscriptionType parameter not present or invalid")
		errHandlerProblemDetails(w, "Mandatory SubscriptionType parameter not present or invalid", http.StatusBadRequest)
		return
	}
	// Check if EnteringLeavingCriteria values are valid
	
	if len(areaCircleSub.LocationEventCriteria) == 0 && areaCircleSub.LocationEventCriteria == nil {
		locationEventType := []LocationEventType{"ENTERING_AREA_EVENT", "LEAVING_AREA_EVENT"}
		//locationEventType := {ENTERING_AREA_EVENT, LEAVING_AREA_EVENT}
		areaCircleSub.LocationEventCriteria = locationEventType
	} else {
		for _, criteria := range areaCircleSub.LocationEventCriteria {
			if criteria != ENTERING_AREA_EVENT && criteria != LEAVING_AREA_EVENT {
				log.Error("Invalid EnteringLeavingCriteria parameter value")
@@ -3268,6 +3271,8 @@ func areaSubPOST(w http.ResponseWriter, r *http.Request) {
				return
			}
		}
	}
	
	if areaCircleSub.TrackingAccuracy == 0 {
		log.Error("Mandatory TrackingAccuracy parameter not present")
		errHandlerProblemDetails(w, "Mandatory TrackingAccuracy parameter not present", http.StatusBadRequest)
@@ -3369,11 +3374,11 @@ func areaSubPUT(w http.ResponseWriter, r *http.Request) {
		errHandlerProblemDetails(w, "Mandatory Radius parameter not present", http.StatusBadRequest)
		return
	}
	if len(areaCircleSub.LocationEventCriteria) == 0 {
		log.Error("LocationEventCriteria not present")
		errHandlerProblemDetails(w, "LocationEventCriteria not present", http.StatusBadRequest)
		return
	}
	// if len(areaCircleSub.LocationEventCriteria) == 0 {
	// 	log.Error("LocationEventCriteria not present")
	// 	errHandlerProblemDetails(w, "LocationEventCriteria not present", http.StatusBadRequest)
	// 	return
	// }
	if areaCircleSub.Links == nil || areaCircleSub.Links.Self == nil || areaCircleSub.Links.Self.Href == "" {
		log.Error("Mandatory Links.Self.Href parameter not present")
		errHandlerProblemDetails(w, "Mandatory Links.Self.Href parameter not present", http.StatusBadRequest)
+1 −1
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ type UserAreaNotification struct {

	TimeStamp *TimeStamp `json:"timeStamp,omitempty"`

	UserLocationEvent []LocationEventType `json:"userLocationEvent"`
	UserLocationEvent *LocationEventType `json:"userLocationEvent"`

	Links *SubscriptionLinks `json:"_links,omitempty"`
}