Skip to content

Commit

Permalink
fix: FindManyConfigs filter to accept any types
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine Gelloz committed Dec 28, 2022
1 parent ac77568 commit 71befb3
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pkg/server/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ func (h *serverHandler) getManyConfigsHandle(w http.ResponseWriter, r *http.Requ

var ErrInvalidParams = errors.New("invalid params: only 'id' and 'endpoint' with a valid URL are accepted")

func buildQueryFilter(values url.Values) (map[string]string, error) {
filter := map[string]string{}
func buildQueryFilter(values url.Values) (map[string]any, error) {
filter := map[string]any{}

for key, value := range values {
if len(value) != 1 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/server/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

func (h *serverHandler) testOneConfigHandle(w http.ResponseWriter, r *http.Request) {
id := chi.URLParam(r, PathParamId)
cfgs, err := h.store.FindManyConfigs(r.Context(), map[string]string{"id": id})
cfgs, err := h.store.FindManyConfigs(r.Context(), map[string]any{"id": id})
if err == nil {
if len(cfgs) == 0 {
sharedlogging.GetLogger(r.Context()).Errorf("GET %s/%s%s: %s", PathConfigs, id, PathTest, storage.ErrConfigNotFound)
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func NewStore() (storage.Store, error) {
return Store{db: db}, nil
}

func (s Store) FindManyConfigs(ctx context.Context, filters map[string]string) ([]webhooks.Config, error) {
func (s Store) FindManyConfigs(ctx context.Context, filters map[string]any) ([]webhooks.Config, error) {
res := []webhooks.Config{}
sq := s.db.NewSelect().Model(&res)
for key, val := range filters {
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/postgres/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestStore(t *testing.T) {
store, err := postgres.NewStore()
require.NoError(t, err)

cfgs, err := store.FindManyConfigs(context.Background(), map[string]string{})
cfgs, err := store.FindManyConfigs(context.Background(), map[string]any{})
require.NoError(t, err)
require.Equal(t, 0, len(cfgs))

Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var (
)

type Store interface {
FindManyConfigs(ctx context.Context, filter map[string]string) ([]webhooks.Config, error)
FindManyConfigs(ctx context.Context, filter map[string]any) ([]webhooks.Config, error)
InsertOneConfig(ctx context.Context, cfg webhooks.ConfigUser) (webhooks.Config, error)
DeleteOneConfig(ctx context.Context, id string) error
UpdateOneConfigActivation(ctx context.Context, id string, active bool) (webhooks.Config, error)
Expand Down
4 changes: 2 additions & 2 deletions pkg/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ func (w *Worker) processMessage(ctx context.Context, msgValue []byte) error {
ev.Type = strings.Join([]string{eventApp, eventType}, ".")
}

filter := map[string]string{
filter := map[string]any{
"event_types": ev.Type,
"active": "true",
"active": true,
}
sharedlogging.GetLogger(ctx).Debugf("searching configs with filter: %+v", filter)
cfgs, err := w.store.FindManyConfigs(ctx, filter)
Expand Down

0 comments on commit 71befb3

Please sign in to comment.