-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfinder.go
35 lines (28 loc) · 791 Bytes
/
finder.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
package service
import (
"errors"
"github.com/dimat/volume-airports-finder/finder"
)
type Finder struct {
PathFinder finder.PathFinder
}
type FindPathRequest [][]string
type FindPathResponse []string
var ErrInvalidRecord = errors.New("each flight record should have two airports")
func (f *Finder) Call(args FindPathRequest) (FindPathResponse, error) {
flights := make([]finder.Flight, len(args), len(args))
for idx, flight := range args {
if len(flight) != 2 {
return nil, ErrInvalidRecord
}
flights[idx] = finder.Flight{
Source: finder.Airport(flight[0]),
Destination: finder.Airport(flight[1]),
}
}
path, err := f.PathFinder.FindFlightPath(flights)
if err != nil {
return nil, err
}
return []string{string(path.Start), string(path.Finish)}, err
}