fix: long distance should only affect the results when true
This commit is contained in:
parent
2bed20e04f
commit
1ff513ebae
1 changed files with 9 additions and 2 deletions
11
main.go
11
main.go
|
|
@ -107,9 +107,16 @@ func (h *stopInfoHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
searchQuery = "%" + searchQuery + "%"
|
||||
}
|
||||
|
||||
queryPgText := pgtype.Text{String: searchQuery, Valid: true}
|
||||
var longDistance pgtype.Bool
|
||||
|
||||
stations, err := queries.GetStationsByName(ctx, queryPgText)
|
||||
// Parse whether only long distance stations shall be returned
|
||||
if r.FormValue("longDistance") == "true" {
|
||||
longDistance = pgtype.Bool{Bool: true, Valid: true}
|
||||
} else {
|
||||
longDistance = pgtype.Bool{Bool: false, Valid: false}
|
||||
}
|
||||
|
||||
stations, err := queries.GetStationsByName(ctx, bahndb_rest.GetStationsByNameParams{SearchParams: searchQueries, LongDistance: longDistance})
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
_ = enc.Encode(RequestError{Code: "0001", Message: "DB Error: " + err.Error()})
|
||||
|
|
|
|||
Loading…
Reference in a new issue