Mercurial > gemma
changeset 1052:e3f3e645792b
Merged.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 25 Oct 2018 11:31:59 +0200 |
parents | 137a8144e581 (diff) e3df77b8074f (current diff) |
children | 82ae9cb56982 1ff8c072df18 |
files | |
diffstat | 2 files changed, 43 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/pkg/controllers/routes.go Thu Oct 25 11:17:58 2018 +0200 +++ b/pkg/controllers/routes.go Thu Oct 25 11:31:59 2018 +0200 @@ -133,11 +133,16 @@ NoConn: true, })).Methods(http.MethodGet) - // Bottleneck selection + // Survey selection api.Handle("/surveys/{bottleneck}", any(&JSONHandler{ Handle: listSurveys, })).Methods(http.MethodGet) + // Bottlenecks + api.Handle("/bottlenecks", any(&JSONHandler{ + Handle: listBottlenecks, + })).Methods(http.MethodGet) + // Cross sections api.Handle("/cross", any(&JSONHandler{ Input: func() interface{} { return new(models.CrossSectionInput) },
--- a/pkg/controllers/search.go Thu Oct 25 11:17:58 2018 +0200 +++ b/pkg/controllers/search.go Thu Oct 25 11:31:59 2018 +0200 @@ -29,12 +29,24 @@ ST_AsGeoJSON(geom)::json AS geom, 'rhm' AS type FROM waterway.distance_marks_virtual WHERE (location_code).hectometre = $1) r` + searchBottleneckSQL = `SELECT COALESCE(json_agg(r),'[]') FROM (SELECT objnam AS name, ST_AsGeoJSON(ST_Centroid(area))::json AS geom, 'bottleneck' AS type FROM waterway.bottlenecks WHERE objnam ILIKE $1) r` + + listBottlenecksSQL = ` +SELECT COALESCE(json_agg(r),'[]') +FROM ( + SELECT + objnam AS name, + ST_AsGeoJSON(ST_Centroid(area))::json AS geom, + 'bottleneck' AS type + FROM waterway.bottlenecks +ORDER BY objnam) r +` ) var rkmRegex = regexp.MustCompile( @@ -93,6 +105,30 @@ } jr.Result = strings.NewReader(result) - return } + +func listBottlenecks( + _ interface{}, + req *http.Request, + conn *sql.Conn, +) (jr JSONResult, err error) { + + var result string + err = conn.QueryRowContext( + req.Context(), listBottlenecksSQL).Scan(&result) + + switch { + case err == sql.ErrNoRows: + err = JSONError{ + Code: http.StatusNotFound, + Message: "Cannot find any bottleneck.", + } + return + case err != nil: + return + } + + jr = JSONResult{Result: strings.NewReader(result)} + return +}