diff --git a/api/endpoint.go b/api/endpoint.go index d962dcd..522a1c2 100644 --- a/api/endpoint.go +++ b/api/endpoint.go @@ -40,8 +40,9 @@ func retrieveEndpoint(svc callhome.Service) endpoint.Endpoint { Limit: req.limit, } filter := callhome.TelemetryFilters{ - From: req.from, - To: req.to, + From: req.from, + To: req.to, + Country: req.country, } tm, err := svc.Retrieve(ctx, pm, filter) if err != nil { @@ -66,8 +67,9 @@ func retrieveSummaryEndpoint(svc callhome.Service) endpoint.Endpoint { return nil, err } filter := callhome.TelemetryFilters{ - From: req.from, - To: req.to, + From: req.from, + To: req.to, + Country: req.country, } summary, err := svc.RetrieveSummary(ctx, filter) if err != nil { @@ -87,8 +89,9 @@ func serveUI(svc callhome.Service) endpoint.Endpoint { return nil, err } filter := callhome.TelemetryFilters{ - From: req.from, - To: req.to, + From: req.from, + To: req.to, + Country: req.country, } res, err := svc.ServeUI(ctx, filter) return uiRes{ diff --git a/api/requests.go b/api/requests.go index fd44875..ee8fef3 100644 --- a/api/requests.go +++ b/api/requests.go @@ -40,10 +40,11 @@ func (req saveTelemetryReq) validate() error { } type listTelemetryReq struct { - offset uint64 - limit uint64 - from time.Time - to time.Time + offset uint64 + limit uint64 + from time.Time + to time.Time + country string } func (req listTelemetryReq) validate() error { diff --git a/api/transport.go b/api/transport.go index 17a55fb..44c6178 100644 --- a/api/transport.go +++ b/api/transport.go @@ -26,6 +26,7 @@ const ( limitKey = "limit" fromKey = "from" toKey = "to" + countryKey = "country" defOffset = 0 defLimit = 10 staticDir = "./web/static" @@ -179,11 +180,17 @@ func decodeRetrieve(_ context.Context, r *http.Request) (interface{}, error) { } } + co, err := ReadStringQuery(r, countryKey, "") + if err != nil { + return nil, err + } + req := listTelemetryReq{ - offset: o, - limit: l, - from: from, - to: to, + offset: o, + limit: l, + from: from, + to: to, + country: co, } return req, nil } diff --git a/openapi/openapi.yaml b/openapi/openapi.yaml index bf43f99..51bc138 100644 --- a/openapi/openapi.yaml +++ b/openapi/openapi.yaml @@ -27,6 +27,7 @@ paths: - $ref: "#/components/parameters/Offset" - $ref: "#/components/parameters/From" - $ref: "#/components/parameters/To" + - $ref: "#/components/parameters/Country" responses: "200": description: found @@ -45,6 +46,7 @@ paths: - $ref: "#/components/parameters/Offset" - $ref: "#/components/parameters/From" - $ref: "#/components/parameters/To" + - $ref: "#/components/parameters/Country" responses: "200": description: found @@ -78,6 +80,7 @@ paths: - $ref: "#/components/parameters/Offset" - $ref: "#/components/parameters/From" - $ref: "#/components/parameters/To" + - $ref: "#/components/parameters/Country" tags: - telemetry summary: Retrieve telemetry events @@ -137,6 +140,14 @@ components: type: string default: "" required: false + Country: + name: country + description: From country filter. + in: query + schema: + type: string + default: "" + required: false requestBodies: TelemetryReq: content: diff --git a/telemetry.go b/telemetry.go index 0a40604..2b4f98b 100644 --- a/telemetry.go +++ b/telemetry.go @@ -21,8 +21,9 @@ type Telemetry struct { } type TelemetryFilters struct { - From time.Time - To time.Time + From time.Time + To time.Time + Country string } type PageMetadata struct { diff --git a/timescale/timescale.go b/timescale/timescale.go index 037e03a..929da47 100644 --- a/timescale/timescale.go +++ b/timescale/timescale.go @@ -162,6 +162,11 @@ func generateQuery(filters callhome.TelemetryFilters) (string, map[string]interf params["to"] = filters.To } + if filters.Country != "" { + queries = append(queries, "country = :country") + params["country"] = filters.Country + } + switch len(queries) { case 0: return "", params