annotate pkg/controllers/system.go @ 3302:ec6163c6687d

'Historicise' gauges on import Gauge data sets will be updated or a new version will be inserted depending on temporal validity and a timestamp marking the last update in the RIS-Index of a data set. The trigger on date_info is removed because the value is actually an attribut coming from the RIS-Index. Gauge measurements and predictions are associated to the version with matching temporal validity. Bottlenecks are always associated to the actual version of the gauge, although this might change as soon as bottlenecks are 'historicised', too.
author Tom Gottfried <tom@intevation.de>
date Thu, 16 May 2019 18:41:43 +0200
parents 8a4fb02ee60a
children a688a478e35f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1017
a244b18cb916 Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 854
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: 854
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: 854
diff changeset
3 //
a244b18cb916 Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 854
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: 854
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: 854
diff changeset
6 //
a244b18cb916 Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 854
diff changeset
7 // Copyright (C) 2018 by via donau
a244b18cb916 Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 854
diff changeset
8 // – Österreichische Wasserstraßen-Gesellschaft mbH
a244b18cb916 Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 854
diff changeset
9 // Software engineering by Intevation GmbH
a244b18cb916 Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 854
diff changeset
10 //
a244b18cb916 Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 854
diff changeset
11 // Author(s):
a244b18cb916 Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 854
diff changeset
12 // * Sascha Wilde <sascha.wilde@intevation.de>
a244b18cb916 Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 854
diff changeset
13
722
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
14 package controllers
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
15
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
16 import (
3104
19fc84a98479 Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
17 "bytes"
722
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
18 "database/sql"
840
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
19 "fmt"
722
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
20 "io/ioutil"
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
21 "net/http"
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
22 "strings"
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
23
3104
19fc84a98479 Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
24 "gemma.intevation.de/gemma/pkg/config"
840
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
25 "gemma.intevation.de/gemma/pkg/models"
722
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
26 "github.com/gorilla/mux"
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
27 )
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
28
840
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
29 const (
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
30 getFeatureColourSQL = `SELECT r,g,b,a
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
31 FROM systemconf.feature_colours
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
32 WHERE feature_name = $1 AND style_attr = $2`
846
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
33 setFeatureColourSQL = `UPDATE systemconf.feature_colours
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
34 SET (r, g, b, a) = ($3, $4, $5, $6)
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
35 WHERE feature_name = $1 AND style_attr = $2`
840
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
36 )
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
37
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
38 // System status end points
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
39
722
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
40 func showSystemLog(
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
41 _ interface{}, req *http.Request,
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
42 _ *sql.Conn,
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
43 ) (jr JSONResult, err error) {
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
44
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
45 serviceName := mux.Vars(req)["service"]
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
46 fileName := mux.Vars(req)["file"]
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
47
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
48 // The following check is currently most likely unnecessary as I wasn't
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
49 // able to inject a verbatim '/' via the middleware, but better be on
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
50 // the safe site...
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
51 if strings.Contains(fileName, "/") {
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
52 err = JSONError{http.StatusBadRequest,
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
53 "error: no slashes allowed in file name"}
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
54 return
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
55 }
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
56
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
57 var path string
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
58
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
59 switch serviceName {
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
60 case "apache2", "postgresql":
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
61 path = "/var/log/" + serviceName + "/" + fileName
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
62 default:
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
63 err = JSONError{http.StatusBadRequest,
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
64 "error: invalid service: " + serviceName}
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
65 return
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
66 }
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
67
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
68 var txt []byte
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
69
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
70 if txt, err = ioutil.ReadFile(path); err != nil {
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
71 return
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
72 }
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
73
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
74 jr = JSONResult{
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
75 Result: struct {
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
76 Path string `json:"path"`
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
77 Content string `json:"content"`
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
78 }{path, string(txt)},
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
79 }
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
80 return
815f5e2ed974 Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
81 }
840
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
82
3104
19fc84a98479 Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
83 func getSystemConfig(
19fc84a98479 Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
84 _ interface{}, req *http.Request,
19fc84a98479 Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
85 _ *sql.Conn,
19fc84a98479 Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
86 ) (jr JSONResult, err error) {
19fc84a98479 Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
87
19fc84a98479 Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
88 cfg := config.PublishedConfig()
19fc84a98479 Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
89 if cfg == "" {
3108
8a4fb02ee60a Send empty JSON document when calling GET /api/system/config and "published-config" is not configure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3104
diff changeset
90 jr = JSONResult{Result: strings.NewReader("{}")}
3104
19fc84a98479 Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
91 return
19fc84a98479 Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
92 }
19fc84a98479 Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
93
19fc84a98479 Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
94 var data []byte
19fc84a98479 Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
95 if data, err = ioutil.ReadFile(cfg); err != nil {
19fc84a98479 Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
96 return
19fc84a98479 Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
97 }
19fc84a98479 Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
98
19fc84a98479 Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
99 jr = JSONResult{Result: bytes.NewReader(data)}
19fc84a98479 Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
100 return
19fc84a98479 Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
101 }
19fc84a98479 Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
102
840
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
103 // Map/Feature style end points
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
104
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
105 func getFeatureStyle(
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
106 _ interface{},
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
107 req *http.Request,
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
108 db *sql.Conn,
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
109 ) (jr JSONResult, err error) {
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
110
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
111 feature := mux.Vars(req)["feature"]
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
112 attr := mux.Vars(req)["attr"]
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
113
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
114 c := models.Colour{}
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
115 err = db.QueryRowContext(
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
116 req.Context(),
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
117 getFeatureColourSQL,
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
118 feature, attr,
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
119 ).Scan(&c.R, &c.G, &c.B, &c.A)
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
120
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
121 switch {
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
122 case err == sql.ErrNoRows:
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
123 err = JSONError{
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
124 Code: http.StatusNotFound,
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
125 Message: "Requestes style not found.",
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
126 }
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
127 return
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
128 case err != nil:
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
129 return
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
130 }
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
131
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
132 jr.Result = &struct {
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
133 Colour models.Colour `json:"colour"`
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
134 Code string `json:"code"`
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
135 }{c, fmt.Sprintf("rgba(%d, %d, %d, %g)", c.R, c.G, c.B, c.A)}
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
136 return
0f61bfc21041 Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 722
diff changeset
137 }
846
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
138
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
139 func setFeatureStyle(
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
140 input interface{},
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
141 req *http.Request,
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
142 db *sql.Conn,
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
143 ) (jr JSONResult, err error) {
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
144
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
145 feature := mux.Vars(req)["feature"]
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
146 attr := mux.Vars(req)["attr"]
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
147
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
148 c := input.(*models.Colour)
854
83c271cb2344 Reverted fcb38cedc680 (More tightened color model.)
Sascha Wilde <wilde@intevation.de>
parents: 850
diff changeset
149 if !c.IsValid() {
83c271cb2344 Reverted fcb38cedc680 (More tightened color model.)
Sascha Wilde <wilde@intevation.de>
parents: 850
diff changeset
150 err = JSONError{http.StatusBadRequest, "error: invalid colours"}
83c271cb2344 Reverted fcb38cedc680 (More tightened color model.)
Sascha Wilde <wilde@intevation.de>
parents: 850
diff changeset
151 return
83c271cb2344 Reverted fcb38cedc680 (More tightened color model.)
Sascha Wilde <wilde@intevation.de>
parents: 850
diff changeset
152 }
846
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
153
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
154 var res sql.Result
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
155 res, err = db.ExecContext(
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
156 req.Context(),
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
157 setFeatureColourSQL,
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
158 feature, attr,
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
159 c.R, c.G, c.B, c.A)
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
160
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
161 if err != nil {
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
162 return
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
163 }
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
164
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
165 if n, err2 := res.RowsAffected(); err2 == nil && n == 0 {
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
166 err = JSONError{
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
167 Code: http.StatusNotFound,
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
168 Message: "Requestes style not found.",
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
169 }
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
170 return
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
171 }
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
172
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
173 jr = JSONResult{
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
174 Code: http.StatusCreated,
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
175 Result: struct {
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
176 Result string `json:"result"`
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
177 }{"success"},
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
178 }
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
179 return
6902032757e4 Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents: 840
diff changeset
180 }