@@ -6,50 +6,63 @@ package api
6
6
import (
7
7
"github.com/Kong/KongAir/flight-data/routes/api/models"
8
8
"github.com/labstack/echo/v4"
9
- "net/http"
9
+ "net/http"
10
10
)
11
11
12
12
type RouteService struct {
13
- Routes []models.Route
13
+ Routes []models.Route
14
+ PrivateRoutes []models.Route
14
15
}
15
16
16
17
func NewRouteService () * RouteService {
17
18
rv := RouteService {}
18
19
rv .Routes = []models.Route {
19
- {Id : "LHR-JFK" , Origin : "LHR" , Destination : "JFK" , AvgDuration : 470 },
20
- {Id : "LHR-SFO" , Origin : "LHR" , Destination : "SFO" , AvgDuration : 660 },
21
- {Id : "LHR-DXB" , Origin : "LHR" , Destination : "DXB" , AvgDuration : 420 },
22
- {Id : "LHR-HKG" , Origin : "LHR" , Destination : "HKG" , AvgDuration : 745 },
23
- {Id : "LHR-BOM" , Origin : "LHR" , Destination : "BOM" , AvgDuration : 540 },
24
- {Id : "LHR-HND" , Origin : "LHR" , Destination : "HND" , AvgDuration : 830 },
25
- {Id : "LHR-CPT" , Origin : "LHR" , Destination : "CPT" , AvgDuration : 700 },
26
- {Id : "LHR-SYD" , Origin : "LHR" , Destination : "SYD" , AvgDuration : 1320 },
27
- {Id : "LHR-SIN" , Origin : "LHR" , Destination : "SIN" , AvgDuration : 800 },
28
- {Id : "LHR-LAX" , Origin : "LHR" , Destination : "LAX" , AvgDuration : 675 },
20
+ {Id : "LHR-JFK" , Origin : "LHR" , Destination : "JFK" , AvgDuration : 470 },
21
+ {Id : "LHR-SFO" , Origin : "LHR" , Destination : "SFO" , AvgDuration : 660 },
22
+ {Id : "LHR-DXB" , Origin : "LHR" , Destination : "DXB" , AvgDuration : 420 },
23
+ {Id : "LHR-HKG" , Origin : "LHR" , Destination : "HKG" , AvgDuration : 745 },
24
+ {Id : "LHR-BOM" , Origin : "LHR" , Destination : "BOM" , AvgDuration : 540 },
25
+ {Id : "LHR-HND" , Origin : "LHR" , Destination : "HND" , AvgDuration : 830 },
26
+ {Id : "LHR-CPT" , Origin : "LHR" , Destination : "CPT" , AvgDuration : 700 },
27
+ {Id : "LHR-SYD" , Origin : "LHR" , Destination : "SYD" , AvgDuration : 1320 },
28
+ {Id : "LHR-SIN" , Origin : "LHR" , Destination : "SIN" , AvgDuration : 800 },
29
+ {Id : "LHR-LAX" , Origin : "LHR" , Destination : "LAX" , AvgDuration : 675 },
30
+ }
31
+ rv .PrivateRoutes = []models.Route {
32
+ {Id : "VIP-LHR-JFK" , Origin : "LHR" , Destination : "VIP-JFK" , AvgDuration : 430 },
33
+ {Id : "VIP-LHR-SFO" , Origin : "LHR" , Destination : "VIP-SFO" , AvgDuration : 620 },
34
+ {Id : "VIP-LHR-DXB" , Origin : "LHR" , Destination : "VIP-DXB" , AvgDuration : 390 },
35
+ {Id : "VIP-LHR-HKG" , Origin : "LHR" , Destination : "VIP-HKG" , AvgDuration : 645 },
29
36
}
30
37
return & rv
31
38
}
32
39
33
40
func (s * RouteService ) GetHealth (ctx echo.Context ) error {
34
- return ctx .JSON (http .StatusOK , map [string ]string {"status" : "OK" })
41
+ return ctx .JSON (http .StatusOK , map [string ]string {"status" : "OK" })
35
42
}
36
43
37
44
func (s * RouteService ) GetRoutes (ctx echo.Context , params models.GetRoutesParams ) error {
38
- err := ctx .JSON ( 200 , s . Routes )
39
- if err != nil {
40
- return err
45
+ if ctx .Request (). Header . Get ( "x-vip" ) == "true" {
46
+ allRoutes := append ( s . Routes , s . PrivateRoutes ... )
47
+ return ctx . JSON ( 200 , allRoutes )
41
48
}
42
- return nil
49
+
50
+ return ctx .JSON (200 , s .Routes )
43
51
}
52
+
44
53
func (s * RouteService ) GetRoute (ctx echo.Context , id string ) error {
45
- for _ , route := range s .Routes {
46
- if route .Id == id {
47
- err := ctx .JSON (200 , route )
48
- if err != nil {
49
- return err
50
- }
51
- return nil
52
- }
53
- }
54
- return ctx .JSON (404 , nil )
54
+ routes := s .Routes
55
+ if ctx .Request ().Header .Get ("x-vip" ) == "true" {
56
+ routes = append (routes , s .PrivateRoutes ... )
57
+ }
58
+ for _ , route := range routes {
59
+ if route .Id == id {
60
+ err := ctx .JSON (200 , route )
61
+ if err != nil {
62
+ return err
63
+ }
64
+ return nil
65
+ }
66
+ }
67
+ return ctx .JSON (404 , nil )
55
68
}
0 commit comments