Commit db56d3e4 authored by M. Hamza's avatar M. Hamza
Browse files

update validate params logic in meep-vis

parent 66eba492
Loading
Loading
Loading
Loading
+8 −12
Original line number Diff line number Diff line
@@ -929,6 +929,7 @@ func subscriptionsPost(w http.ResponseWriter, r *http.Request) {
	var extractSubType SubscriptionCommon

	bodyBytes, _ := ioutil.ReadAll(r.Body)

	err := json.Unmarshal(bodyBytes, &extractSubType)
	if err != nil {
		log.Error(err.Error())
@@ -936,6 +937,12 @@ func subscriptionsPost(w http.ResponseWriter, r *http.Request) {
		return
	}

	if extractSubType.SubscriptionType == "" {
		log.Error("Mandatory SubscriptionType parameter should be present")
		errHandlerProblemDetails(w, "Mandatory attribute SubscriptionType is missing in the request body.", http.StatusBadRequest)
		return
	}

	//extract subscription type
	subscriptionType := extractSubType.SubscriptionType

@@ -954,6 +961,7 @@ func subscriptionsPost(w http.ResponseWriter, r *http.Request) {
	case V2X_MSG:

		var v2xSubscription V2xMsgSubscription

		err = json.Unmarshal(bodyBytes, &v2xSubscription)
		if err != nil {
			log.Error(err.Error())
@@ -962,24 +970,12 @@ func subscriptionsPost(w http.ResponseWriter, r *http.Request) {
		}

		// Validating mandatory parameters provided in the request body
		if v2xSubscription.SubscriptionType == "" {
			log.Error("Mandatory SubscriptionType parameter should be present")
			errHandlerProblemDetails(w, "Mandatory attribute SubscriptionType is missing in the request body.", http.StatusBadRequest)
			return
		}

		if v2xSubscription.Links != nil {
			log.Error("Links attribute should not be present in request body")
			errHandlerProblemDetails(w, "Links attribute should not be present in request body.", http.StatusBadRequest)
			return
		}

		if v2xSubscription.SubscriptionType != "V2xMsgSubscription" {
			log.Error("SubscriptionType should be set to V2xMsgSubscription")
			errHandlerProblemDetails(w, "SubscriptionType should be set to V2xMsgSubscription in the request body.", http.StatusBadRequest)
			return
		}

		if v2xSubscription.FilterCriteria == nil {
			log.Error("Mandatory FilterCriteria parameter should be present")
			errHandlerProblemDetails(w, "Mandatory attribute FilterCriteria is missing in the request body.", http.StatusBadRequest)