Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
Fix sync filter map reading
Browse files Browse the repository at this point in the history
  • Loading branch information
v1adhope committed Apr 21, 2023
1 parent 6f18182 commit 5aee365
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Binary file modified .bin/app
Binary file not shown.
8 changes: 7 additions & 1 deletion internal/usecase/repository/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package repository
import (
"fmt"
"strings"
"sync"

"github.com/v1adhope/crypto-diary/internal/entity"
)
Expand All @@ -20,16 +21,21 @@ type filterBuilderDeps struct {
}

func BuildFilterString(deps filterBuilderDeps) (string, []string) {
var filterRaw strings.Builder
var (
filterRaw strings.Builder
mu sync.RWMutex
)

args, argsCounter := make([]string, 0), deps.QueryPlaceholderCount+1

for fieldKey, fieldVal := range deps.Filter.Fields {
mu.RLock()
if realFilterName, ok := allowedFilters[fieldKey]; ok {
fmt.Fprintf(&filterRaw, "AND %s = $%d ", realFilterName, argsCounter)
args = append(args, fieldVal)
argsCounter++
}
mu.RUnlock()
}

fmt.Fprintf(&filterRaw, "ORDER by position_id ASC LIMIT $%d", argsCounter)
Expand Down

0 comments on commit 5aee365

Please sign in to comment.