changeset 2129:8f6345ad5f13

Extend /surveys/ endpoint to include reference gauge * Add a subselection to the sql query in models/surveys.go which similiar to the `bottleneck_geoserver` view assumes that the reference gauge is the same for each survey result. * Maintain rights infos.
author Bernhard Reiter <bernhard@intevation.de>
date Wed, 06 Feb 2019 15:44:55 +0100
parents bc310a0b5bae
children c6a4990a1d93
files pkg/controllers/surveys.go pkg/models/surveys.go
diffstat 2 files changed, 16 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/controllers/surveys.go	Wed Feb 06 15:35:30 2019 +0100
+++ b/pkg/controllers/surveys.go	Wed Feb 06 15:44:55 2019 +0100
@@ -4,13 +4,14 @@
 // SPDX-License-Identifier: AGPL-3.0-or-later
 // License-Filename: LICENSES/AGPL-3.0.txt
 //
-// Copyright (C) 2018 by via donau
+// Copyright (C) 2018, 2019 by via donau
 //   – Österreichische Wasserstraßen-Gesellschaft mbH
 // Software engineering by Intevation GmbH
 //
 // Author(s):
 //  * Sascha Wilde <sascha.wilde@intevation.de>
 //  * Sascha L. Teichmann <sascha.teichmann@intevation.de>
+//  * Bernhard Reiter <bernhard.reiter@intevation.de>
 
 package controllers
 
@@ -26,10 +27,15 @@
 	listSurveysSQL = `
 SELECT
   s.bottleneck_id,
-  s.date_info::text
-FROM waterway.bottlenecks b JOIN waterway.sounding_results s
-ON b.id = s.bottleneck_id
-WHERE b.objnam=$1`
+  s.date_info::text,
+  bg.objname AS gauge_objname
+FROM
+  ( SELECT * FROM waterway.bottlenecks AS b, waterway.gauges AS g
+    WHERE b.fk_g_fid = g.location
+  ) AS bg
+  JOIN waterway.sounding_results AS s
+ON bg.id = s.bottleneck_id
+WHERE bg.objnam=$1`
 )
 
 func listSurveys(
@@ -55,6 +61,7 @@
 		if err = rows.Scan(
 			&survey.BottleneckID,
 			&survey.DateInfo,
+			&survey.ReferenceGauge,
 		); err != nil {
 			return
 		}
--- a/pkg/models/surveys.go	Wed Feb 06 15:35:30 2019 +0100
+++ b/pkg/models/surveys.go	Wed Feb 06 15:44:55 2019 +0100
@@ -4,7 +4,7 @@
 // SPDX-License-Identifier: AGPL-3.0-or-later
 // License-Filename: LICENSES/AGPL-3.0.txt
 //
-// Copyright (C) 2018 by via donau
+// Copyright (C) 2018, 2019 by via donau
 //   – Österreichische Wasserstraßen-Gesellschaft mbH
 // Software engineering by Intevation GmbH
 //
@@ -15,7 +15,8 @@
 
 type (
 	Survey struct {
-		BottleneckID string `json:"bottleneck_id"`
-		DateInfo     string `json:"date_info"`
+		BottleneckID   string `json:"bottleneck_id"`
+		DateInfo       string `json:"date_info"`
+		ReferenceGauge string `json:"gauge_objname"`
 	}
 )