Mercurial > gemma
annotate pkg/controllers/surveys.go @ 1329:ea2143adc6d3
Named method recievers consistently to make golint happy.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sun, 25 Nov 2018 17:05:19 +0100 |
parents | 5443f5c9154c |
children | 447db2bce052 |
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 ( |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
26 listSurveysSQL = `SELECT s.bottleneck_id, |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
27 s.date_info::text |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
28 FROM waterway.bottlenecks b, waterway.sounding_results s |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
29 WHERE b.objnam=$1 AND s.bottleneck_id = b.bottleneck_id;` |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
30 ) |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
31 |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
32 func listSurveys( |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
33 _ interface{}, |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
34 req *http.Request, |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
35 db *sql.Conn, |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
36 ) (jr JSONResult, err error) { |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
37 |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
38 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
|
39 |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
40 var rows *sql.Rows |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
41 |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
42 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
|
43 if err != nil { |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
44 return |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
45 } |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
46 defer rows.Close() |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
47 |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
48 surveys := []models.Survey{} |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
49 |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
50 for rows.Next() { |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
51 var survey models.Survey |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
52 if err = rows.Scan( |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
53 &survey.BottleneckId, |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
54 &survey.DateInfo, |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
55 ); err != nil { |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
56 return |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
57 } |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
58 surveys = append(surveys, survey) |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
59 } |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
60 |
825
a5452a001b46
Added missing error check in surveys controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
812
diff
changeset
|
61 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
|
62 return |
a5452a001b46
Added missing error check in surveys controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
812
diff
changeset
|
63 } |
a5452a001b46
Added missing error check in surveys controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
812
diff
changeset
|
64 |
812
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
65 jr = JSONResult{ |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
66 Result: struct { |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
67 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
|
68 }{surveys}, |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
69 } |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
70 return |
98a7776100fb
Added end point lo list available surveys for a given bottleneck.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
71 } |