Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NOISSUE - Add version filter #21

Merged
merged 2 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions api/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func retrieveEndpoint(svc callhome.Service) endpoint.Endpoint {
To: req.to,
Country: req.country,
City: req.city,
Version: req.version,
}
tm, err := svc.Retrieve(ctx, pm, filter)
if err != nil {
Expand Down Expand Up @@ -72,6 +73,7 @@ func retrieveSummaryEndpoint(svc callhome.Service) endpoint.Endpoint {
To: req.to,
Country: req.country,
City: req.city,
Version: req.version,
}
summary, err := svc.RetrieveSummary(ctx, filter)
if err != nil {
Expand All @@ -95,6 +97,7 @@ func serveUI(svc callhome.Service) endpoint.Endpoint {
To: req.to,
Country: req.country,
City: req.city,
Version: req.version,
}
res, err := svc.ServeUI(ctx, filter)
return uiRes{
Expand Down
1 change: 1 addition & 0 deletions api/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type listTelemetryReq struct {
to time.Time
country string
city string
version string
}

func (req listTelemetryReq) validate() error {
Expand Down
7 changes: 7 additions & 0 deletions api/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const (
toKey = "to"
countryKey = "country"
cityKey = "city"
versionKey = "version"
defOffset = 0
defLimit = 10
staticDir = "./web/static"
Expand Down Expand Up @@ -191,13 +192,19 @@ func decodeRetrieve(_ context.Context, r *http.Request) (interface{}, error) {
return nil, err
}

ve, err := ReadStringQuery(r, versionKey, "")
if err != nil {
return nil, err
}

req := listTelemetryReq{
offset: o,
limit: l,
from: from,
to: to,
country: co,
city: ci,
version: ve,
}
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 @@ -29,6 +29,7 @@ paths:
- $ref: "#/components/parameters/To"
- $ref: "#/components/parameters/Country"
- $ref: "#/components/parameters/City"
- $ref: "#/components/parameters/Version"
responses:
"200":
description: found
Expand All @@ -49,6 +50,7 @@ paths:
- $ref: "#/components/parameters/To"
- $ref: "#/components/parameters/Country"
- $ref: "#/components/parameters/City"
- $ref: "#/components/parameters/Version"
responses:
"200":
description: found
Expand Down Expand Up @@ -84,6 +86,7 @@ paths:
- $ref: "#/components/parameters/To"
- $ref: "#/components/parameters/Country"
- $ref: "#/components/parameters/City"
- $ref: "#/components/parameters/Version"
tags:
- telemetry
summary: Retrieve telemetry events
Expand Down Expand Up @@ -159,6 +162,14 @@ components:
type: string
default: ""
required: false
Version:
name: version
description: From version filter.
in: query
schema:
type: string
default: ""
required: false
requestBodies:
TelemetryReq:
content:
Expand Down
1 change: 1 addition & 0 deletions telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type TelemetryFilters struct {
To time.Time
Country string
City string
Version 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 @@ -171,6 +171,11 @@ func generateQuery(filters callhome.TelemetryFilters) (string, map[string]interf
params["city"] = filters.City
}

if filters.Version != "" {
queries = append(queries, "mf_version = :version")
params["version"] = filters.Version
}

switch len(queries) {
case 0:
return "", params
Expand Down