Mercurial > gemma
changeset 2152:8132434f4093
Surveys controller: Fixed nullable water level.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 08 Feb 2019 11:47:31 +0100 |
parents | d639b721c7be |
children | cdd68f555ad7 |
files | pkg/controllers/surveys.go pkg/models/surveys.go |
diffstat | 2 files changed, 13 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/pkg/controllers/surveys.go Fri Feb 08 11:32:14 2019 +0100 +++ b/pkg/controllers/surveys.go Fri Feb 08 11:47:31 2019 +0100 @@ -69,23 +69,27 @@ } defer rows.Close() - surveys := []models.Survey{} + surveys := []*models.Survey{} // as we do not use the values here, we could simply the code here // to work without an explicit mdels/surverys.go // (like done in controllers/search.go) for rows.Next() { var survey models.Survey + var level sql.NullInt64 if err = rows.Scan( &survey.BottleneckID, &survey.DateInfo, &survey.DepthReference, &survey.ReferenceGauge, - &survey.WaterLevelValue, + &level, ); err != nil { return } - surveys = append(surveys, survey) + if level.Valid { + survey.WaterLevelValue = &level.Int64 + } + surveys = append(surveys, &survey) } if err = rows.Err(); err != nil { @@ -94,7 +98,7 @@ jr = JSONResult{ Result: struct { - Surveys []models.Survey `json:"surveys"` + Surveys []*models.Survey `json:"surveys"` }{surveys}, } return
--- a/pkg/models/surveys.go Fri Feb 08 11:32:14 2019 +0100 +++ b/pkg/models/surveys.go Fri Feb 08 11:47:31 2019 +0100 @@ -13,16 +13,12 @@ package models -import ( - "database/sql" -) - type ( Survey struct { - BottleneckID string `json:"bottleneck_id"` - DateInfo string `json:"date_info"` - DepthReference string `json:"depth_reference"` - ReferenceGauge string `json:"gauge_objname"` - WaterLevelValue sql.NullInt64 `json:"waterlevel_value"` + BottleneckID string `json:"bottleneck_id"` + DateInfo string `json:"date_info"` + DepthReference string `json:"depth_reference"` + ReferenceGauge string `json:"gauge_objname"` + WaterLevelValue *int64 `json:"waterlevel_value,omitempty"` } )