Mercurial > gemma
view pkg/controllers/search.go @ 3793:d428f283fe10 yworks-svg2pdf
client: remove `export SVG` button for waterlevel
* Use html comments to disable the button, this was wrongly activated
with commit d36ccff8de5f.
author | Bernhard Reiter <bernhard@intevation.de> |
---|---|
date | Wed, 03 Jul 2019 17:19:28 +0200 |
parents | 1504856c9378 |
children | f68529ff47a4 |
line wrap: on
line source
// This is Free Software under GNU Affero General Public License v >= 3.0 // without warranty, see README.md and license for details. // // SPDX-License-Identifier: AGPL-3.0-or-later // License-Filename: LICENSES/AGPL-3.0.txt // // Copyright (C) 2018 by via donau // – Österreichische Wasserstraßen-Gesellschaft mbH // Software engineering by Intevation GmbH // // Author(s): // * Sascha Wilde <sascha.wilde@intevation.de> // * Sascha Teichmann <sascha.teichmann@intevation.de> package controllers import ( "database/sql" "net/http" "regexp" "strings" "gemma.intevation.de/gemma/pkg/models" ) const ( searchMostSQL = `SELECT search_most($1)::text` 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 WHERE validity @> current_timestamp ORDER BY objnam) r ` ) var rkmRegex = regexp.MustCompile( "^[[:space:]]*([0-9]+)([,.]([0-9]))?[[:space:]]*$", ) func searchFeature( input interface{}, req *http.Request, db *sql.Conn, ) (jr JSONResult, err error) { s := input.(*models.SearchRequest) if len(s.SearchString) == 0 { err = JSONError{http.StatusBadRequest, "error: empty search string"} return } var result string err = db.QueryRowContext( req.Context(), searchMostSQL, s.SearchString, ).Scan(&result) if err != nil { return } 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 }