0
0
Fork 0
This repository has been archived on 2024-05-09. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
metrotransit/environment.go
2018-05-26 08:59:34 -05:00

36 lines
727 B
Go

package metrotransit
import (
"errors"
"time"
)
// Env is a wrapper around the Datastore so that any struct which implements the Datastore functions can be used.
type Env struct {
DS Datastore
}
// GetDepartures combines the departure times & stop information into one struct.
func (env *Env) GetDepartures(stopID int) (*Stop, error) {
stop := &Stop{
StopID: stopID,
}
if stopID <= 0 {
return stop, errors.New("invalid stopID")
}
sd, err := env.DS.GetStopDetails(stopID)
if err != nil {
return nil, err
}
stop.Details = *sd
stopDepartures, err := env.DS.GetStopDepartures(stopID)
if err != nil {
return nil, err
}
stop.Departures = *stopDepartures
stop.UpdateTime = time.Now()
return stop, nil
}