aboutsummaryrefslogtreecommitdiff
path: root/internal/webui
diff options
context:
space:
mode:
authorJulien Dessaux2021-05-04 11:59:13 +0200
committerJulien Dessaux2021-05-04 12:03:18 +0200
commitdc4fea013c5f89054ae348cab2935eebe28a4712 (patch)
treebf3455ab4e3953489495c5621a40c108d4dba5e3 /internal/webui
parentUpdated dependencies (diff)
downloadtrains-dc4fea013c5f89054ae348cab2935eebe28a4712.tar.gz
trains-dc4fea013c5f89054ae348cab2935eebe28a4712.tar.bz2
trains-dc4fea013c5f89054ae348cab2935eebe28a4712.zip
Cleaned the navitia - webui calls
Diffstat (limited to 'internal/webui')
-rw-r--r--internal/webui/root.go29
1 files changed, 10 insertions, 19 deletions
diff --git a/internal/webui/root.go b/internal/webui/root.go
index c3a0ec5..ab6fdcd 100644
--- a/internal/webui/root.go
+++ b/internal/webui/root.go
@@ -5,7 +5,6 @@ import (
"html/template"
"log"
"net/http"
- "time"
"git.adyxax.org/adyxax/trains/pkg/model"
)
@@ -15,38 +14,30 @@ var rootTemplate = template.Must(template.ParseFS(templatesFS, "html/base.html",
// The page template variable
type Page struct {
User *model.User
- Departures []Departure
+ Departures []model.Departure
Title string
}
-type Departure struct {
- DisplayName string
- Arrival string
- Odd bool
-}
// The root handler of the webui
func rootHandler(e *env, w http.ResponseWriter, r *http.Request) error {
if r.URL.Path == "/" {
- var p Page
user, err := tryAndResumeSession(e, r)
if err != nil {
http.Redirect(w, r, "/login", http.StatusFound)
return nil
}
- p.User = user
- if d, err := e.navitia.GetDepartures(e.conf.TrainStop); err != nil {
- log.Printf("%+v\n%s\n", d, err)
+ var departures []model.Departure
+ if departures, err := e.navitia.GetDepartures(e.conf.TrainStop); err != nil {
+ log.Printf("%s; data returned: %+v\n", err, departures)
+ return newStatusError(http.StatusInternalServerError, fmt.Errorf("Could not get departures"))
} else {
- for i := 0; i < len(d.Departures); i++ {
- t, err := time.Parse("20060102T150405", d.Departures[i].StopDateTime.ArrivalDateTime)
- if err != nil {
- panic(err)
- }
- p.Departures = append(p.Departures, Departure{d.Departures[i].DisplayInformations.Direction, t.Format("Mon, 02 Jan 2006 15:04:05"), i%2 == 1})
- }
w.Header().Set("Cache-Control", "no-store, no-cache")
}
- p.Title = "Horaires des prochains trains à Crépieux la Pape"
+ p := Page{
+ User: user,
+ Departures: departures,
+ Title: "Horaires des prochains trains à Crépieux la Pape",
+ }
err = rootTemplate.ExecuteTemplate(w, "root.html", p)
if err != nil {
return newStatusError(http.StatusInternalServerError, err)