-
Notifications
You must be signed in to change notification settings - Fork 0
/
transport_taxi_availability.go
58 lines (50 loc) · 1.87 KB
/
transport_taxi_availability.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package datagovsg
import (
"encoding/json"
)
type TaxiAvailabilityOptions struct {
DateTime string `json:"date_time,omitempy" url:"date_time,omitempy"`
}
type TaxiAvailabilityResultProperties struct {
Timestamp string `json:"timestamp,omitempty"`
TaxiCount int `json:"taxi_count,omitempty"`
APIInfo APIInfo `json:"api_info,omitempty"`
}
type TaxiAvailabilityResultItem struct {
Type string `json:"type,omitempty"`
Geometry interface{} `json:"geometry,omitempty"`
Properties TaxiAvailabilityResultProperties `json:"properties,omitempty"`
}
// TaxiAvailabilityResult interim struct until we model GeoJSON struct
type TaxiAvailabilityResult struct {
Type string `json:"type,omitempty"`
CRS interface{} `json:"crs,omitempty"`
Features []TaxiAvailabilityResultItem `json:"features,omitempty"`
}
func (resp *TaxiAvailabilityResult) ToGraphQL() interface{} {
if resp == nil {
return TaxiAvailabilityResultGraphQL{}
}
// This assumes that /transport/taxi-availability always returns
// a FeatureCollection with a single Feature of MultiPoint
feature := TaxiAvailabilityResultItem{}
if len(resp.Features) > 0 {
feature = resp.Features[0]
}
// marshal-unmarshal to map[string]interface{}
geoJSONMap := map[string]interface{}{}
b, _ := json.Marshal(resp)
json.Unmarshal(b, &geoJSONMap)
return TaxiAvailabilityResultGraphQL{
Timestamp: feature.Properties.Timestamp,
TaxiCount: feature.Properties.TaxiCount,
APIInfo: feature.Properties.APIInfo,
Result: geoJSONMap,
}
}
type TaxiAvailabilityResultGraphQL struct {
Timestamp string `json:"timestamp,omitempty"`
TaxiCount int `json:"taxi_count,omitempty"`
APIInfo APIInfo `json:"api_info,omitempty"`
Result map[string]interface{} `json:"result,omitempty"`
}