Skip to content

Commit

Permalink
updated detailview
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaya-Sem committed Sep 27, 2024
1 parent f62e430 commit 923807a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
20 changes: 10 additions & 10 deletions cmd/api/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

// GetConnections fetches the connection data from the API and returns the response body as a byte slice.
func GetConnections(stationFrom string, stationTo string) ([]byte, error) {
url := fmt.Sprintf("https://api.irail.be/connections/?from=%s&to=%s&timesel=departure&format=json&lang=en&typeOfTransport=automatic&alerts=false&results=6", stationFrom, stationTo)
url := fmt.Sprintf("https://api.irail.be/connections/?from=%s&to=%s&timesel=departure&format=json&lang=nl&typeOfTransport=automatic&alerts=false&results=6", stationFrom, stationTo)

resp, err := http.Get(url)
if err != nil {
Expand All @@ -26,7 +26,7 @@ func GetConnections(stationFrom string, stationTo string) ([]byte, error) {

body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
fmt.Println(fmt.Errorf("couldn't read response body: %v", err))
}

return body, nil
Expand Down Expand Up @@ -82,7 +82,7 @@ type Connection struct {
Arrival ConnectionArrival `json:"arrival"`
Duration string `json:"duration"`
Number string `json:"number"`
Vias *Vias `json:"vias,omitempty"`
Vias Vias `json:"vias,omitempty"` // waarom de * ?
}

// TODO:
Expand All @@ -98,7 +98,7 @@ type ConnectionDeparture struct {
//Stops []Stop `json:"stops"`
VehicleInfo VehicleInfo `json:"vehicleinfo"`
// StationInfo StationInfo `json:"stationinfo"`
//PlatformInfo PlatformInfo `json:"platforminfo"`
// PlatformInfo PlatformInfo `json:"platforminfo"`
}

type ConnectionArrival struct {
Expand All @@ -124,10 +124,10 @@ type Vias struct {
}

type ViaInfo struct {
ID string `json:"id"`
Station string `json:"station"`
TimeBetween string `json:"timeBetween"`
Vehicle string `json:"vehicle"`
Departure ConnectionDeparture `json:"departure"`
Arrival ConnectionArrival `json:"arrival"`
ID string `json:"id"`
Arrival ConnectionArrival `json:"arrival"`
Departure ConnectionDeparture `json:"departure"`
// Station string `json:"station"`
TimeBetween string `json:"timeBetween"`
//Vehicle string `json:"vehicle"`
}
25 changes: 13 additions & 12 deletions cmd/tables/detailView.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,24 @@ func buildDetailView(conn api.Connection) string {
red := "\033[31m" // ANSI escape code for red
reset := "\033[0m" // ANSI Reset color

// FIX: better color formatting
// Start building the output string
output := "\n"
output += " " + cmd.UnixToHHMM(conn.Departure.Time) + " " + yellow + "S" + reset + " " + conn.Departure.Station + "\n"
output += " " + red + cmd.FormatDelay(conn.Departure.Delay) + reset + yellow + " ┃" + reset + " " + italic + conn.Departure.VehicleInfo.ShortName + reset + "\n"
output += " " + cmd.UnixToHHMM(conn.Departure.Time) + " " + yellow + "┏━" + reset + " " + conn.Departure.Station + "\n"
output += " " + red + cmd.FormatDelay(conn.Departure.Delay) + reset + yellow + " ┃" + reset + " " + italic + conn.Departure.VehicleInfo.ShortName + reset + "\n"
output += yellow + " ┃ " + reset + "\n"
output += yellow + " ┃ " + reset + "\n"

// Uncomment and modify the following code to add stops
// for i, stop := range conn.Vias.Via {
// if i == len(conn.Vias.Via)-1 { // Last stop gets blue color
// output += yellow + " \u2502 " + reset + "\n"
// output += blue + " ○ " + reset + stop.Station + "\n"
// } else {
// output += yellow + " \u2502 " + reset + "\n"
// output += yellow + " ○ " + reset + stop.Station + "\n"
// }
// }
for _, stop := range conn.Vias.Via {
output += " " + cmd.UnixToHHMM(conn.Arrival.Time) + yellow + " ┗━ " + reset + stop.Arrival.Station + ", platform " + stop.Arrival.Platform + "\n"
output += " ┊ " + "\n"
output += " " + cmd.UnixToHHMM(stop.Departure.Time) + yellow + " ┏━ " + reset + stop.Departure.Station + ", platform " + stop.Departure.Platform + "\n"
output += yellow + " ┃ " + reset + "\n"
output += yellow + " ┃ " + reset + "\n"
output += yellow + " ┃ " + reset + "\n"
}

output += " " + cmd.UnixToHHMM(conn.Arrival.Time) + yellow + " ┗━ " + reset + conn.Arrival.Station + "\n"
output += "\n"
return output
}

0 comments on commit 923807a

Please sign in to comment.