Skip to content

Commit

Permalink
Merge pull request #17 from 1998-felix/country-filter
Browse files Browse the repository at this point in the history
NOISSUE- Add country filter to telemetry filters
  • Loading branch information
drasko authored Jul 28, 2023
2 parents 3fd1224 + cad3e4f commit 35a1c76
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 16 deletions.
15 changes: 9 additions & 6 deletions api/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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{
Expand Down
9 changes: 5 additions & 4 deletions api/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 11 additions & 4 deletions api/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
limitKey = "limit"
fromKey = "from"
toKey = "to"
countryKey = "country"
defOffset = 0
defLimit = 10
staticDir = "./web/static"
Expand Down Expand Up @@ -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
}
Expand Down
11 changes: 11 additions & 0 deletions openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions timescale/timescale.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 35a1c76

Please sign in to comment.