44 "encoding/json"
55 "fmt"
66 "net/url"
7+ "path"
78 "time"
89)
910
@@ -24,23 +25,44 @@ type PatrolsResponse struct {
2425 } `json:"status"`
2526}
2627
28+ type PatrolByIDResponse struct {
29+ Data PatrolDetails `json:"data"`
30+ Status struct {
31+ Code int `json:"code"`
32+ Message string `json:"message"`
33+ } `json:"status"`
34+ }
35+
2736type Patrol struct {
28- ID string `json:"id"`
29- SerialNumber int `json:"serial_number"`
30- State string `json:"state"`
31- Title * string `json:"title"`
32- PatrolSegments []PatrolSegment `json:"patrol_segments"`
37+ ID string `json:"id"`
38+ SerialNumber int `json:"serial_number"`
39+ State string `json:"state"`
40+ Title * string `json:"title"`
41+ PatrolSegments []PatrolSegmentDetails `json:"patrol_segments"`
42+ }
43+
44+ type PatrolDetails struct {
45+ ID string `json:"id"`
46+ SerialNumber int `json:"serial_number"`
47+ State string `json:"state"`
48+ Title string `json:"title"`
49+ PatrolSegments []PatrolSegmentDetails `json:"patrol_segments"`
3350}
3451
35- type PatrolSegment struct {
36- ID string `json:"id"`
37- Leader * struct {
38- Name string `json:"name"`
39- } `json:"leader"`
40- PatrolType string `json:"patrol_type"`
41- StartLocation * Location `json:"start_location"`
42- EndLocation * Location `json:"end_location"`
43- TimeRange TimeRange `json:"time_range"`
52+ type PatrolSegmentDetails struct {
53+ ID string `json:"id"`
54+ Leader PatrolLeader `json:"leader"`
55+ PatrolType string `json:"patrol_type"`
56+ StartLocation * Location `json:"start_location"`
57+ EndLocation * Location `json:"end_location"`
58+ TimeRange TimeRange `json:"time_range"`
59+ }
60+
61+ type PatrolLeader struct {
62+ ID string `json:"id"`
63+ Name string `json:"name"`
64+ SubjectType string `json:"subject_type"`
65+ SubjectSubtype string `json:"subject_subtype"`
4466}
4567
4668type Location struct {
@@ -107,3 +129,40 @@ func (c *Client) Patrols(days int, status string) (*PatrolsResponse, error) {
107129
108130 return & response , nil
109131}
132+
133+ func (c * Client ) PatrolTracks (subjectID string , since string , until string ) (* TracksResponse , error ) {
134+ params := url.Values {}
135+ params .Add ("since" , since )
136+ params .Add ("until" , until )
137+
138+ endpoint := path .Join (API_SUBJECT , subjectID , API_SUBJECT_TRACKS )
139+ endpoint = fmt .Sprintf ("%s?%s" , endpoint , params .Encode ())
140+
141+ req , err := c .newRequest ("GET" , endpoint , false )
142+ if err != nil {
143+ return nil , fmt .Errorf ("error generating patrol tracks request: %w" , err )
144+ }
145+
146+ var responseData TracksResponse
147+ if err := c .doRequest (req , & responseData ); err != nil {
148+ return nil , fmt .Errorf ("error fetching patrol tracks: %w" , err )
149+ }
150+
151+ return & responseData , nil
152+ }
153+
154+ func (c * Client ) PatrolByID (patrolID string ) (* PatrolByIDResponse , error ) {
155+ endpoint := fmt .Sprintf ("%s/%s" , API_PATROLS , patrolID )
156+
157+ req , err := c .newRequest ("GET" , endpoint , false )
158+ if err != nil {
159+ return nil , fmt .Errorf ("error generating patrol by ID request: %w" , err )
160+ }
161+
162+ var responseData PatrolByIDResponse
163+ if err := c .doRequest (req , & responseData ); err != nil {
164+ return nil , fmt .Errorf ("error fetching patrol by ID: %w" , err )
165+ }
166+
167+ return & responseData , nil
168+ }
0 commit comments