Commit ddde2e09 authored by Simon Pastor's avatar Simon Pastor
Browse files

pr comment

parent 33586882
Loading
Loading
Loading
Loading
+12 −12
Original line number Diff line number Diff line
@@ -267,17 +267,17 @@ paths:
        type: "string"
        x-exportParamName: "AssetName"
      - in: "body"
        name: "distanceParameters"
        name: "targetPoint"
        description: "Parameters of geospatial assets"
        required: true
        schema:
          $ref: "#/definitions/DistanceParameters"
        x-exportParamName: "DistanceParameters"
          $ref: "#/definitions/TargetPoint"
        x-exportParamName: "TargetPoint"
      responses:
        200:
          description: "OK"
          schema:
            $ref: "#/definitions/DistanceResponse"
            $ref: "#/definitions/Distance"
        404:
          description: "Not found"
        500:
@@ -301,17 +301,17 @@ paths:
        type: "string"
        x-exportParamName: "AssetName"
      - in: "body"
        name: "withinRangeParameters"
        name: "targetRange"
        description: "Parameters of geospatial assets"
        required: true
        schema:
          $ref: "#/definitions/WithinRangeParameters"
        x-exportParamName: "WithinRangeParameters"
          $ref: "#/definitions/TargetRange"
        x-exportParamName: "TargetRange"
      responses:
        200:
          description: "OK"
          schema:
            $ref: "#/definitions/WithinRangeResponse"
            $ref: "#/definitions/WithinRange"
        404:
          description: "Not found"
        500:
@@ -350,7 +350,7 @@ definitions:
    example:
      active: true
      type: "MOBILITY"
  DistanceParameters:
  TargetPoint:
    type: "object"
    properties:
      assetName:
@@ -372,7 +372,7 @@ definitions:
      latitude: 0.8008282
      assetName: "assetName"
      longitude: 6.0274563
  DistanceResponse:
  Distance:
    type: "object"
    required:
    - "distance"
@@ -434,7 +434,7 @@ definitions:
          - "CLOUD"
    - $ref: "#/definitions/GeoData"
    description: "List of geospatial data"
  WithinRangeParameters:
  TargetRange:
    type: "object"
    required:
    - "radius"
@@ -468,7 +468,7 @@ definitions:
      accuracy: 5.962134
      radius: 1.4658129
      longitude: 6.0274563
  WithinRangeResponse:
  WithinRange:
    type: "object"
    required:
    - "within"
+1 −1
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@ To see how to make this your own, look here:
[README](https://github.com/swagger-api/swagger-codegen/blob/master/README.md)

- API version: 1.0.0
- Build date: 2021-05-31T09:07:11.391-04:00
- Build date: 2021-06-02T13:11:19.569-04:00


### Running the server
+21 −20
Original line number Diff line number Diff line
@@ -1142,20 +1142,19 @@ func geGetDistanceGeoDataByName(w http.ResponseWriter, r *http.Request) {

	srcLongStr := ""
	srcLatStr := ""
	if srcAsset.geoData != nil {
		srcPosition := srcAsset.geoData.position
		srcPoint := convertJsonToPoint(srcPosition)
		srcLongStr = strconv.FormatFloat(float64(srcPoint.Coordinates[0]), 'f', -1, 32)
		srcLatStr = strconv.FormatFloat(float64(srcPoint.Coordinates[1]), 'f', -1, 32)
	} else {
	position, err := ge.gisCache.GetPosition("*", assetName)
	if err != nil {
		err := errors.New("Asset has no geo location")
		log.Error(err.Error())
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}

	srcLongStr = strconv.FormatFloat(float64(position.Longitude), 'f', -1, 32)
	srcLatStr = strconv.FormatFloat(float64(position.Latitude), 'f', -1, 32)

	// Retrieve Distance parameters from request body
	var distanceParam DistanceParameters
	var distanceParam TargetPoint
	if r.Body == nil {
		err := errors.New("Request body is missing")
		log.Error(err.Error())
@@ -1163,7 +1162,7 @@ func geGetDistanceGeoDataByName(w http.ResponseWriter, r *http.Request) {
		return
	}
	decoder := json.NewDecoder(r.Body)
	err := decoder.Decode(&distanceParam)
	err = decoder.Decode(&distanceParam)
	if err != nil {
		log.Error(err.Error())
		http.Error(w, err.Error(), http.StatusInternalServerError)
@@ -1174,9 +1173,9 @@ func geGetDistanceGeoDataByName(w http.ResponseWriter, r *http.Request) {
	dstLat := float32(0.0)
	dstLongStr := ""
	dstLatStr := ""

	if distanceParam.AssetName != "" {

		// Find second asset in active scenario model
		dstAsset := ge.assets[distanceParam.AssetName]
		if dstAsset == nil {
			err := errors.New("Destination asset not in scenario")
@@ -1184,19 +1183,21 @@ func geGetDistanceGeoDataByName(w http.ResponseWriter, r *http.Request) {
			http.Error(w, err.Error(), http.StatusBadRequest)
			return
		}
		if dstAsset.geoData != nil {
			dstPosition := dstAsset.geoData.position
			dstPoint := convertJsonToPoint(dstPosition)
			dstLong = dstPoint.Coordinates[0]
			dstLat = dstPoint.Coordinates[1]
			dstLongStr = strconv.FormatFloat(float64(dstPoint.Coordinates[0]), 'f', -1, 32)
			dstLatStr = strconv.FormatFloat(float64(dstPoint.Coordinates[1]), 'f', -1, 32)
		} else {
		// Find second asset in active scenario model
		position, err = ge.gisCache.GetPosition("*", distanceParam.AssetName)

		if err != nil {
			err := errors.New("Destination asset has no geo location")
			log.Error(err.Error())
			http.Error(w, err.Error(), http.StatusBadRequest)
			return
		}
		dstLong = position.Longitude
		dstLat = position.Latitude

		dstLongStr = strconv.FormatFloat(float64(position.Longitude), 'f', -1, 32)
		dstLatStr = strconv.FormatFloat(float64(position.Latitude), 'f', -1, 32)

	} else {
		dstLong = distanceParam.Longitude
		dstLat = distanceParam.Latitude
@@ -1215,7 +1216,7 @@ func geGetDistanceGeoDataByName(w http.ResponseWriter, r *http.Request) {
	}

	// Create Response to return
	var resp DistanceResponse
	var resp Distance
	resp.Distance = distance
	resp.Longitude = dstLong
	resp.Latitude = dstLat
@@ -1272,7 +1273,7 @@ func geGetWithinRangeGeoDataByName(w http.ResponseWriter, r *http.Request) {
	}

	// Retrieve Within Range parameters from request body
	var withinRangeParam WithinRangeParameters
	var withinRangeParam TargetRange
	if r.Body == nil {
		err := errors.New("Request body is missing")
		log.Error(err.Error())
@@ -1334,7 +1335,7 @@ func geGetWithinRangeGeoDataByName(w http.ResponseWriter, r *http.Request) {
	}

	// Create Response to return
	var resp WithinRangeResponse
	var resp WithinRange
	resp.Within = withinRange
	resp.Longitude = dstLong
	resp.Latitude = dstLat
+1 −1
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@
package server

// Distance response
type DistanceResponse struct {
type Distance struct {

	// Distance between two points (in meters)
	Distance float32 `json:"distance"`
+1 −1
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@
package server

// Parameters for distance query purpose.
type DistanceParameters struct {
type TargetPoint struct {

	// Asset name of a second element for query purpose. If present, latitude and longitude are ignored.
	AssetName string `json:"assetName,omitempty"`
Loading