comparison pkg/controllers/surveys.go @ 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 056a86b24be2
children 7267f8168176
comparison
equal deleted inserted replaced
2128:bc310a0b5bae 2129:8f6345ad5f13
2 // without warranty, see README.md and license for details. 2 // without warranty, see README.md and license for details.
3 // 3 //
4 // SPDX-License-Identifier: AGPL-3.0-or-later 4 // SPDX-License-Identifier: AGPL-3.0-or-later
5 // License-Filename: LICENSES/AGPL-3.0.txt 5 // License-Filename: LICENSES/AGPL-3.0.txt
6 // 6 //
7 // Copyright (C) 2018 by via donau 7 // Copyright (C) 2018, 2019 by via donau
8 // – Österreichische Wasserstraßen-Gesellschaft mbH 8 // – Österreichische Wasserstraßen-Gesellschaft mbH
9 // Software engineering by Intevation GmbH 9 // Software engineering by Intevation GmbH
10 // 10 //
11 // Author(s): 11 // Author(s):
12 // * Sascha Wilde <sascha.wilde@intevation.de> 12 // * Sascha Wilde <sascha.wilde@intevation.de>
13 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> 13 // * Sascha L. Teichmann <sascha.teichmann@intevation.de>
14 // * Bernhard Reiter <bernhard.reiter@intevation.de>
14 15
15 package controllers 16 package controllers
16 17
17 import ( 18 import (
18 "database/sql" 19 "database/sql"
24 25
25 const ( 26 const (
26 listSurveysSQL = ` 27 listSurveysSQL = `
27 SELECT 28 SELECT
28 s.bottleneck_id, 29 s.bottleneck_id,
29 s.date_info::text 30 s.date_info::text,
30 FROM waterway.bottlenecks b JOIN waterway.sounding_results s 31 bg.objname AS gauge_objname
31 ON b.id = s.bottleneck_id 32 FROM
32 WHERE b.objnam=$1` 33 ( SELECT * FROM waterway.bottlenecks AS b, waterway.gauges AS g
34 WHERE b.fk_g_fid = g.location
35 ) AS bg
36 JOIN waterway.sounding_results AS s
37 ON bg.id = s.bottleneck_id
38 WHERE bg.objnam=$1`
33 ) 39 )
34 40
35 func listSurveys( 41 func listSurveys(
36 _ interface{}, 42 _ interface{},
37 req *http.Request, 43 req *http.Request,
53 for rows.Next() { 59 for rows.Next() {
54 var survey models.Survey 60 var survey models.Survey
55 if err = rows.Scan( 61 if err = rows.Scan(
56 &survey.BottleneckID, 62 &survey.BottleneckID,
57 &survey.DateInfo, 63 &survey.DateInfo,
64 &survey.ReferenceGauge,
58 ); err != nil { 65 ); err != nil {
59 return 66 return
60 } 67 }
61 surveys = append(surveys, survey) 68 surveys = append(surveys, survey)
62 } 69 }