diff --git a/main.go b/main.go index 1248014..2235376 100644 --- a/main.go +++ b/main.go @@ -195,6 +195,49 @@ func (h *stopIdInfoHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } // Return departures at specific stop +type GetDeparturesByIdRowWithString struct { + bahndb_rest.GetDeparturesByIdRow +} + +func (r GetDeparturesByIdRowWithString) MarshalJSON() ([]byte, error) { + var direction map[string]interface{} + err := json.Unmarshal(r.Direction, &direction) + if err != nil { + return nil, err + } + + // Create an anonymous struct that mirrors the original but with string Direction + tmp := struct { + ID string `json:"id"` + LineName pgtype.Text `json:"lineName"` + LineProductName pgtype.Text `json:"lineProductName"` + DepartureDelay pgtype.Int4 `json:"departureDelay"` + Direction interface{} `json:"direction"` + Stopovers interface{} `json:"stopovers"` + Departure pgtype.Timestamptz `json:"departure"` + PlannedDeparture pgtype.Timestamptz `json:"plannedDeparture"` + DeparturePlatform pgtype.Text `json:"departurePlattform"` + PlannedDeparturePlatform pgtype.Text `json:"plannedDeparturePlattform"` + Cancelled pgtype.Text `json:"cancelled"` + RealtimeDataUpdatedAt pgtype.Timestamptz `json:"realtimeDataUpdatedAt"` + }{ + ID: r.ID, + LineName: r.LineName, + LineProductName: r.LineProductName, + DepartureDelay: r.DepartureDelay, + Direction: direction, + Stopovers: r.Stopovers, + Departure: r.Departure, + PlannedDeparture: r.PlannedDeparture, + DeparturePlatform: r.DeparturePlatform, + PlannedDeparturePlatform: r.PlannedDeparturePlatform, + Cancelled: r.Cancelled, + RealtimeDataUpdatedAt: r.RealtimeDataUpdatedAt, + } + + return json.Marshal(tmp) +} + type stopDeparturesHandler struct{} func (h *stopDeparturesHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { @@ -273,10 +316,16 @@ func (h *stopDeparturesHandler) ServeHTTP(w http.ResponseWriter, r *http.Request return } + var stationsReturn []GetDeparturesByIdRowWithString + + for _, station := range stations { + stationsReturn = append(stationsReturn, GetDeparturesByIdRowWithString{station}) + } + // Return Data w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) - err = enc.Encode(stations) + err = enc.Encode(stationsReturn) if err != nil { w.WriteHeader(500)