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

Remove unnecessary code

parent 094f713d
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -71,9 +71,6 @@ func DistanceSubListGET(w http.ResponseWriter, r *http.Request) {
	distanceSubListGet(w, r)
}

func DistanceSubPOST_test(w http.ResponseWriter, r *http.Request) {
	distanceSubPOST_test(w, r)
}
func DistanceSubPOST(w http.ResponseWriter, r *http.Request) {
	distanceSubPost(w, r)
}
+13 −79
Original line number Diff line number Diff line
@@ -2395,9 +2395,6 @@ func distanceSubListGet(w http.ResponseWriter, r *http.Request) {

	var response []InlineNotificationSubscriptionList
	var subscriptions []Subscription
	// distanceSubList.ResourceURL = &LinkType{}
	// distanceSubList.ResourceURL.Href = hostUrl.String() + basePath + "subscriptions/distance"
	// response.NotificationSubscriptionList = &distanceSubList

	keyName := baseKey + typeDistanceSubscription + "*"
	err := rc.ForEachJSONEntry(keyName, populateDistanceList, &subscriptions)
@@ -2456,7 +2453,7 @@ func distanceSubGet(w http.ResponseWriter, r *http.Request) {
	fmt.Fprint(w, string(jsonResponse))
}

func distanceSubPOST_test(w http.ResponseWriter, r *http.Request) {
func distanceSubPost(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	var response InlineUserDistanceSubscription
	var body InlineUserDistanceSubscription
@@ -2499,6 +2496,11 @@ func distanceSubPOST_test(w http.ResponseWriter, r *http.Request) {
	nextDistanceSubscriptionIdAvailable++
	subsIdStr := strconv.Itoa(newSubsId)
	distanceSub.ResourceURL = hostUrl.String() + basePath + "subscriptions/distance/" + subsIdStr
	distanceSub.Links = &Links{
		Self: &LinkType{
			Href: hostUrl.String() + basePath + "subscriptions/distance/" + subsIdStr,
		},
	}
	_ = rc.JSONSetEntry(baseKey+typeDistanceSubscription+":"+subsIdStr, ".", convertDistanceSubscriptionToJson1(distanceSub))
	registerDistance1(distanceSub, subsIdStr)
	response.UserDistanceSubscription = distanceSub
@@ -2512,78 +2514,6 @@ func distanceSubPOST_test(w http.ResponseWriter, r *http.Request) {
	fmt.Fprint(w, string(jsonResponse))
}

func distanceSubPost(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")

	var response InlineDistanceNotificationSubscription

	var body InlineDistanceNotificationSubscription
	decoder := json.NewDecoder(r.Body)
	err := decoder.Decode(&body)
	if err != nil {
		log.Error(err.Error())
		errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError)
		return
	}
	distanceSub := body.DistanceNotificationSubscription

	if distanceSub == nil {
		log.Error("Body not present")
		errHandlerProblemDetails(w, "Body not present", http.StatusBadRequest)
		return
	}

	//checking for mandatory properties
	if distanceSub.CallbackReference == nil || distanceSub.CallbackReference.NotifyURL == "" {
		log.Error("Mandatory CallbackReference parameter not present")
		errHandlerProblemDetails(w, "Mandatory CallbackReference parameter not present", http.StatusBadRequest)
		return
	}
	if distanceSub.Criteria == nil {
		log.Error("Mandatory DistanceCriteria parameter not present")
		errHandlerProblemDetails(w, "Mandatory DistanceCriteria parameter not present", http.StatusBadRequest)
		return
	}
	if distanceSub.Frequency == 0 {
		log.Error("Mandatory Frequency parameter not present")
		errHandlerProblemDetails(w, "Mandatory Frequency parameter not present", http.StatusBadRequest)
		return
	}
	if distanceSub.MonitoredAddress == nil {
		log.Error("Mandatory MonitoredAddress parameter not present")
		errHandlerProblemDetails(w, "Mandatory MonitoredAddress parameter not present", http.StatusBadRequest)
		return
	}
	/*
		   if distanceSub.TrackingAccuracy == 0 {
			   log.Error("Mandatory TrackingAccuracy parameter not present")
			   errHandlerProblemDetails(w, "Mandatory TrackingAccuracy parameter not present", http.StatusBadRequest)
			   return
		   }
	*/

	newSubsId := nextDistanceSubscriptionIdAvailable
	nextDistanceSubscriptionIdAvailable++
	subsIdStr := strconv.Itoa(newSubsId)

	distanceSub.ResourceURL = hostUrl.String() + basePath + "subscriptions/distance/" + subsIdStr

	_ = rc.JSONSetEntry(baseKey+typeDistanceSubscription+":"+subsIdStr, ".", convertDistanceSubscriptionToJson(distanceSub))

	registerDistance(distanceSub, subsIdStr)

	response.DistanceNotificationSubscription = distanceSub

	jsonResponse, err := json.Marshal(response)
	if err != nil {
		log.Error(err.Error())
		errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError)
		return
	}
	w.WriteHeader(http.StatusCreated)
	fmt.Fprint(w, string(jsonResponse))
}

func distanceSubPut(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	vars := mux.Vars(r)
@@ -2646,7 +2576,11 @@ func distanceSubPut(w http.ResponseWriter, r *http.Request) {
		return
	}

	distanceSub.ResourceURL = hostUrl.String() + basePath + "subscriptions/distance/" + subsIdStr
	distanceSub.Links = &Links{
		Self: &LinkType{
			Href: hostUrl.String() + basePath + "subscriptions/distance/" + subsIdStr,
		},
	}

	subsId, err := strconv.Atoi(subsIdStr)
	if err != nil {
@@ -2655,7 +2589,7 @@ func distanceSubPut(w http.ResponseWriter, r *http.Request) {
		return
	}

	if distanceSubscriptionMap[subsId] == nil {
	if distanceSubscriptionMap1[subsId] == nil {
		w.WriteHeader(http.StatusNotFound)
		return
	}
@@ -2666,7 +2600,7 @@ func distanceSubPut(w http.ResponseWriter, r *http.Request) {
	notifSent := distanceSubscriptionMap[subsId].NbNotificationsSent
	deregisterDistance(subsIdStr)
	registerDistance1(distanceSub, subsIdStr)
	distanceSubscriptionMap[subsId].NbNotificationsSent = notifSent
	distanceSubscriptionMap1[subsId].NbNotificationsSent = notifSent

	response.UserDistanceSubscription = distanceSub

+0 −7
Original line number Diff line number Diff line
@@ -171,13 +171,6 @@ var routes = Routes{
		DistanceSubPOST,
	},

	Route{
		"distanceSubPOST_test",
		strings.ToUpper("Post"),
		"/location/v2/subscriptions/distance/test",
		DistanceSubPOST_test,
	},

	Route{
		"DistanceSubPUT",
		strings.ToUpper("Put"),