changeset 5591:0011f50cf216 surveysperbottleneckid

Removed no longer used alternative api for surveys/ endpoint. As bottlenecks in the summary for SR imports are now identified by their id and no longer by the (not guarantied to be unique!) name, there is no longer the need to request survey data by the name+date tuple (which isn't reliable anyway). So the workaround was now reversed.
author Sascha Wilde <wilde@sha-bang.de>
date Wed, 06 Apr 2022 13:30:29 +0200
parents 826e67e959c9
children 613612ce0ff6
files pkg/controllers/surveys.go
diffstat 1 files changed, 8 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/controllers/surveys.go	Tue Apr 05 13:02:13 2022 +0200
+++ b/pkg/controllers/surveys.go	Wed Apr 06 13:30:29 2022 +0200
@@ -19,6 +19,8 @@
 	"database/sql"
 	"net/http"
 
+	"github.com/gorilla/mux"
+
 	"gemma.intevation.de/gemma/pkg/models"
 
 	mw "gemma.intevation.de/gemma/pkg/middleware"
@@ -41,43 +43,22 @@
     ON s.depth_reference = r.depth_reference
       AND g.location = r.location AND g.validity = r.validity
 WHERE b.bottleneck_id = $1`
-
-	listSurveysByNameDateSQL = `
-SELECT DISTINCT
-	s.bottleneck_id,
-	s.date_info::text,
-	s.depth_reference,
-	COALESCE(g.objname, 'ERROR: MISSING GAUGE') AS gauge_objname,
-	r.value AS waterlevel_value,
-	COALESCE(s.surtyp, 'ERROR: MISSING SURVEY TYPE') AS surtype
-FROM waterway.bottlenecks AS b
-	JOIN waterway.sounding_results AS s ON b.bottleneck_id = s.bottleneck_id
-	LEFT JOIN waterway.gauges AS g
-	  ON b.gauge_location = g.location AND s.date_info::timestamptz <@ g.validity
-	LEFT JOIN waterway.gauges_reference_water_levels AS r
-	  ON s.depth_reference = r.depth_reference
-		AND g.location = r.location AND g.validity = r.validity
-WHERE b.objnam = $1 and s.date_info = $2`
 )
 
 func listSurveys(req *http.Request) (jr mw.JSONResult, err error) {
 
-	v := req.URL.Query()
-	bottleneckName := v.Get("name")
-	date := v.Get("date")
-	id := v.Get("id")
+	bottleneckId := mux.Vars(req)["id"]
+
 	var rows *sql.Rows
-	surveys := []*models.Survey{}
 
-	if date == "" && bottleneckName == "" && id != "" {
-		rows, err = mw.JSONConn(req).QueryContext(req.Context(), listSurveysByIdSQL, id)
-	} else if date != "" && bottleneckName != "" && id == "" {
-		rows, err = mw.JSONConn(req).QueryContext(req.Context(), listSurveysByNameDateSQL, bottleneckName, date)
-	}
+	rows, err = mw.JSONConn(req).QueryContext(req.Context(), listSurveysByIdSQL, bottleneckId)
 	if err != nil {
 		return
 	}
 	defer rows.Close()
+
+	surveys := []*models.Survey{}
+
 	// as we do not use the values here, we could simply the code here
 	// to work without an explicit mdels/surverys.go
 	// (like done in controllers/search.go)