fix: long distance should only affect the results when true

This commit is contained in:
etwas 2025-04-15 21:44:37 +02:00
parent 2bed20e04f
commit 1ff513ebae
Signed by: etwas
SSH key fingerprint: SHA256:bHhIeAdn/2k9jmOs6+u6ox98VYmoHUN3HfnpV2w8Ws0

11
main.go
View file

@ -107,9 +107,16 @@ func (h *stopInfoHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
searchQuery = "%" + searchQuery + "%" 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 { if err != nil {
w.WriteHeader(500) w.WriteHeader(500)
_ = enc.Encode(RequestError{Code: "0001", Message: "DB Error: " + err.Error()}) _ = enc.Encode(RequestError{Code: "0001", Message: "DB Error: " + err.Error()})