-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandlers.go
60 lines (57 loc) · 2.06 KB
/
handlers.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
59
60
package main
import (
"net/http"
"strings"
. "github.com/HackPartners/delorean-graph-api/graph"
"github.com/labstack/echo/v4"
)
func Stations(c echo.Context) error {
from := c.QueryParam("from")
direction := c.QueryParam("direction")
if (from == "") && (direction == "") {
return c.JSON(http.StatusOK, GetAllStations())
} else if (from != "") && (direction != "") {
direction = strings.ToUpper(direction)
return c.JSON(http.StatusOK, GetStationsAfter(direction, from))
} else {
return c.String(http.StatusBadRequest, "Both 'from' and 'direction' query params are required, or no params to get a full list of stations.")
}
}
func UpStations(c echo.Context) error {
station := c.Param("station")
return c.JSON(http.StatusOK, GetStationsAfter("UP", station))
}
func DownStations(c echo.Context) error {
station := c.Param("station")
return c.JSON(http.StatusOK, GetStationsAfter("DOWN", station))
}
func Paths(c echo.Context) error {
from := c.QueryParam("from")
to := c.QueryParam("to")
direction := strings.ToUpper(c.QueryParam("direction"))
if (from != "") && (to != "") && (direction != "") {
return c.JSON(http.StatusOK, GetPathsBetween(direction, from, to))
} else if (from != "") && (direction != "") {
return c.JSON(http.StatusOK, GetPathsAfter(direction, from))
} else {
return c.String(http.StatusBadRequest, "'to', 'from' and 'direction' query params are required, or 'from' and 'direction' query params.")
}
}
func UpPaths(c echo.Context) error {
station := c.Param("station")
return c.JSON(http.StatusOK, GetPathsAfter("UP", station))
}
func DownPaths(c echo.Context) error {
station := c.Param("station")
return c.JSON(http.StatusOK, GetPathsAfter("DOWN", station))
}
func UpPathsBetweenStations(c echo.Context) error {
stationA := c.Param("stationA")
stationB := c.Param("stationB")
return c.JSON(http.StatusOK, GetPathsBetween("UP", stationA, stationB))
}
func DownPathsBetweenStations(c echo.Context) error {
stationA := c.Param("stationA")
stationB := c.Param("stationB")
return c.JSON(http.StatusOK, GetPathsBetween("DOWN", stationA, stationB))
}