From cfd3a8ffd5275d90556a217d8229b59223361a0c Mon Sep 17 00:00:00 2001
From: lewa <lene.wasskog@nibio.no>
Date: Mon, 9 Sep 2024 14:48:25 +0200
Subject: [PATCH] refactor: Use the same variables names from start to end, set
 altitude to 0

---
 .../no/nibio/vips/logic/service/POIService.java     |  8 ++++----
 src/main/webapp/js/mapModal.js                      |  4 ++--
 .../webapp/templates/forecastConfigurationForm.ftl  | 13 +++----------
 3 files changed, 9 insertions(+), 16 deletions(-)

diff --git a/src/main/java/no/nibio/vips/logic/service/POIService.java b/src/main/java/no/nibio/vips/logic/service/POIService.java
index 8f75290e..78c92f2d 100644
--- a/src/main/java/no/nibio/vips/logic/service/POIService.java
+++ b/src/main/java/no/nibio/vips/logic/service/POIService.java
@@ -117,14 +117,14 @@ public class POIService {
         LOGGER.error("Remember to check for roles as well, if necessary!");
 
         PointOfInterestBean poiBean = SessionControllerGetter.getPointOfInterestBean();
-        Integer poiTypeId = poiMap.get("typeId") != null ? Integer.parseInt(poiMap.get("typeId").toString()) : null;
+        Integer poiTypeId = poiMap.get("pointOfInterestTypeId") != null ? Integer.parseInt(poiMap.get("pointOfInterestTypeId").toString()) : null;
         if(poiTypeId == null) {
-            return Response.status(Status.BAD_REQUEST).entity("Point of interest type is required").build();
+            return Response.status(Status.BAD_REQUEST).entity("pointOfInterestTypeId is required").build();
         }
         String poiName = poiMap.get("name") != null ? poiMap.get("name").toString() : null;
         Double poiLongitude = poiMap.get("longitude") != null ? Double.valueOf(poiMap.get("longitude").toString()): null;
         Double poiLatitude = poiMap.get("latitude") != null ? Double.valueOf(poiMap.get("latitude").toString()): null;
-        Double poiAltitude = poiMap.get("altitude") != null ? Double.valueOf(poiMap.get("altitude").toString()): null;
+        Double poiAltitude = 0.0;
 
         PointOfInterest poiToSave = PointOfInterestFactory.getPointOfInterest(poiTypeId);
         poiToSave.setName(poiName);
@@ -149,7 +149,7 @@ public class POIService {
                     .build();
         } else {
             return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
-                    .entity("Failed to create PointOfInterest")
+                    .entity("Failed to create PointOfInterest " + poiName)
                     .build();
         }
     }
diff --git a/src/main/webapp/js/mapModal.js b/src/main/webapp/js/mapModal.js
index 526c27bc..1683c2f5 100644
--- a/src/main/webapp/js/mapModal.js
+++ b/src/main/webapp/js/mapModal.js
@@ -306,9 +306,9 @@ class MapModal {
     confirmSelection(feature) {
         if (typeof this.callbackOnClose === 'function') {
             const pointData = {
-                id: feature.properties.pointOfInterestId,
+                pointOfInterestId: feature.properties.pointOfInterestId,
                 name: feature.properties.pointOfInterestName,
-                typeId: feature.properties.pointOfInterestTypeId,
+                pointOfInterestTypeId: feature.properties.pointOfInterestTypeId,
                 longitude: feature.geometry.coordinates[0],
                 latitude: feature.geometry.coordinates[1]
             };
diff --git a/src/main/webapp/templates/forecastConfigurationForm.ftl b/src/main/webapp/templates/forecastConfigurationForm.ftl
index 1d164406..95af236f 100755
--- a/src/main/webapp/templates/forecastConfigurationForm.ftl
+++ b/src/main/webapp/templates/forecastConfigurationForm.ftl
@@ -108,21 +108,14 @@
         }
 
         function callbackOnCloseLocationMap(poiData) {
-            if(!poiData.id) {
+            if(!poiData.pointOfInterestId) {
                 persistNewLocation(poiData);
             } else {
-                selectPoi("locationPointOfInterestId", poiData.id);
+                selectPoi("locationPointOfInterestId", poiData.pointOfInterestId);
             }
         }
 
         function persistNewLocation(poiData) {
-            const params = {
-                'name': poiData.name,
-                'typeId': poiData.typeId,
-                'longitude': poiData.longitude,
-                'latitude': poiData.latitude,
-                'altitude': '0', // default value - populate using a service for getting altitude for coordinates?
-            }
             fetch("/rest/poi", {
                 method: 'POST',
                 headers: {
@@ -130,7 +123,7 @@
                     'Accept': 'application/json',
                     'Authorization': '${user.userUuid!'NOT LOGGED IN?'}'
                 },
-                body: JSON.stringify(params)
+                body: JSON.stringify(poiData)
             })
                 .then(response => response.json())
                 .then(poi => {
-- 
GitLab