Mercurial > gemma
diff pkg/controllers/system.go @ 846:6902032757e4
Added end point to set style (colour) information for feature.
author | Sascha Wilde <wilde@intevation.de> |
---|---|
date | Fri, 28 Sep 2018 11:51:06 +0200 |
parents | 0f61bfc21041 |
children | fcb38cedc680 |
line wrap: on
line diff
--- a/pkg/controllers/system.go Fri Sep 28 11:48:57 2018 +0200 +++ b/pkg/controllers/system.go Fri Sep 28 11:51:06 2018 +0200 @@ -15,6 +15,9 @@ getFeatureColourSQL = `SELECT r,g,b,a FROM systemconf.feature_colours WHERE feature_name = $1 AND style_attr = $2` + setFeatureColourSQL = `UPDATE systemconf.feature_colours +SET (r, g, b, a) = ($3, $4, $5, $6) +WHERE feature_name = $1 AND style_attr = $2` ) // System status end points @@ -97,3 +100,46 @@ }{c, fmt.Sprintf("rgba(%d, %d, %d, %g)", c.R, c.G, c.B, c.A)} return } + +func setFeatureStyle( + input interface{}, + req *http.Request, + db *sql.Conn, +) (jr JSONResult, err error) { + + feature := mux.Vars(req)["feature"] + attr := mux.Vars(req)["attr"] + + c := input.(*models.Colour) + if !c.IsValid() { + err = JSONError{http.StatusBadRequest, "error: invalid colours"} + return + } + + var res sql.Result + res, err = db.ExecContext( + req.Context(), + setFeatureColourSQL, + feature, attr, + c.R, c.G, c.B, c.A) + + if err != nil { + return + } + + if n, err2 := res.RowsAffected(); err2 == nil && n == 0 { + err = JSONError{ + Code: http.StatusNotFound, + Message: "Requestes style not found.", + } + return + } + + jr = JSONResult{ + Code: http.StatusCreated, + Result: struct { + Result string `json:"result"` + }{"success"}, + } + return +}