Mercurial > gemma
changeset 5196:5bc8daa986d9 new-fwa
More code movement.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 07 May 2020 16:25:58 +0200 |
parents | d6710d29516b |
children | c352dbbf2778 |
files | pkg/controllers/bottlenecks.go pkg/controllers/fwa.go |
diffstat | 2 files changed, 33 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/pkg/controllers/bottlenecks.go Thu May 07 15:46:51 2020 +0200 +++ b/pkg/controllers/bottlenecks.go Thu May 07 16:25:58 2020 +0200 @@ -373,20 +373,11 @@ return } - from, ok := parseFormTime(rw, req, "from", time.Now().AddDate(-1, 0, 0)) + from, to, ok := parseFromTo(rw, req) if !ok { return } - to, ok := parseFormTime(rw, req, "to", from.AddDate(1, 0, 0)) - if !ok { - return - } - - if to.Before(from) { - to, from = from, to - } - los, ok := parseFormInt(rw, req, "los", 1) if !ok { return
--- a/pkg/controllers/fwa.go Thu May 07 15:46:51 2020 +0200 +++ b/pkg/controllers/fwa.go Thu May 07 16:25:58 2020 +0200 @@ -16,7 +16,9 @@ import ( "log" "net/http" + "time" + "gemma.intevation.de/gemma/pkg/common" "github.com/gorilla/mux" ) @@ -37,6 +39,23 @@ // TODO: Implement me! } +func parseFromTo( + rw http.ResponseWriter, + req *http.Request, +) (time.Time, time.Time, bool) { + from, ok := parseFormTime(rw, req, "from", time.Now().AddDate(-1, 0, 0)) + if !ok { + return time.Time{}, time.Time{}, false + } + + to, ok := parseFormTime(rw, req, "to", from.AddDate(1, 0, 0)) + if !ok { + return time.Time{}, time.Time{}, false + } + from, to = common.OrderTime(from, to) + return from, to, true +} + func fairwayAvailabilityBottleneck(rw http.ResponseWriter, req *http.Request) { vars := mux.Vars(req) @@ -48,5 +67,18 @@ } log.Printf("info: fairway availability for bottleneck_id '%s'\n", bottleneckID) + from, to, ok := parseFromTo(rw, req) + if !ok { + return + } + + los, ok := parseFormInt(rw, req, "los", 1) + if !ok { + return + } + // TODO: Implement me! + _ = from + _ = to + _ = los }