Mercurial > gemma
annotate pkg/controllers/surveys.go @ 1921:0059aa870a39 v2
Hotfixed stretch import.
author | Sascha Wilde <wilde@intevation.de> |
---|---|
date | Fri, 18 Jan 2019 20:26:21 +0100 |
parents | 056a86b24be2 |
children | 8f6345ad5f13 |
rev | line source |
---|---|
1017
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
825
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:
825
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:
825
diff
changeset
|
3 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
825
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:
825
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:
825
diff
changeset
|
6 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
825
diff
changeset
|
7 // Copyright (C) 2018 by via donau |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
825
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
825
diff
changeset
|
9 // Software engineering by Intevation GmbH |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
825
diff
changeset
|
10 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
825
diff
changeset
|
11 // Author(s): |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
825
diff
changeset
|
12 // * Sascha Wilde <sascha.wilde@intevation.de> |
1317
5443f5c9154c
Added missing authors names in Go files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
13 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
1017
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
825
diff
changeset
|
14 |
812
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
15 package controllers |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
16 |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
17 import ( |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
18 "database/sql" |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
19 "net/http" |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
20 |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
21 "gemma.intevation.de/gemma/pkg/models" |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
22 "github.com/gorilla/mux" |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
23 ) |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
24 |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
25 const ( |
1572
056a86b24be2
Made bottleneck primary key an int. Attention: This may break something!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1332
diff
changeset
|
26 listSurveysSQL = ` |
056a86b24be2
Made bottleneck primary key an int. Attention: This may break something!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1332
diff
changeset
|
27 SELECT |
056a86b24be2
Made bottleneck primary key an int. Attention: This may break something!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1332
diff
changeset
|
28 s.bottleneck_id, |
056a86b24be2
Made bottleneck primary key an int. Attention: This may break something!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1332
diff
changeset
|
29 s.date_info::text |
056a86b24be2
Made bottleneck primary key an int. Attention: This may break something!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1332
diff
changeset
|
30 FROM waterway.bottlenecks b JOIN waterway.sounding_results s |
056a86b24be2
Made bottleneck primary key an int. Attention: This may break something!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1332
diff
changeset
|
31 ON b.id = s.bottleneck_id |
056a86b24be2
Made bottleneck primary key an int. Attention: This may break something!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1332
diff
changeset
|
32 WHERE b.objnam=$1` |
812
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
33 ) |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
34 |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
35 func listSurveys( |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
36 _ interface{}, |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
37 req *http.Request, |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
38 db *sql.Conn, |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
39 ) (jr JSONResult, err error) { |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
40 |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
41 bottleneckName := mux.Vars(req)["bottleneck"] |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
42 |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
43 var rows *sql.Rows |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
44 |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
45 rows, err = db.QueryContext(req.Context(), listSurveysSQL, bottleneckName) |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
46 if err != nil { |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
47 return |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
48 } |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
49 defer rows.Close() |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
50 |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
51 surveys := []models.Survey{} |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
52 |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
53 for rows.Next() { |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
54 var survey models.Survey |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
55 if err = rows.Scan( |
1332
447db2bce052
Renamed BottleneckId to BottleneckID to make golint happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1317
diff
changeset
|
56 &survey.BottleneckID, |
812
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
57 &survey.DateInfo, |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
58 ); err != nil { |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
59 return |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
60 } |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
61 surveys = append(surveys, survey) |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
62 } |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
63 |
825
a5452a001b46
Added missing error check in surveys controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
812
diff
changeset
|
64 if err = rows.Err(); err != nil { |
a5452a001b46
Added missing error check in surveys controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
812
diff
changeset
|
65 return |
a5452a001b46
Added missing error check in surveys controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
812
diff
changeset
|
66 } |
a5452a001b46
Added missing error check in surveys controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
812
diff
changeset
|
67 |
812
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
68 jr = JSONResult{ |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
69 Result: struct { |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
70 Surveys []models.Survey `json:"surveys"` |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
71 }{surveys}, |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
72 } |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
73 return |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
74 } |