Skip to content

Commit

Permalink
Merge pull request #18 from 1998-felix/city-filter
Browse files Browse the repository at this point in the history
NOISSUE - Add city filter
  • Loading branch information
drasko authored Aug 2, 2023
2 parents 35a1c76 + 03efc48 commit bc27630
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions api/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func retrieveEndpoint(svc callhome.Service) endpoint.Endpoint {
From: req.from,
To: req.to,
Country: req.country,
City: req.city,
}
tm, err := svc.Retrieve(ctx, pm, filter)
if err != nil {
Expand Down Expand Up @@ -70,6 +71,7 @@ func retrieveSummaryEndpoint(svc callhome.Service) endpoint.Endpoint {
From: req.from,
To: req.to,
Country: req.country,
City: req.city,
}
summary, err := svc.RetrieveSummary(ctx, filter)
if err != nil {
Expand All @@ -92,6 +94,7 @@ func serveUI(svc callhome.Service) endpoint.Endpoint {
From: req.from,
To: req.to,
Country: req.country,
City: req.city,
}
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 @@ -45,6 +45,7 @@ type listTelemetryReq struct {
from time.Time
to time.Time
country string
city 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 @@ -27,6 +27,7 @@ const (
fromKey = "from"
toKey = "to"
countryKey = "country"
cityKey = "city"
defOffset = 0
defLimit = 10
staticDir = "./web/static"
Expand Down Expand Up @@ -185,12 +186,18 @@ func decodeRetrieve(_ context.Context, r *http.Request) (interface{}, error) {
return nil, err
}

ci, err := ReadStringQuery(r, cityKey, "")
if err != nil {
return nil, err
}

req := listTelemetryReq{
offset: o,
limit: l,
from: from,
to: to,
country: co,
city: ci,
}
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 @@ -28,6 +28,7 @@ paths:
- $ref: "#/components/parameters/From"
- $ref: "#/components/parameters/To"
- $ref: "#/components/parameters/Country"
- $ref: "#/components/parameters/City"
responses:
"200":
description: found
Expand All @@ -47,6 +48,7 @@ paths:
- $ref: "#/components/parameters/From"
- $ref: "#/components/parameters/To"
- $ref: "#/components/parameters/Country"
- $ref: "#/components/parameters/City"
responses:
"200":
description: found
Expand Down Expand Up @@ -81,6 +83,7 @@ paths:
- $ref: "#/components/parameters/From"
- $ref: "#/components/parameters/To"
- $ref: "#/components/parameters/Country"
- $ref: "#/components/parameters/City"
tags:
- telemetry
summary: Retrieve telemetry events
Expand Down Expand Up @@ -148,6 +151,14 @@ components:
type: string
default: ""
required: false
City:
name: city
description: From city 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 @@ -24,6 +24,7 @@ type TelemetryFilters struct {
From time.Time
To time.Time
Country string
City 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 @@ -167,6 +167,11 @@ func generateQuery(filters callhome.TelemetryFilters) (string, map[string]interf
params["country"] = filters.Country
}

if filters.City != "" {
queries = append(queries, "city = :city")
params["city"] = filters.City
}

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

0 comments on commit bc27630

Please sign in to comment.