From 1ff513ebae2edc964584957b76b823c6b901fec8 Mon Sep 17 00:00:00 2001 From: etwas Date: Tue, 15 Apr 2025 21:44:37 +0200 Subject: [PATCH] fix: long distance should only affect the results when true --- main.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 2709a22..2b0b897 100644 --- a/main.go +++ b/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()})