view pkg/controllers/surveys.go @ 935:430d52c2f6ef

client: move layer isolines to be drawn at the top * Move layer isolones to be drawn last (and thus being "on top") so that the bottleneck (position) layer will not interfere that much with the colours. It also allows to set a white background with high opacity on the bottleneck polygon in order to get highly visible isolines.
author Bernhard Reiter <bernhard@intevation.de>
date Mon, 08 Oct 2018 17:20:42 +0200
parents a5452a001b46
children a244b18cb916
line wrap: on
line source

package controllers

import (
	"database/sql"
	"net/http"

	"gemma.intevation.de/gemma/pkg/models"
	"github.com/gorilla/mux"
)

const (
	listSurveysSQL = `SELECT s.bottleneck_id,
                                 s.date_info::text
FROM waterway.bottlenecks b, waterway.sounding_results s
WHERE b.objnam=$1 AND s.bottleneck_id = b.bottleneck_id;`
)

func listSurveys(
	_ interface{},
	req *http.Request,
	db *sql.Conn,
) (jr JSONResult, err error) {

	bottleneckName := mux.Vars(req)["bottleneck"]

	var rows *sql.Rows

	rows, err = db.QueryContext(req.Context(), listSurveysSQL, bottleneckName)
	if err != nil {
		return
	}
	defer rows.Close()

	surveys := []models.Survey{}

	for rows.Next() {
		var survey models.Survey
		if err = rows.Scan(
			&survey.BottleneckId,
			&survey.DateInfo,
		); err != nil {
			return
		}
		surveys = append(surveys, survey)
	}

	if err = rows.Err(); err != nil {
		return
	}

	jr = JSONResult{
		Result: struct {
			Surveys []models.Survey `json:"surveys"`
		}{surveys},
	}
	return
}