Mercurial > gemma
annotate pkg/controllers/search.go @ 5311:72d3b8321ed0 zpg-exception
Fixed broken migration which erased the style of the modified GeoServer view.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 02 Jun 2021 16:55:00 +0200 |
parents | a6e5bb85f0a7 |
children |
rev | line source |
---|---|
1017
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
995
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
995
diff
changeset
|
2 // without warranty, see README.md and license for details. |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
995
diff
changeset
|
3 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
995
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
995
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
995
diff
changeset
|
6 // |
5130
a6e5bb85f0a7
Added new (optional) parameter "time" to search end point.
Sascha Wilde <wilde@intevation.de>
parents:
5127
diff
changeset
|
7 // Copyright (C) 2018, 2020 by via donau |
1017
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
995
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
995
diff
changeset
|
9 // Software engineering by Intevation GmbH |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
995
diff
changeset
|
10 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
995
diff
changeset
|
11 // Author(s): |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
995
diff
changeset
|
12 // * Sascha Wilde <sascha.wilde@intevation.de> |
1337
53057ab27ff2
add headers for licensing to some middleware files
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1109
diff
changeset
|
13 // * Sascha Teichmann <sascha.teichmann@intevation.de> |
1017
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
995
diff
changeset
|
14 |
743
fdff2de616ad
Added search function for river kilometer.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
15 package controllers |
fdff2de616ad
Added search function for river kilometer.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
16 |
fdff2de616ad
Added search function for river kilometer.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
17 import ( |
fdff2de616ad
Added search function for river kilometer.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
18 "net/http" |
fdff2de616ad
Added search function for river kilometer.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
19 "strings" |
fdff2de616ad
Added search function for river kilometer.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
20 |
fdff2de616ad
Added search function for river kilometer.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
21 "gemma.intevation.de/gemma/pkg/models" |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
22 |
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
23 mw "gemma.intevation.de/gemma/pkg/middleware" |
743
fdff2de616ad
Added search function for river kilometer.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
24 ) |
fdff2de616ad
Added search function for river kilometer.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
25 |
fdff2de616ad
Added search function for river kilometer.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
26 const ( |
5130
a6e5bb85f0a7
Added new (optional) parameter "time" to search end point.
Sascha Wilde <wilde@intevation.de>
parents:
5127
diff
changeset
|
27 searchMostSQL = `SELECT search_most($1,$2)::text` |
743
fdff2de616ad
Added search function for river kilometer.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
28 ) |
fdff2de616ad
Added search function for river kilometer.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
29 |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
30 func searchFeature(req *http.Request) (jr mw.JSONResult, err error) { |
743
fdff2de616ad
Added search function for river kilometer.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
31 |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
32 s := mw.JSONInput(req).(*models.SearchRequest) |
743
fdff2de616ad
Added search function for river kilometer.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
33 |
fdff2de616ad
Added search function for river kilometer.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
34 if len(s.SearchString) == 0 { |
4506
e020e6e34ad7
Made 'go vet' happy again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4244
diff
changeset
|
35 err = mw.JSONError{ |
e020e6e34ad7
Made 'go vet' happy again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4244
diff
changeset
|
36 Code: http.StatusBadRequest, |
e020e6e34ad7
Made 'go vet' happy again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4244
diff
changeset
|
37 Message: "error: empty search string", |
e020e6e34ad7
Made 'go vet' happy again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4244
diff
changeset
|
38 } |
743
fdff2de616ad
Added search function for river kilometer.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
39 return |
fdff2de616ad
Added search function for river kilometer.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
40 } |
fdff2de616ad
Added search function for river kilometer.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
41 |
751
21dd10f26206
Some refactoring in search endpoint.
Sascha Wilde <wilde@intevation.de>
parents:
750
diff
changeset
|
42 var result string |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
43 err = mw.JSONConn(req).QueryRowContext( |
3734
1504856c9378
Moved rhm search to db.
Sascha Wilde <wilde@intevation.de>
parents:
3666
diff
changeset
|
44 req.Context(), |
1504856c9378
Moved rhm search to db.
Sascha Wilde <wilde@intevation.de>
parents:
3666
diff
changeset
|
45 searchMostSQL, |
1504856c9378
Moved rhm search to db.
Sascha Wilde <wilde@intevation.de>
parents:
3666
diff
changeset
|
46 s.SearchString, |
5130
a6e5bb85f0a7
Added new (optional) parameter "time" to search end point.
Sascha Wilde <wilde@intevation.de>
parents:
5127
diff
changeset
|
47 s.SearchTime, |
3734
1504856c9378
Moved rhm search to db.
Sascha Wilde <wilde@intevation.de>
parents:
3666
diff
changeset
|
48 ).Scan(&result) |
748
3cb012d4d9ef
Added search for bottlenecks
Sascha Wilde <wilde@intevation.de>
parents:
744
diff
changeset
|
49 |
751
21dd10f26206
Some refactoring in search endpoint.
Sascha Wilde <wilde@intevation.de>
parents:
750
diff
changeset
|
50 if err != nil { |
21dd10f26206
Some refactoring in search endpoint.
Sascha Wilde <wilde@intevation.de>
parents:
750
diff
changeset
|
51 return |
21dd10f26206
Some refactoring in search endpoint.
Sascha Wilde <wilde@intevation.de>
parents:
750
diff
changeset
|
52 } |
743
fdff2de616ad
Added search function for river kilometer.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
53 |
751
21dd10f26206
Some refactoring in search endpoint.
Sascha Wilde <wilde@intevation.de>
parents:
750
diff
changeset
|
54 jr.Result = strings.NewReader(result) |
743
fdff2de616ad
Added search function for river kilometer.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
55 return |
fdff2de616ad
Added search function for river kilometer.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
56 } |