-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetStops.go
More file actions
46 lines (41 loc) · 1.14 KB
/
getStops.go
File metadata and controls
46 lines (41 loc) · 1.14 KB
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
package main
import "github.com/jmcvetta/neoism"
//Stop represent a stop bus
type Stop struct {
IDStop string `json:"IDStop"`
Name string `json:"Name"`
Direction int `json:"Dir"`
}
//Stops is used to represent multiple Stop
type Stops []Stop
//GetStopsFromLineID return all stops for a lineId
func GetStopsFromLineID(idLine string) (res Stops, err error) {
query := "MATCH (b:BusStop)-[p:PATH]->() WHERE p.busLineID = {busLineID} RETURN b.idStop AS IDStop, b.name AS Name, p.direction AS Dir"
params := neoism.Props{
"busLineID": idLine,
}
cq := neoism.CypherQuery{
Statement: query,
Parameters: params,
Result: &res,
}
if err = DB.Cypher(&cq); err != nil {
return nil, err
}
return res, nil
}
func getStopAutocomplete(name string) (res Stops, err error) {
query := "MATCH (b:BusStop)-[p:PATH]->(n) WHERE b.name =~ '(?ui).*{name}.*' return DISTINCT b.idStop AS IDStop, b.name AS Name, p.direction AS Dir"
params := neoism.Props{
"name": name,
}
cq := neoism.CypherQuery{
Statement: query,
Parameters: params,
Result: &res,
}
if err = DB.Cypher(&cq); err != nil {
return nil, err
}
return res, nil
}