Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

Commit

Permalink
Filter for outdated centers
Browse files Browse the repository at this point in the history
  • Loading branch information
dreske committed Oct 10, 2022
1 parent 920fb37 commit 84e7515
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/api/centers.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,16 @@ func (*Centers) getSearchParameters(r *http.Request) repositories.SearchParamete
}
}

includeOutdatedParameter, hasOutdatedParameter := r.URL.Query()["includeOutdated"]
if hasOutdatedParameter {
if tmp, err := strconv.ParseBool(includeOutdatedParameter[0]); err != nil {
result.IncludeOutdated = &tmp
}
} else {
tmp := false
result.IncludeOutdated = &tmp
}

return result
}

Expand Down
12 changes: 8 additions & 4 deletions src/repositories/centers.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ import (
const DistanceUnit = 111.045

type SearchParameters struct {
Appointment *domain.AppointmentType
TestKind *domain.TestKind
DCC *bool
Appointment *domain.AppointmentType
TestKind *domain.TestKind
DCC *bool
IncludeOutdated *bool
}

type PagedCentersResult struct {
Expand Down Expand Up @@ -177,7 +178,7 @@ func (r *centersRepository) Update(ctx context.Context, center domain.Center) (d
return center, err
}

// FindByCoordinates finds centers within the given distance of the specified target coordinates.
// FindByBounds finds centers within the given bounds
func (r *centersRepository) FindByBounds(ctx context.Context, target domain.Bounds, params SearchParameters, limit uint) ([]domain.Center, error) {
// build base query restriction
builder := goqu.From("centers").Where(
Expand Down Expand Up @@ -209,6 +210,9 @@ func (r *centersRepository) FindByBounds(ctx context.Context, target domain.Boun
if params.TestKind != nil {
builder = builder.Where(goqu.L("test_kinds @> ARRAY[?]::varchar[]", *params.TestKind))
}
if params.IncludeOutdated == nil || *params.IncludeOutdated == false {
builder = builder.Where(goqu.L("last_update > now() - INTERVAL '4 weeks'"))
}

countQuery := builder.Select(goqu.COUNT("*"))
var count uint
Expand Down

0 comments on commit 84e7515

Please sign in to comment.