changeset 5250:13e1767b63a1 new-fwa

Reverted: 8c44b518141a, which didn't fix anything.
author Sascha Wilde <wilde@intevation.de>
date Tue, 12 May 2020 23:03:21 +0200
parents d855426a6e5d
children 1fce0fd81f46
files pkg/controllers/fwa.go
diffstat 1 files changed, 14 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/controllers/fwa.go	Tue May 12 22:55:10 2020 +0200
+++ b/pkg/controllers/fwa.go	Tue May 12 23:03:21 2020 +0200
@@ -50,7 +50,8 @@
   %s s, waterway.bottlenecks b
 WHERE
   ST_Intersects(b.area, s.area)
-  AND s.name = $1`
+  AND s.name = $1
+  AND b.validity && tstzrange($2, $3)`
 
 	selectLDCsSQL = `
 SELECT
@@ -202,7 +203,7 @@
 	conn := middleware.GetDBConn(req)
 
 	// Function to extract the bottleneck_id's from the query.
-	var extract func(context.Context, *sql.Conn, string) (bottlenecks, error)
+	var extract func(context.Context, *sql.Conn, string, time.Time, time.Time) (bottlenecks, error)
 
 	switch vars["kind"] {
 	case "bottleneck":
@@ -216,7 +217,7 @@
 		return
 	}
 
-	bottlenecks, err := extract(ctx, conn, name)
+	bottlenecks, err := extract(ctx, conn, name, from, to)
 	if err != nil {
 		log.Printf("error: %v\n", err)
 		http.Error(rw, "cannot extract bottlenecks", http.StatusBadRequest)
@@ -627,12 +628,14 @@
 	ctx context.Context,
 	conn *sql.Conn,
 	what, name string,
+	from, to time.Time,
 ) (bottlenecks, error) {
 
 	rows, err := conn.QueryContext(
 		ctx,
 		fmt.Sprintf(selectSymbolBottlenecksSQL, what),
-		name)
+		name,
+		from, to)
 	if err != nil {
 		return nil, err
 	}
@@ -655,6 +658,7 @@
 	_ context.Context,
 	_ *sql.Conn,
 	name string,
+	_, _ time.Time,
 ) (bottlenecks, error) {
 	return bottlenecks{{id: name}}, nil
 }
@@ -663,22 +667,26 @@
 	ctx context.Context,
 	conn *sql.Conn,
 	name string,
+	from, to time.Time,
 ) (bottlenecks, error) {
 	return loadSymbolBottlenecksFromTo(
 		ctx,
 		conn,
-		"users.stretches", name)
+		"users.stretches", name,
+		from, to)
 }
 
 func extractSection(
 	ctx context.Context,
 	conn *sql.Conn,
 	name string,
+	from, to time.Time,
 ) (bottlenecks, error) {
 	return loadSymbolBottlenecksFromTo(
 		ctx,
 		conn,
-		"waterway.sections", name)
+		"waterway.sections", name,
+		from, to)
 }
 
 func (bn *bottleneck) loadLimitingValidities(