ch some
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"online-back/internal/org/province"
|
||||
"online-back/internal/shared"
|
||||
"online-back/pkg/client/postgresql"
|
||||
"online-back/pkg/logging"
|
||||
"online-back/pkg/repository/genericrepo"
|
||||
@@ -116,7 +117,7 @@ func buildListQuery(filter province.ListFilter) (whereClause string, args []inte
|
||||
var conditions []string
|
||||
|
||||
if filter.Name != "" {
|
||||
args = append(args, likePattern(filter.Name))
|
||||
args = append(args, shared.LikePattern(filter.Name))
|
||||
n := len(args)
|
||||
conditions = append(conditions, fmt.Sprintf(`(
|
||||
name->>'en' ILIKE $%[1]d OR name->>'ru' ILIKE $%[1]d OR name->>'tm' ILIKE $%[1]d
|
||||
@@ -124,7 +125,7 @@ func buildListQuery(filter province.ListFilter) (whereClause string, args []inte
|
||||
}
|
||||
|
||||
if filter.Region != "" {
|
||||
args = append(args, likePattern(filter.Region))
|
||||
args = append(args, shared.LikePattern(filter.Region))
|
||||
n := len(args)
|
||||
conditions = append(conditions, fmt.Sprintf(`(
|
||||
region->>'en' ILIKE $%[1]d OR region->>'ru' ILIKE $%[1]d OR region->>'tm' ILIKE $%[1]d
|
||||
@@ -143,13 +144,6 @@ func buildListQuery(filter province.ListFilter) (whereClause string, args []inte
|
||||
return " WHERE " + strings.Join(conditions, " AND "), args
|
||||
}
|
||||
|
||||
func likePattern(term string) string {
|
||||
term = strings.ReplaceAll(term, `\`, `\\`)
|
||||
term = strings.ReplaceAll(term, `%`, `\%`)
|
||||
term = strings.ReplaceAll(term, `_`, `\_`)
|
||||
return "%" + term + "%"
|
||||
}
|
||||
|
||||
func (r *repository) GetByID(ctx context.Context, id int64) (province.ProvinceDTO, error) {
|
||||
return r.generic.GetByID(ctx, id)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user